neovim: migrate to new lsp config
This commit is contained in:
@@ -1,141 +0,0 @@
|
||||
local ts = require("telescope.builtin")
|
||||
local mason = require("mason")
|
||||
local lsp_installer = require("mason-lspconfig")
|
||||
local lspconfig = require("lspconfig")
|
||||
local null_ls = require("null-ls")
|
||||
local util = lspconfig.util
|
||||
local formatting = require("daniil.formatting")
|
||||
|
||||
local null_formatting = null_ls.builtins.formatting
|
||||
|
||||
mason.setup()
|
||||
lsp_installer.setup()
|
||||
|
||||
null_ls.setup({
|
||||
sources = {
|
||||
null_formatting.prettierd.with({
|
||||
extra_filetypes = { "svelte" },
|
||||
}),
|
||||
null_formatting.stylua,
|
||||
null_formatting.gofmt,
|
||||
null_formatting.goimports,
|
||||
null_formatting.shfmt,
|
||||
},
|
||||
on_attach = function()
|
||||
local group = vim.api.nvim_create_augroup("NullLsLspFormatting", { clear = true })
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
pattern = "*",
|
||||
group = group,
|
||||
callback = function()
|
||||
if not formatting.is_enabled() then
|
||||
return
|
||||
end
|
||||
|
||||
vim.lsp.buf.format()
|
||||
end,
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
||||
local lsp_server_without_formatting = { "ts_ls", "html", "cssls", "eslint", "jsonls", "svelte" }
|
||||
|
||||
local function on_attach(client, bufnr)
|
||||
local opts = { buffer = bufnr, remap = false }
|
||||
|
||||
-- disable lsp formatting here because i don't understand how lsp configuration works
|
||||
if vim.list_contains(lsp_server_without_formatting, client.name) then
|
||||
client.server_capabilities.documentFormattingProvider = false
|
||||
client.server_capabilities.documentRangeFormattingProvider = false
|
||||
end
|
||||
|
||||
vim.keymap.set("n", "gd", ts.lsp_definitions, opts)
|
||||
vim.keymap.set("n", "gr", ts.lsp_references, opts)
|
||||
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
||||
vim.keymap.set("n", "<F2>", vim.lsp.buf.rename, opts)
|
||||
vim.keymap.set("n", "<leader>r", vim.lsp.buf.rename, opts)
|
||||
vim.keymap.set("n", "<leader>.", vim.lsp.buf.code_action, opts)
|
||||
vim.keymap.set("i", "<C-e>", vim.lsp.buf.signature_help, opts)
|
||||
|
||||
if not vim.lsp.buf.range_code_action == nil then
|
||||
vim.keymap.set("v", "<leader>.", vim.lsp.buf.range_code_action, opts)
|
||||
end
|
||||
end
|
||||
|
||||
vim.keymap.set("n", "<leader>ee", function()
|
||||
vim.diagnostic.open_float(nil, { focus = false, scope = "line" })
|
||||
end)
|
||||
vim.keymap.set("n", "<leader>en", function()
|
||||
vim.diagnostic.goto_next({ float = false })
|
||||
end)
|
||||
vim.keymap.set("n", "<leader>eN", function()
|
||||
vim.diagnostic.goto_prev({ float = false })
|
||||
end)
|
||||
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||||
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||
|
||||
local servers = lsp_installer.get_installed_servers()
|
||||
for _, server in ipairs(servers) do
|
||||
local opts = {
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
root_dir = util.root_pattern(".git"),
|
||||
}
|
||||
|
||||
if server == "lua_ls" then
|
||||
opts.settings = {
|
||||
Lua = {
|
||||
diagnostics = {
|
||||
globals = { "vim" },
|
||||
},
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
if server == "emmet_ls" then
|
||||
opts.filetypes = { "html", "css", "scss", "javascripreact", "typescriptreact", "astro" }
|
||||
end
|
||||
|
||||
if server == "golangci_lint_ls" then
|
||||
opts.root_dir = util.root_pattern("go.mod", ".git")
|
||||
end
|
||||
|
||||
if server == "gopls" then
|
||||
-- https://github.com/golang/tools/blob/master/gopls/doc/settings.md
|
||||
opts.settings = {
|
||||
gopls = {
|
||||
linksInHover = true,
|
||||
usePlaceholders = false, -- just to ensure it's off, incase in the future go team decides to toggle it on by default
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
if server == "tailwindcss" then
|
||||
opts.root_dir = util.root_pattern("tailwind.config.js", ".git")
|
||||
end
|
||||
|
||||
if server == "jsonls" then
|
||||
opts.settings = {
|
||||
json = {
|
||||
schemas = require("schemastore").json.schemas(),
|
||||
validate = {
|
||||
enable = true,
|
||||
},
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
lspconfig[server].setup(opts)
|
||||
end
|
||||
|
||||
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
|
||||
update_in_insert = false,
|
||||
signs = false,
|
||||
})
|
||||
|
||||
vim.cmd([[
|
||||
hi DiagnosticError guifg=#e80f43
|
||||
hi DiagnosticWarn guifg=#ffc914
|
||||
hi DiagnosticInfo guifg=#9fd356
|
||||
hi DiagnosticHint guifg=#1d74f7
|
||||
]])
|
||||
77
neovim/.config/nvim/after/plugin/lsp/config.lua
Normal file
77
neovim/.config/nvim/after/plugin/lsp/config.lua
Normal file
@@ -0,0 +1,77 @@
|
||||
local ts = require("telescope.builtin")
|
||||
local null_ls = require("null-ls")
|
||||
local formatting = require("daniil.formatting")
|
||||
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||||
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||
|
||||
vim.lsp.config("*", {
|
||||
capabilities = capabilities,
|
||||
})
|
||||
|
||||
local null_formatting = null_ls.builtins.formatting
|
||||
null_ls.setup({
|
||||
sources = {
|
||||
null_formatting.prettierd.with({
|
||||
extra_filetypes = { "svelte" },
|
||||
}),
|
||||
null_formatting.stylua,
|
||||
null_formatting.gofmt,
|
||||
null_formatting.goimports,
|
||||
null_formatting.shfmt,
|
||||
},
|
||||
on_attach = function()
|
||||
local group = vim.api.nvim_create_augroup("NullLsLspFormatting", { clear = true })
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
pattern = "*",
|
||||
group = group,
|
||||
callback = function()
|
||||
if not formatting.is_enabled() then
|
||||
return
|
||||
end
|
||||
|
||||
vim.lsp.buf.format()
|
||||
end,
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
callback = function(ev)
|
||||
local client = vim.lsp.get_client_by_id(ev.data.client_id)
|
||||
if not client then
|
||||
return
|
||||
end
|
||||
|
||||
local opts = { silent = true }
|
||||
|
||||
vim.keymap.set("n", "gd", ts.lsp_definitions, opts)
|
||||
vim.keymap.set("n", "gr", ts.lsp_references, opts)
|
||||
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
||||
vim.keymap.set("n", "<F2>", vim.lsp.buf.rename, opts)
|
||||
vim.keymap.set("n", "<leader>r", vim.lsp.buf.rename, opts)
|
||||
vim.keymap.set("n", "<leader>.", vim.lsp.buf.code_action, opts)
|
||||
vim.keymap.set("i", "<C-e>", vim.lsp.buf.signature_help, opts)
|
||||
|
||||
if not vim.lsp.buf.range_code_action == nil then
|
||||
vim.keymap.set("v", "<leader>.", vim.lsp.buf.range_code_action, opts)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
vim.diagnostic.config({
|
||||
update_in_insert = false,
|
||||
virtual_lines = {
|
||||
severity = { vim.diagnostic.severity.ERROR },
|
||||
},
|
||||
})
|
||||
|
||||
vim.keymap.set("n", "<leader>ee", function()
|
||||
vim.diagnostic.open_float(nil, { focus = false, scope = "line" })
|
||||
end)
|
||||
vim.keymap.set("n", "<leader>en", function()
|
||||
vim.diagnostic.goto_next({ float = false })
|
||||
end)
|
||||
vim.keymap.set("n", "<leader>eN", function()
|
||||
vim.diagnostic.goto_prev({ float = false })
|
||||
end)
|
||||
31
neovim/.config/nvim/after/plugin/lsp/go.lua
Normal file
31
neovim/.config/nvim/after/plugin/lsp/go.lua
Normal file
@@ -0,0 +1,31 @@
|
||||
local filetypes = { "go", "gotempl", "gowork", "gomod" }
|
||||
local root_markers = { ".git", "go.mod", "go.work", vim.uv.cwd() }
|
||||
|
||||
vim.lsp.config.gopls = {
|
||||
cmd = { "gopls" },
|
||||
filetypes = filetypes,
|
||||
root_markers = root_markers,
|
||||
settings = {
|
||||
gopls = {
|
||||
linksInHover = true,
|
||||
usePlaceholders = false, -- just to ensure it's off, incase in the future go team decides to toggle it on by default
|
||||
completeUnimported = true,
|
||||
analyses = {
|
||||
unusedparams = true,
|
||||
},
|
||||
["ui.inlayhint.hints"] = {
|
||||
compositeLiteralFields = true,
|
||||
constantValues = true,
|
||||
parameterNames = true,
|
||||
rangeVariableTypes = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
vim.lsp.enable("gopls")
|
||||
|
||||
vim.lsp.config.golangci_lint_ls = {
|
||||
cmd = { "golangci-lint-langserver" },
|
||||
filetypes = filetypes,
|
||||
root_markers = root_markers,
|
||||
}
|
||||
62
neovim/.config/nvim/after/plugin/lsp/other.lua
Normal file
62
neovim/.config/nvim/after/plugin/lsp/other.lua
Normal file
@@ -0,0 +1,62 @@
|
||||
-- lua
|
||||
vim.lsp.config.lua_ls = {
|
||||
cmd = { "lua-language-server" },
|
||||
filetypes = { "lua" },
|
||||
root_markers = { ".luarc.json", ".git", vim.uv.cwd() },
|
||||
settings = {
|
||||
Lua = {
|
||||
telemetry = {
|
||||
enable = false,
|
||||
},
|
||||
diagnostics = {
|
||||
globals = { "vim" },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
vim.lsp.enable("lua_ls")
|
||||
|
||||
-- json
|
||||
vim.lsp.config.json_ls = {
|
||||
cmd = { "vscode-json-language-server", "--stdio" },
|
||||
filetypes = { "json", "jsonc" },
|
||||
root_markers = { vim.uv.cwd() },
|
||||
settings = {
|
||||
json = {
|
||||
schemas = require("schemastore").json.schemas(),
|
||||
validate = {
|
||||
enable = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
vim.lsp.enable("json_ls")
|
||||
|
||||
-- bash
|
||||
vim.lsp.config.bashls = {
|
||||
cmd = { "bash-language-server", "start" },
|
||||
filetypes = { "bash", "sh" },
|
||||
root_markers = { ".git", vim.uv.cwd() },
|
||||
settings = {
|
||||
bashIde = {
|
||||
globPattern = vim.env.GLOB_PATTERN or "*@(.sh|.inc|.bash|.command)",
|
||||
},
|
||||
},
|
||||
}
|
||||
vim.lsp.enable("bashls")
|
||||
|
||||
-- docker compose
|
||||
vim.lsp.config.compose_ls = {
|
||||
cmd = { "docker-compose-langserver", "--stdio" },
|
||||
filetypes = { "yaml" },
|
||||
root_markers = { "docker-compose.yml", vim.uv.cwd() },
|
||||
}
|
||||
vim.lsp.enable("compose_ls")
|
||||
|
||||
-- docker
|
||||
vim.lsp.config.docker_ls = {
|
||||
cmd = { "docker-langserver", "--stdio" },
|
||||
filetypes = { "dockerfile" },
|
||||
root_markers = { "Dockerfile", ".git", vim.uv.cwd() },
|
||||
}
|
||||
vim.lsp.enable("docker_ls")
|
||||
144
neovim/.config/nvim/after/plugin/lsp/webdev.lua
Normal file
144
neovim/.config/nvim/after/plugin/lsp/webdev.lua
Normal file
@@ -0,0 +1,144 @@
|
||||
-- typescript
|
||||
vim.lsp.config.ts_ls = {
|
||||
cmd = { "typescript-language-server", "--stdio" },
|
||||
filetypes = { "javascript", "javascriptreact", "javascript.jsx", "typescript", "typescriptreact", "typescript.tsx" },
|
||||
root_markers = { "tsconfig.json", "jsconfig.json", "package.json", ".git", vim.uv.cwd() },
|
||||
|
||||
init_options = {
|
||||
hostInfo = "neovim",
|
||||
},
|
||||
}
|
||||
vim.lsp.enable("ts_ls")
|
||||
|
||||
-- css
|
||||
vim.lsp.config.cssls = {
|
||||
cmd = { "vscode-css-language-server", "--stdio" },
|
||||
filetypes = { "css", "scss" },
|
||||
root_markers = { "package.json", ".git", vim.uv.cwd() },
|
||||
init_options = {
|
||||
provideFormatter = false,
|
||||
},
|
||||
}
|
||||
vim.lsp.enable("cssls")
|
||||
|
||||
-- cssmodules
|
||||
vim.lsp.config.cssmodules_ls = {
|
||||
cmd = { "cssmodules-language-server" },
|
||||
filetypes = {
|
||||
"css",
|
||||
"scss",
|
||||
"javascript",
|
||||
"javascript.jsx",
|
||||
"javascriptreact",
|
||||
"typescript",
|
||||
"typescript.tsx",
|
||||
"typescriptreact",
|
||||
},
|
||||
root_markers = { "package.json", ".git", vim.uv.cwd() },
|
||||
init_options = {
|
||||
camelCase = true,
|
||||
},
|
||||
}
|
||||
vim.lsp.enable("cssmodules_ls")
|
||||
|
||||
-- tailwindcss
|
||||
vim.lsp.config.tailwindcssls = {
|
||||
cmd = { "tailwindcss-language-server", "--stdio" },
|
||||
filetypes = {
|
||||
"html",
|
||||
"css",
|
||||
"scss",
|
||||
"javascript",
|
||||
"javascriptreact",
|
||||
"typescript",
|
||||
"typescriptreact",
|
||||
},
|
||||
root_markers = {
|
||||
"tailwind.config.js",
|
||||
"tailwind.config.cjs",
|
||||
"tailwind.config.mjs",
|
||||
"tailwind.config.ts",
|
||||
"postcss.config.js",
|
||||
"postcss.config.cjs",
|
||||
"postcss.config.mjs",
|
||||
"postcss.config.ts",
|
||||
"package.json",
|
||||
"node_modules",
|
||||
},
|
||||
settings = {
|
||||
tailwindCSS = {
|
||||
classAttributes = { "class", "className", "class:list", "classList" },
|
||||
includeLanguages = {
|
||||
templ = "html",
|
||||
},
|
||||
lint = {
|
||||
cssConflict = "warning",
|
||||
invalidApply = "error",
|
||||
invalidConfigPath = "error",
|
||||
invalidScreen = "error",
|
||||
invalidTailwindDirective = "error",
|
||||
invalidVariant = "error",
|
||||
recommendedVariantOrder = "warning",
|
||||
},
|
||||
validate = true,
|
||||
},
|
||||
},
|
||||
}
|
||||
vim.lsp.enable("tailwindcssls")
|
||||
|
||||
-- html
|
||||
vim.lsp.config.htmlls = {
|
||||
cmd = { "vscode-html-language-server", "--stdio" },
|
||||
filetypes = { "html" },
|
||||
root_markers = { "package.json", ".git", vim.uv.cwd() },
|
||||
|
||||
init_options = {
|
||||
configurationSection = { "html", "css", "javascript" },
|
||||
embeddedLanguages = {
|
||||
css = true,
|
||||
javascript = true,
|
||||
},
|
||||
},
|
||||
}
|
||||
vim.lsp.enable("htmlls")
|
||||
|
||||
-- emmet
|
||||
vim.lsp.config.emmet_ls = {
|
||||
cmd = { "emmet-ls", "--stdio" },
|
||||
filetypes = {
|
||||
"html",
|
||||
"css",
|
||||
"scss",
|
||||
"javascript",
|
||||
"javascript.jsx",
|
||||
"javascriptreact",
|
||||
"typescript",
|
||||
"typescript.tsx",
|
||||
"typescriptreact",
|
||||
},
|
||||
root_markers = { "package.json", ".git", vim.uv.cwd() },
|
||||
}
|
||||
vim.lsp.enable("emmet_ls")
|
||||
|
||||
-- eslint
|
||||
vim.lsp.config.eslint_ls = {
|
||||
cmd = { "vscode-eslint-language-server", "--stdio" },
|
||||
filetypes = {
|
||||
"javascript",
|
||||
"javascript.jsx",
|
||||
"javascriptreact",
|
||||
"typescript",
|
||||
"typescript.tsx",
|
||||
"typescriptreact",
|
||||
},
|
||||
root_markers = {
|
||||
".eslintrc.json",
|
||||
"eslint.config.js",
|
||||
"eslint.config.mjs",
|
||||
"eslint.config.cjs",
|
||||
"eslint.config.ts",
|
||||
"eslint.config.mts",
|
||||
"eslint.config.cts",
|
||||
},
|
||||
}
|
||||
-- vim.lsp.enable("eslint_ls")
|
||||
Reference in New Issue
Block a user