2024-11-20 00:31:45 +08:00
|
|
|
local LazyVim = require("lazyvim.util")
|
|
|
|
local util = require("lspconfig.util")
|
|
|
|
|
2023-03-29 23:58:11 +08:00
|
|
|
return {
|
|
|
|
"neovim/nvim-lspconfig",
|
|
|
|
opts = {
|
2023-10-05 02:55:01 +08:00
|
|
|
servers = {
|
|
|
|
tailwindcss = {
|
|
|
|
filetypes_exclude = { "markdown" },
|
|
|
|
},
|
2024-11-20 00:31:45 +08:00
|
|
|
--- @deprecated -- tsserver renamed to ts_ls but not yet released, so keep this for now
|
|
|
|
--- the proper approach is to check the nvim-lspconfig release version when it's released to determine the server name dynamically
|
|
|
|
tsserver = {
|
|
|
|
enabled = false,
|
|
|
|
},
|
|
|
|
ts_ls = {
|
|
|
|
enabled = false,
|
|
|
|
},
|
|
|
|
vtsls = {
|
|
|
|
-- explicitly add default filetypes, so that we can extend
|
|
|
|
-- them in related extras
|
|
|
|
filetypes = {
|
|
|
|
"javascript",
|
|
|
|
"javascriptreact",
|
|
|
|
"javascript.jsx",
|
|
|
|
"typescript",
|
|
|
|
"typescriptreact",
|
|
|
|
"typescript.tsx",
|
|
|
|
},
|
|
|
|
root_dir = util.root_pattern("tsconfig.json", "jsconfig.json", "package.json", ".git"),
|
|
|
|
settings = {
|
|
|
|
complete_function_calls = true,
|
|
|
|
vtsls = {
|
|
|
|
enableMoveToFileCodeAction = true,
|
|
|
|
autoUseWorkspaceTsdk = true,
|
|
|
|
experimental = {
|
|
|
|
completion = {
|
|
|
|
enableServerSideFuzzyMatch = true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
typescript = {
|
|
|
|
updateImportsOnFileMove = { enabled = "always" },
|
|
|
|
suggest = {
|
|
|
|
completeFunctionCalls = true,
|
|
|
|
},
|
|
|
|
inlayHints = {
|
|
|
|
enumMemberValues = { enabled = true },
|
|
|
|
functionLikeReturnTypes = { enabled = true },
|
|
|
|
parameterNames = { enabled = "literals" },
|
|
|
|
parameterTypes = { enabled = true },
|
|
|
|
propertyDeclarationTypes = { enabled = true },
|
|
|
|
variableTypes = { enabled = false },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
keys = {
|
|
|
|
{
|
|
|
|
"gD",
|
|
|
|
function()
|
|
|
|
local params = vim.lsp.util.make_position_params()
|
|
|
|
LazyVim.lsp.execute({
|
|
|
|
command = "typescript.goToSourceDefinition",
|
|
|
|
arguments = { params.textDocument.uri, params.position },
|
|
|
|
open = true,
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
desc = "Goto Source Definition",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"gR",
|
|
|
|
function()
|
|
|
|
LazyVim.lsp.execute({
|
|
|
|
command = "typescript.findAllFileReferences",
|
|
|
|
arguments = { vim.uri_from_bufnr(0) },
|
|
|
|
open = true,
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
desc = "File References",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"<leader>co",
|
|
|
|
LazyVim.lsp.action["source.organizeImports"],
|
|
|
|
desc = "Organize Imports",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"<leader>cM",
|
|
|
|
LazyVim.lsp.action["source.addMissingImports.ts"],
|
|
|
|
desc = "Add missing imports",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"<leader>cu",
|
|
|
|
LazyVim.lsp.action["source.removeUnused.ts"],
|
|
|
|
desc = "Remove unused imports",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"<leader>cD",
|
|
|
|
LazyVim.lsp.action["source.fixAll.ts"],
|
|
|
|
desc = "Fix all diagnostics",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"<leader>cV",
|
|
|
|
function()
|
|
|
|
LazyVim.lsp.execute({ command = "typescript.selectTypeScriptVersion" })
|
|
|
|
end,
|
|
|
|
desc = "Select TS workspace version",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-03-29 21:57:29 +08:00
|
|
|
marksman = {},
|
2023-10-05 02:55:01 +08:00
|
|
|
eslint = {},
|
|
|
|
emmet_language_server = {
|
|
|
|
filetypes = {
|
|
|
|
"css",
|
|
|
|
"eruby",
|
|
|
|
"html",
|
|
|
|
"javascript",
|
|
|
|
"javascriptreact",
|
|
|
|
"less",
|
|
|
|
"sass",
|
|
|
|
"scss",
|
|
|
|
"svelte",
|
|
|
|
"pug",
|
|
|
|
"typescriptreact",
|
|
|
|
"vue",
|
|
|
|
},
|
|
|
|
-- Read more about this options in the [vscode docs](https://code.visualstudio.com/docs/editor/emmet#_emmet-configuration).
|
|
|
|
-- **Note:** only the options listed in the table are supported.
|
|
|
|
init_options = {
|
|
|
|
--- @type string[]
|
|
|
|
excludeLanguages = {},
|
|
|
|
--- @type table<string, any> [Emmet Docs](https://docs.emmet.io/customization/preferences/)
|
|
|
|
preferences = {},
|
|
|
|
--- @type boolean Defaults to `true`
|
|
|
|
showAbbreviationSuggestions = true,
|
|
|
|
--- @type "always" | "never" Defaults to `"always"`
|
|
|
|
showExpandedAbbreviation = "always",
|
|
|
|
--- @type boolean Defaults to `false`
|
|
|
|
showSuggestionsAsSnippets = false,
|
|
|
|
--- @type table<string, any> [Emmet Docs](https://docs.emmet.io/customization/syntax-profiles/)
|
|
|
|
syntaxProfiles = {},
|
|
|
|
--- @type table<string, string> [Emmet Docs](https://docs.emmet.io/customization/snippets/#variables)
|
|
|
|
variables = {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-03-29 23:58:11 +08:00
|
|
|
setup = {
|
|
|
|
eslint = function()
|
2024-03-29 21:57:29 +08:00
|
|
|
require("lazyvim.util").lsp.on_attach(function(client)
|
2024-11-20 00:31:45 +08:00
|
|
|
print(client.name)
|
2023-03-29 23:58:11 +08:00
|
|
|
if client.name == "eslint" then
|
|
|
|
client.server_capabilities.documentFormattingProvider = true
|
2024-11-20 00:31:45 +08:00
|
|
|
-- elseif client.name == "ts_ls" then
|
|
|
|
-- client.server_capabilities.documentFormattingProvider = false
|
2023-03-29 23:58:11 +08:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
end,
|
2023-10-05 02:55:01 +08:00
|
|
|
|
2024-11-20 00:31:45 +08:00
|
|
|
tsserver = function()
|
|
|
|
-- disable tsserver
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
ts_ls = function()
|
|
|
|
-- disable tsserver
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
vtsls = function(_, opts)
|
|
|
|
LazyVim.lsp.on_attach(function(client, buffer)
|
|
|
|
client.commands["_typescript.moveToFileRefactoring"] = function(command, ctx)
|
|
|
|
---@type string, string, lsp.Range
|
|
|
|
local action, uri, range = unpack(command.arguments)
|
|
|
|
|
|
|
|
local function move(newf)
|
|
|
|
client.request("workspace/executeCommand", {
|
|
|
|
command = command.command,
|
|
|
|
arguments = { action, uri, range, newf },
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
local fname = vim.uri_to_fname(uri)
|
|
|
|
client.request("workspace/executeCommand", {
|
|
|
|
command = "typescript.tsserverRequest",
|
|
|
|
arguments = {
|
|
|
|
"getMoveToRefactoringFileSuggestions",
|
|
|
|
{
|
|
|
|
file = fname,
|
|
|
|
startLine = range.start.line + 1,
|
|
|
|
startOffset = range.start.character + 1,
|
|
|
|
endLine = range["end"].line + 1,
|
|
|
|
endOffset = range["end"].character + 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, function(_, result)
|
|
|
|
---@type string[]
|
|
|
|
local files = result.body.files
|
|
|
|
table.insert(files, 1, "Enter new path...")
|
|
|
|
vim.ui.select(files, {
|
|
|
|
prompt = "Select move destination:",
|
|
|
|
format_item = function(f)
|
|
|
|
return vim.fn.fnamemodify(f, ":~:.")
|
|
|
|
end,
|
|
|
|
}, function(f)
|
|
|
|
if f and f:find("^Enter new path") then
|
|
|
|
vim.ui.input({
|
|
|
|
prompt = "Enter move destination:",
|
|
|
|
default = vim.fn.fnamemodify(fname, ":h") .. "/",
|
|
|
|
completion = "file",
|
|
|
|
}, function(newf)
|
|
|
|
return newf and move(newf)
|
|
|
|
end)
|
|
|
|
elseif f then
|
|
|
|
move(f)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end, "vtsls")
|
|
|
|
-- copy typescript settings to javascript
|
|
|
|
opts.settings.javascript =
|
|
|
|
vim.tbl_deep_extend("force", {}, opts.settings.typescript, opts.settings.javascript or {})
|
|
|
|
end,
|
|
|
|
|
2023-10-05 02:55:01 +08:00
|
|
|
tailwindcss = function(_, opts)
|
2024-11-20 00:31:45 +08:00
|
|
|
local tw = require("lspconfig.server_configurations.tailwindcss")
|
|
|
|
--- @param ft string
|
|
|
|
opts.filetypes = vim.tbl_filter(function(ft)
|
|
|
|
return not vim.tbl_contains(opts.filetypes_exclude or {}, ft)
|
|
|
|
end, tw.default_config.filetypes)
|
2023-10-05 02:55:01 +08:00
|
|
|
end,
|
2023-03-29 23:58:11 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|