Skip to content

New clients started per tsconfig.json in a multi-project TypeScript codebase #3910

@faergeek

Description

@faergeek

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:

  1. Clone the repo
  2. npm install -g typescript typescript-language-server as per configs.md
  3. 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 two ts_ls instances under vim.lsp: Active Clients.
  4. 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 one ts_ls instance under vim.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.

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