Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Existing language server instances with different root_dirs are reused, out of accordance with lspconfig's documentation #3531

Open
andrewbraxton opened this issue Dec 29, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@andrewbraxton
Copy link

Description

This is essentially a duplicate of #2967 which was incorrectly closed (lspconfig does indeed manage launching of servers.).

The help docs for lspconfig say:

If a root directory (string) is returned which is unique from any previously
returned root_dir, a new server will be spawned with that root directory.

But this is not the case. See the following code which causes existing language servers with the same name to be reused.

reuse_client = function(existing_client)
if (self._clients[root_dir] or {})[existing_client.name] then
self:_notify_workspace_folder_added(root_dir, existing_client)
return true

Either the code should be updated to match the docs, or the docs should be corrected and a new flag should be added to indicate that unique root dirs should always launch new language server instances. I am happy to try out a PR if the maintainers have a preference for either of those solutions.

@andrewbraxton andrewbraxton added the bug Something isn't working label Dec 29, 2024
@justinmk
Copy link
Member

justinmk commented Dec 30, 2024

Please try latest Nvim 0.11 from https://github.com/neovim/neovim/releases , using the vim.lsp.config feature. neovim/neovim#31565 seems related, and should give a hint about where the relevant code lives.

The "manager" part of nvim-lspconfig is deprecated #3494 in favor of the vim.lsp.config feature in Nvim core. It will be helpful if you can confirm whether the vim.lsp.config behavior is as you expected.

@andrewbraxton
Copy link
Author

I'm using nightly, and yes, the vim.lsp.config behavior in Neovim core does work as expected. I didn't know the manager portion was slated for deprecation (though that makes sense given the additions to core), so feel free to close if manager-related bugs are a wont-fix.

@rcurran1221
Copy link

Having the same issue, if I upgrade to 0.11, my issue will be resolved? Or will I need to change config as well? Thanks!

@andrewbraxton
Copy link
Author

You'll have to change your config. I don't believe lspconfig provides a way to override reuse_client, so I recommend moving to the vim.lsp.enable() scheme which gives you much more control.

@rcurran1221

This comment has been minimized.

@rcurran1221
Copy link

  local client_id = lsp.start(new_config, {
    bufnr = bufnr,
    silent = silent,
    reuse_client = function(existing_client)
      print('reuse client?')
      print(existing_client.root_dir)
      print(root_dir)
      if existing_client.root_dir ~= root_dir then
        print('using new client...')
        return false
      end
      if (self._clients[root_dir] or {})[existing_client.name] then
        self:_notify_workspace_folder_added(root_dir, existing_client)
        return true
      end

      for _, dir_clients in pairs(self._clients) do
        if dir_clients[existing_client.name] then
          self:_notify_workspace_folder_added(root_dir, existing_client)
          return true
        end
      end

      return false
    end,
  })

work around if anyone is looking for one..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants