yioneko / vtsls

LSP wrapper for typescript extension of vscode
Other
374 stars 6 forks source link

Select typescript version doesn't work correctly in monorepo #167

Closed niba closed 3 weeks ago

niba commented 3 weeks ago

I use lazyvim that integrated vtsls. In my monorepo vtsls doesn't show workspace version if im in the nested package file. It works when I create typescript file on the root of the entire monorepo and from this file / buffer try to execute typescript.selectTypeScriptVersion.

Basically it only checks the closest node_modules

VSCode works okay

I checked lazyvim but don't see any path params so I don't know if the bug belongs here or in lazyvim

yioneko commented 3 weeks ago

The workspace version of tsdk is searched relative to node_modules of the workspace folders, usually given by root_dir in nvim builtin lsp client. I guess in your case the root_dir is not resolved to the root of your monorepo from the file you opened.

You can execute the following command :lua for _, client in pairs(vim.lsp.get_clients({ bufnr = 0, name = "vtsls" })) do print(vim.inspect(client.workspace_folders)) end to list the workspace folders and check if the listed folder contains path ./node_modules/typescript/lib.

niba commented 3 weeks ago

You are right. It returns one path to the first node_modules (package level) and there is no root node_modules entry.

I managed to override root_dir property to point to the top of monorepo and now I get correct node_modules and everything works. Thank you for your help

Config to achieve that

return {
  "neovim/nvim-lspconfig",
  opts = {
    inlay_hints = { enabled = false },
    servers = {
      vtsls = {
        root_dir = function()
          local lazyvimRoot = require("lazyvim.util.root")
          return lazyvimRoot.git()
        end,
      },
    },
  },
}