emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.72k stars 860 forks source link

Angular-ls returns no result #4459

Closed XenHunt closed 2 days ago

XenHunt commented 1 month ago

Thank you for the bug report

Bug description

Angular-ls doesn't work correctly, as it must. When I try to edit html file of a component, it does gives me any autocompletion of angular specific components or variables in ts file of that component. As of lsp-workspace-show-log I get for angular-ls in code-Action, hover, codeLens only Result:null

Steps to reproduce

  1. Create a new angular project with ng new test.
  2. Open app.component.html in app folder.
  3. Delete all and write this construction:
    <div>
    {{}}
    </div>
  4. In brackets, try to print title, that is a variable in app.component.ts

Expected behavior

Expected that will be given autocompletion for selecting this variable.

Which Language Server did you use?

angular-ls, html-ls, ts-ls

OS

Linux

Error callstack

No response

Anything else?

I did some research for myself.

  1. I tried to use vs-code to see if angular-ls is the one, who must give autocompletion in html, and yes it is. After disabling it, I didn't get any autocompletion of specific angular element in html.
  2. After disabling angular in vs-code, I still was given with lsp power in ts file, as typescript extension was working, so as in #4237, I can get completion in ts file by ts-ls in emacs.
XenHunt commented 1 month ago

After some research and finding how it is working in neovim config of mason package, I found a correct config for lsp-client-angular-language-server-command:

  (setq lsp-clients-angular-language-server-command
   '("ngserver"
     "--stdio"
     "--tsProbeLocations"
     "<mine-root-directory>/.nvm/versions/node/v20.13.1/lib/node_modules/"
     "--ngProbeLocations"
     "<mine-root-directory>/.nvm/versions/node/v20.13.1/lib/node_modules/@angular/language-server/node_modules/"
     ))

edit: Added a lua function from which I got a right configuration

---@param install_dir string
return function(install_dir)
    local append_node_modules = _.map(function(dir)
        return path.concat { dir, "node_modules" }
    end)

    local function get_cmd(workspace_dir)
        local cmd = {
            "ngserver",
            "--stdio",
            "--tsProbeLocations",
            table.concat(append_node_modules { install_dir, workspace_dir }, ","),
            "--ngProbeLocations",
            table.concat(
                append_node_modules {
                    path.concat { install_dir, "node_modules", "@angular", "language-server" },
                    workspace_dir,
                },
                ","
            ),
        }
        if platform.is.win then
            cmd[1] = vim.fn.exepath(cmd[1])
        end

        return cmd
    end

    return {
        cmd = get_cmd(vim.loop.cwd()),
        on_new_config = function(new_config, root_dir)
            new_config.cmd = get_cmd(root_dir)
        end,
    }
end