Skip to content

AngularLs does not properly detect current @angular/core version #3859

@beneeng

Description

@beneeng

Description

Hey,

At the moment the angular language server in my project starts with an empty string as parameter for --angularCoreVersion
This leads to features not being enabled in the angular language server.

The reason is in my opinion this line:

local node_modules_dir = vim.fs.find('node_modules', { path = root_dir, upward = true })[1]

in the angularls.lua file.
The upward = true setting seems to be wrong. The node_modules folder should be a subfolder of the root directory.
Locally changing it to

local node_modules_dir = vim.fs.find('node_modules', { path = root_dir })[1]

fixed the issue of a missing version number.

Also in cases where the version can not be determined, the --angularCoreVersion parameter should not be added to the program arguments. right now the parameter just exists with an empty value, which prevents the default handling of the Language server.

I suggest changing the return statement like this:

    local tbl = {
        cmd = {
            'ngserver',
            '--stdio',
            '--tsProbeLocations',
            ts_probe_dirs,
            '--ngProbeLocations',
            ng_probe_dirs,
        },
        filetypes = { 'typescript', 'html', 'typescriptreact', 'typescript.tsx', 'htmlangular' },
        root_markers = { 'angular.json', 'nx.json' },
    }
    if default_angular_core_version ~= "" then
        table.insert(tbl["cmd"], '--angularCoreVersion')
        table.insert(tbl["cmd"], default_angular_core_version)
    end
    return tbl

Best regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions