cleanup lsp module
This commit is contained in:
parent
d7f591fd26
commit
c0e15e1141
1 changed files with 19 additions and 47 deletions
66
lua/lsp.lua
66
lua/lsp.lua
|
@ -1,6 +1,4 @@
|
||||||
local on_attach = function(client, bufnr)
|
local common_on_attach = function(client, bufnr)
|
||||||
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
|
||||||
|
|
||||||
-- Mappings.
|
-- Mappings.
|
||||||
vim.keymap.set("n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>")
|
vim.keymap.set("n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>")
|
||||||
vim.keymap.set("n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>")
|
vim.keymap.set("n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>")
|
||||||
|
@ -9,11 +7,11 @@ local on_attach = function(client, bufnr)
|
||||||
vim.keymap.set("n", "<leader>wl", "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>")
|
vim.keymap.set("n", "<leader>wl", "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>")
|
||||||
vim.keymap.set("n", "<leader>wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>")
|
vim.keymap.set("n", "<leader>wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>")
|
||||||
vim.keymap.set("n", "<leader>wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>")
|
vim.keymap.set("n", "<leader>wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>")
|
||||||
|
vim.keymap.set("n", "<leader>r", "<cmd>lua vim.lsp.buf.rename()<CR>")
|
||||||
|
|
||||||
|
-- Autoformat on save.
|
||||||
if client.supports_method("textDocument/formatting") then
|
if client.supports_method("textDocument/formatting") then
|
||||||
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
|
||||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
group = augroup,
|
|
||||||
buffer = bufnr,
|
buffer = bufnr,
|
||||||
callback = function()
|
callback = function()
|
||||||
vim.lsp.buf.format()
|
vim.lsp.buf.format()
|
||||||
|
@ -21,7 +19,7 @@ local on_attach = function(client, bufnr)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- use vim's default coloring
|
-- Use vim's default coloring.
|
||||||
client.server_capabilities.semanticTokensProvider = nil
|
client.server_capabilities.semanticTokensProvider = nil
|
||||||
for _, group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do
|
for _, group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do
|
||||||
vim.api.nvim_set_hl(0, group, {})
|
vim.api.nvim_set_hl(0, group, {})
|
||||||
|
@ -40,16 +38,15 @@ local servers = {
|
||||||
"ocamllsp",
|
"ocamllsp",
|
||||||
"pyright",
|
"pyright",
|
||||||
"rnix",
|
"rnix",
|
||||||
"ruff_lsp",
|
|
||||||
"terraformls",
|
"terraformls",
|
||||||
"vimls",
|
"vimls",
|
||||||
}
|
}
|
||||||
for _, lsp in ipairs(servers) do
|
for _, lsp in ipairs(servers) do
|
||||||
nvim_lsp[lsp].setup { capabilities = capabilities, on_attach = on_attach }
|
nvim_lsp[lsp].setup { capabilities = capabilities, on_attach = common_on_attach }
|
||||||
end
|
end
|
||||||
|
|
||||||
nvim_lsp.rust_analyzer.setup({
|
nvim_lsp.rust_analyzer.setup({
|
||||||
on_attach = on_attach,
|
on_attach = common_on_attach,
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
settings = {
|
settings = {
|
||||||
["rust-analyzer"] = {
|
["rust-analyzer"] = {
|
||||||
|
@ -74,26 +71,21 @@ nvim_lsp.rust_analyzer.setup({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
vim.g.code_action_menu_window_border = 'single'
|
nvim_lsp.ruff.setup({
|
||||||
|
on_attach = function (client)
|
||||||
-- symbols-outline.nvim
|
common_on_attach(client)
|
||||||
vim.g.symbols_outline = {
|
client.server_capabilities.renameProvider = false
|
||||||
highlight_hovered_item = true,
|
client.server_capabilities.hoverProvider = false
|
||||||
show_guides = true,
|
end,
|
||||||
auto_preview = false, -- experimental
|
init_options = {
|
||||||
position = 'right',
|
settings = {
|
||||||
keymaps = {
|
-- Any extra CLI arguments for `ruff` go here.
|
||||||
close = "<Esc>",
|
args = {}
|
||||||
goto_location = "<Cr>",
|
}
|
||||||
focus_location = "o",
|
|
||||||
hover_symbol = "<C-space>",
|
|
||||||
rename_symbol = "r",
|
|
||||||
code_actions = "a"
|
|
||||||
},
|
},
|
||||||
lsp_blacklist = {}
|
})
|
||||||
}
|
|
||||||
|
|
||||||
-- LSP Enable diagnostics
|
-- LSP diagnostics.
|
||||||
vim.lsp.handlers["textDocument/publishDiagnostics"] =
|
vim.lsp.handlers["textDocument/publishDiagnostics"] =
|
||||||
vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
|
vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
|
||||||
virtual_text = false,
|
virtual_text = false,
|
||||||
|
@ -101,23 +93,3 @@ vim.lsp.handlers["textDocument/publishDiagnostics"] =
|
||||||
signs = true,
|
signs = true,
|
||||||
update_in_insert = false
|
update_in_insert = false
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Send diagnostics to quickfix list
|
|
||||||
do
|
|
||||||
local method = "textDocument/publishDiagnostics"
|
|
||||||
local default_handler = vim.lsp.handlers[method]
|
|
||||||
vim.lsp.handlers[method] = function(err, method, result, client_id, bufnr, config)
|
|
||||||
default_handler(err, method, result, client_id, bufnr, config)
|
|
||||||
local diagnostics = vim.diagnostic.get()
|
|
||||||
local qflist = {}
|
|
||||||
for bufnr, diagnostic in pairs(diagnostics) do
|
|
||||||
for _, d in ipairs(diagnostic) do
|
|
||||||
d.bufnr = bufnr
|
|
||||||
d.lnum = d.range.start.line + 1
|
|
||||||
d.col = d.range.start.character + 1
|
|
||||||
d.text = d.message
|
|
||||||
table.insert(qflist, d)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
Loading…
Reference in a new issue