-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Description
With the migration to a new way of configuring LSPs I noticed a change in behavior when working with multiple TypeScript projects tied together using project references.
When using require('lspconfig').<lsp-name>.setup(...)
and opening files from different projects there is only one client instance.
But with vim.lsp.config
+ vim.lsp.enable
a new separate client instance is started for each project.
The issue is that with multiple instances finding references doesn't work reliably across all projects even when all of them are loaded.
I've tried ts_ls
and vtsls
, they both behave the same way before and after.
Here is a repository to demonstrate the issue: https://github.com/faergeek/nvim-ts-workspace-folders-repro
Steps to reproduce:
- Clone the repo
npm install -g typescript typescript-language-server
as per configs.md- Run
nvim --clean -u init.new.lua -O a/index.ts b/index.ts
, which uses the new way of configuration. Run:LspInfo
. There will be twots_ls
instances undervim.lsp: Active Clients
. - Run
nvim --clean -u init.old.lua -O a/index.ts b/index.ts
, which uses the old way. Run:LspInfo
. There will be just onets_ls
instance undervim.lsp: Active Clients
.
With the old way any unrelated project will also be added to the same instance as well (from a completely different repository in a parent directory, for example), which doesn't seem right, but I don't know if it actually causes any issues.
Based on :help vim.lsp.Config
possible workaround outside of nvim-lspconfig would be either defining a custom reuse_client
implementation or just setting root_dir
to a cwd, for example:
vim.lsp.config('vtsls', {
root_dir = vim.uv.cwd(),
})
I don't know what would be a generic solution to this other than looking for root markers top-down instead of bottom-up when detecting root_dir
.