dotfiles/lua/lsp.lua

121 lines
3.7 KiB
Lua
Raw Normal View History

2021-11-25 22:10:31 +01:00
local on_attach = function(client, bufnr)
local utils = require('utils')
2021-11-25 22:10:31 +01:00
-- Mappings.
utils.map("n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>")
utils.map("n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>")
utils.map("n", "<M-k>", "<cmd>lua vim.lsp.buf.type_definition()<CR>")
utils.map("n", "<M-r>", "<cmd>lua vim.lsp.buf.rename()()<CR>")
2024-01-04 00:45:21 +01:00
utils.map("n", "[d", "<cmd>lua vim.diagnostic.goto_prev()<CR>")
utils.map("n", "]d", "<cmd>lua vim.diagnostic.goto_next()<CR>")
utils.map("n", "<leader>wl", "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>")
utils.map("n", "<leader>wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>")
utils.map("n", "<leader>wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>")
-- Set formatting keybinds conditional on server capabilities
2022-10-23 01:48:10 +02:00
if client.server_capabilities.document_formatting then
utils.map('n', '<leader>lf', '<cmd>lua vim.lsp.buf.formatting()<CR>')
2022-10-23 01:48:10 +02:00
elseif client.server_capabilities.document_range_formatting then
utils.map('n', '<leader>lf', '<cmd>lua vim.lsp.buf.range_formatting()<CR>')
2021-11-25 22:10:31 +01:00
end
2023-05-16 02:25:48 +02:00
client.server_capabilities.semanticTokensProvider = nil
2021-11-25 22:10:31 +01:00
end
local nvim_lsp = require('lspconfig')
local capabilities = vim.lsp.protocol.make_client_capabilities()
-- show snippets in code completion popup
2021-11-25 22:10:31 +01:00
capabilities.textDocument.completion.completionItem.snippetSupport = true;
-- LSPs
local servers = {
"clangd",
"gleam",
"lua_ls",
"ocamllsp",
2024-01-02 01:43:10 +01:00
"pyright",
"rnix",
2024-01-02 01:43:10 +01:00
"ruff_lsp",
2024-02-26 14:03:08 +01:00
"terraformls",
"vimls",
}
2021-11-25 22:10:31 +01:00
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {capabilities = capabilities, on_attach = on_attach}
end
nvim_lsp.rust_analyzer.setup({
on_attach = on_attach,
capabilities = capabilities,
settings = {
["rust-analyzer"] = {
imports = {
granularity = {
group = "module",
},
prefix = "self",
},
cargo = {
buildScripts = {
enable = true,
},
},
2024-01-04 00:45:21 +01:00
--procMacro = {
-- enable = true
--},
checkOnSave = {
command = "clippy",
},
}
}
})
vim.g.code_action_menu_window_border = 'single'
2021-11-25 22:10:31 +01:00
-- 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 = {}
}
-- LSP Enable diagnostics
vim.lsp.handlers["textDocument/publishDiagnostics"] =
vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = false,
underline = true,
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)
2022-10-23 01:48:10 +02:00
local diagnostics = vim.diagnostic.get()
2021-11-25 22:10:31 +01:00
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