typescript-tools.nvim icon indicating copy to clipboard operation
typescript-tools.nvim copied to clipboard

how to custom the root dir config

Open KevinNitroG opened this issue 9 months ago • 5 comments

I want typescript tools not to attach to the buffer where the denols is active. I have declared my deno search and made the custom root_dir in opts, but typescript-tools still attach to my buffer. Am I on the right track to configure this?

return {
  opts = {
    root_dir = function(fname)
      -- NOTE: https://github.com/pmizio/typescript-tools.nvim/blob/master/lua/typescript-tools/init.lua
      local util = require "lspconfig.util"

      local deno = require("plugins.lsp.settings.denols").root_dir(fname) -- Dont mind this here
      if deno ~= "" then
        return -- THIS, HOW TO?
      end

      local root_dir = util.root_pattern "tsconfig.json"(fname)
        or util.root_pattern("package.json", "jsconfig.json", ".git")(fname)

      local node_modules_index = root_dir and root_dir:find("node_modules", 1, true)
      if node_modules_index and node_modules_index > 0 then
        root_dir = root_dir:sub(1, node_modules_index - 2)
      end

      return root_dir
    end,
  }
}

KevinNitroG avatar Apr 09 '25 15:04 KevinNitroG

I'm having the exact same issue.

I've tried using a function as you have, giving the value to root_dir directly, setting it explicitly to nil... typescript-tools will always activate for typescript etc. files regardless.

Maybe this is a 0.11 compatibility issue?

egargan avatar May 15 '25 08:05 egargan

I gave up using typescripttools and moved to vtsls 🫥

KevinNitroG avatar May 15 '25 11:05 KevinNitroG

Also having this issue and had to stop using typescript tools! Would love to see this get fixed.

404Wolf avatar Jun 07 '25 22:06 404Wolf

Also having this issue and had to stop using typescript tools! Would love to see this get fixed.

I think we should wait for tsgo

KevinNitroG avatar Jun 08 '25 05:06 KevinNitroG

See if this works as it does look like it does the trick for me:

local ts_tools = require("typescript-tools")
ts_tools.setup({
  single_file_support = false,
  root_dir = function(fname)
    if lspconfig_util.root_pattern("deno.json", "deno.jsonc")(fname) then
      return nil
    end
    return lspconfig_util.root_pattern("package.json", "tsconfig.json")(fname)
  end,
})

DanzigerGeist avatar Jul 11 '25 16:07 DanzigerGeist