You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

75 lines
2.1 KiB

local util = require("lspconfig.util")
local utils = require("lsp.utils")
-- Determine base path for node_modules
local base_path = utils.find_node_modules_path()
if not base_path then
vim.notify("No global node_modules found for TypeScript server", vim.log.levels.WARN)
base_path = ""
end
local function get_typescript_server_path(root_dir)
local global_ts = base_path .. "/typescript/lib"
local found_ts = ""
local function check_dir(path)
found_ts = table.concat({ path, "typescript", "lib" }, "/")
if vim.loop.fs_stat(found_ts) then
return path
end
end
-- Check frontend/node_modules first
if util.search_ancestors(root_dir .. '/frontend/node_modules', check_dir) then
return found_ts
end
-- Check root node_modules
if util.search_ancestors(root_dir .. '/node_modules', check_dir) then
return found_ts
end
return global_ts
end
local function organize_imports()
local params = {
command = "_typescript.organizeImports",
arguments = { vim.api.nvim_buf_get_name(0) },
title = ""
}
vim.lsp.buf.execute_command(params)
end
return {
init_options = {
plugins = {
{
name = "@vue/typescript-plugin",
location = base_path .. "/@vue/typescript-plugin",
languages = { "javascript", "typescript", "vue", "react" },
},
},
},
filetypes = {
"javascript",
"typescript",
"vue",
"typescriptreact",
},
commands = {
OrganizeImports = {
organize_imports,
description = "Organize Imports"
}
},
on_new_config = function(new_config, new_root_dir)
if get_typescript_server_path then
new_config.init_options.typescript = new_config.init_options.typescript or {}
new_config.init_options.typescript.tsdk = get_typescript_server_path(new_root_dir)
else
vim.notify("get_typescript_server_path is not defined", vim.log.levels.ERROR)
end
end,
}