mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
use new api vim.lsp.config for lsp configuration (#402)
Now nvim-lspconfig serves as ready made configuration for different lsp server configurations. See also related PR in lspconfig: https://github.com/neovim/nvim-lspconfig/pull/3659
This commit is contained in:
parent
e23d4bb661
commit
488ba52644
@ -1,8 +1,3 @@
|
|||||||
local api = vim.api
|
|
||||||
local keymap = vim.keymap
|
|
||||||
local lsp = vim.lsp
|
|
||||||
local lspconfig = require("lspconfig")
|
|
||||||
|
|
||||||
local utils = require("utils")
|
local utils = require("utils")
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("LspAttach", {
|
vim.api.nvim_create_autocmd("LspAttach", {
|
||||||
@ -22,7 +17,7 @@ vim.api.nvim_create_autocmd("LspAttach", {
|
|||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
opts.silent = true
|
opts.silent = true
|
||||||
opts.buffer = bufnr
|
opts.buffer = bufnr
|
||||||
keymap.set(mode, l, r, opts)
|
vim.keymap.set(mode, l, r, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" })
|
map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" })
|
||||||
@ -55,20 +50,20 @@ vim.api.nvim_create_autocmd("LspAttach", {
|
|||||||
|
|
||||||
-- The blow command will highlight the current variable and its usages in the buffer.
|
-- The blow command will highlight the current variable and its usages in the buffer.
|
||||||
if client.server_capabilities.documentHighlightProvider then
|
if client.server_capabilities.documentHighlightProvider then
|
||||||
local gid = api.nvim_create_augroup("lsp_document_highlight", { clear = true })
|
local gid = vim.api.nvim_create_augroup("lsp_document_highlight", { clear = true })
|
||||||
api.nvim_create_autocmd("CursorHold", {
|
vim.api.nvim_create_autocmd("CursorHold", {
|
||||||
group = gid,
|
group = gid,
|
||||||
buffer = bufnr,
|
buffer = bufnr,
|
||||||
callback = function()
|
callback = function()
|
||||||
lsp.buf.document_highlight()
|
vim.lsp.buf.document_highlight()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
api.nvim_create_autocmd("CursorMoved", {
|
vim.api.nvim_create_autocmd("CursorMoved", {
|
||||||
group = gid,
|
group = gid,
|
||||||
buffer = bufnr,
|
buffer = bufnr,
|
||||||
callback = function()
|
callback = function()
|
||||||
lsp.buf.clear_references()
|
vim.lsp.buf.clear_references()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
@ -108,7 +103,7 @@ if utils.executable("pyright") then
|
|||||||
}
|
}
|
||||||
local merged_capability = vim.tbl_deep_extend("force", capabilities, new_capability)
|
local merged_capability = vim.tbl_deep_extend("force", capabilities, new_capability)
|
||||||
|
|
||||||
lspconfig.pyright.setup {
|
vim.lsp.config("pyright", {
|
||||||
cmd = { "delance-langserver", "--stdio" },
|
cmd = { "delance-langserver", "--stdio" },
|
||||||
capabilities = merged_capability,
|
capabilities = merged_capability,
|
||||||
settings = {
|
settings = {
|
||||||
@ -137,13 +132,15 @@ if utils.executable("pyright") then
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
|
vim.lsp.enable("pyright")
|
||||||
else
|
else
|
||||||
vim.notify("pyright not found!", vim.log.levels.WARN, { title = "Nvim-config" })
|
vim.notify("pyright not found!", vim.log.levels.WARN, { title = "Nvim-config" })
|
||||||
end
|
end
|
||||||
|
|
||||||
if utils.executable("ruff") then
|
if utils.executable("ruff") then
|
||||||
require("lspconfig").ruff.setup {
|
vim.lsp.config("ruff", {
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
init_options = {
|
init_options = {
|
||||||
-- the settings can be found here: https://docs.astral.sh/ruff/editors/settings/
|
-- the settings can be found here: https://docs.astral.sh/ruff/editors/settings/
|
||||||
@ -151,12 +148,12 @@ if utils.executable("ruff") then
|
|||||||
organizeImports = true,
|
organizeImports = true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
|
vim.lsp.enable("ruff")
|
||||||
end
|
end
|
||||||
|
|
||||||
if utils.executable("ltex-ls") then
|
if utils.executable("ltex-ls") then
|
||||||
lspconfig.ltex.setup {
|
vim.lsp.config("ltex", {
|
||||||
cmd = { "ltex-ls" },
|
|
||||||
filetypes = { "text", "plaintex", "tex", "markdown" },
|
filetypes = { "text", "plaintex", "tex", "markdown" },
|
||||||
settings = {
|
settings = {
|
||||||
ltex = {
|
ltex = {
|
||||||
@ -164,41 +161,49 @@ if utils.executable("ltex-ls") then
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
flags = { debounce_text_changes = 300 },
|
flags = { debounce_text_changes = 300 },
|
||||||
}
|
})
|
||||||
|
|
||||||
|
vim.lsp.enable("ltex")
|
||||||
end
|
end
|
||||||
|
|
||||||
if utils.executable("clangd") then
|
if utils.executable("clangd") then
|
||||||
lspconfig.clangd.setup {
|
vim.lsp.config("clangd", {
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
filetypes = { "c", "cpp", "cc" },
|
filetypes = { "c", "cpp", "cc" },
|
||||||
flags = {
|
flags = {
|
||||||
debounce_text_changes = 500,
|
debounce_text_changes = 500,
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
|
vim.lsp.enable("clangd")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set up vim-language-server
|
-- set up vim-language-server
|
||||||
if utils.executable("vim-language-server") then
|
if utils.executable("vim-language-server") then
|
||||||
lspconfig.vimls.setup {
|
vim.lsp.config("vimls", {
|
||||||
flags = {
|
flags = {
|
||||||
debounce_text_changes = 500,
|
debounce_text_changes = 500,
|
||||||
},
|
},
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
}
|
})
|
||||||
|
|
||||||
|
vim.lsp.enable("vimls")
|
||||||
else
|
else
|
||||||
vim.notify("vim-language-server not found!", vim.log.levels.WARN, { title = "Nvim-config" })
|
vim.notify("vim-language-server not found!", vim.log.levels.WARN, { title = "Nvim-config" })
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set up bash-language-server
|
-- set up bash-language-server
|
||||||
if utils.executable("bash-language-server") then
|
if utils.executable("bash-language-server") then
|
||||||
lspconfig.bashls.setup {
|
vim.lsp.config("bashls", {
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
}
|
})
|
||||||
|
|
||||||
|
vim.lsp.enable("bashls")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- settings for lua-language-server can be found on https://luals.github.io/wiki/settings/
|
-- settings for lua-language-server can be found on https://luals.github.io/wiki/settings/
|
||||||
if utils.executable("lua-language-server") then
|
if utils.executable("lua-language-server") then
|
||||||
lspconfig.lua_ls.setup {
|
vim.lsp.config("lua_ls", {
|
||||||
settings = {
|
settings = {
|
||||||
Lua = {
|
Lua = {
|
||||||
runtime = {
|
runtime = {
|
||||||
@ -211,5 +216,7 @@ if utils.executable("lua-language-server") then
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
}
|
})
|
||||||
|
|
||||||
|
vim.lsp.enable("lua_ls")
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user