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 augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
||||
|
||||
local common_on_attach = function(client, bufnr)
|
||||
-- Mappings.
|
||||
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>")
|
||||
|
@ -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>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>r", "<cmd>lua vim.lsp.buf.rename()<CR>")
|
||||
|
||||
-- Autoformat on save.
|
||||
if client.supports_method("textDocument/formatting") then
|
||||
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
group = augroup,
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
vim.lsp.buf.format()
|
||||
|
@ -21,7 +19,7 @@ local on_attach = function(client, bufnr)
|
|||
})
|
||||
end
|
||||
|
||||
-- use vim's default coloring
|
||||
-- Use vim's default coloring.
|
||||
client.server_capabilities.semanticTokensProvider = nil
|
||||
for _, group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do
|
||||
vim.api.nvim_set_hl(0, group, {})
|
||||
|
@ -40,16 +38,15 @@ local servers = {
|
|||
"ocamllsp",
|
||||
"pyright",
|
||||
"rnix",
|
||||
"ruff_lsp",
|
||||
"terraformls",
|
||||
"vimls",
|
||||
}
|
||||
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
|
||||
|
||||
nvim_lsp.rust_analyzer.setup({
|
||||
on_attach = on_attach,
|
||||
on_attach = common_on_attach,
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
["rust-analyzer"] = {
|
||||
|
@ -74,26 +71,21 @@ nvim_lsp.rust_analyzer.setup({
|
|||
}
|
||||
})
|
||||
|
||||
vim.g.code_action_menu_window_border = 'single'
|
||||
|
||||
-- symbols-outline.nvim
|
||||
vim.g.symbols_outline = {
|
||||
highlight_hovered_item = true,
|
||||
show_guides = true,
|
||||
auto_preview = false, -- experimental
|
||||
position = 'right',
|
||||
keymaps = {
|
||||
close = "<Esc>",
|
||||
goto_location = "<Cr>",
|
||||
focus_location = "o",
|
||||
hover_symbol = "<C-space>",
|
||||
rename_symbol = "r",
|
||||
code_actions = "a"
|
||||
},
|
||||
lsp_blacklist = {}
|
||||
nvim_lsp.ruff.setup({
|
||||
on_attach = function (client)
|
||||
common_on_attach(client)
|
||||
client.server_capabilities.renameProvider = false
|
||||
client.server_capabilities.hoverProvider = false
|
||||
end,
|
||||
init_options = {
|
||||
settings = {
|
||||
-- Any extra CLI arguments for `ruff` go here.
|
||||
args = {}
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
-- LSP Enable diagnostics
|
||||
-- LSP diagnostics.
|
||||
vim.lsp.handlers["textDocument/publishDiagnostics"] =
|
||||
vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
|
||||
virtual_text = false,
|
||||
|
@ -101,23 +93,3 @@ vim.lsp.handlers["textDocument/publishDiagnostics"] =
|
|||
signs = true,
|
||||
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