96 lines
2.8 KiB
Lua
96 lines
2.8 KiB
Lua
|
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>")
|
||
|
vim.keymap.set("n", "<M-k>", "<cmd>lua vim.lsp.buf.type_definition()<CR>")
|
||
|
vim.keymap.set("n", "<M-r>", "<cmd>lua vim.lsp.buf.rename()()<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>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_create_autocmd("BufWritePre", {
|
||
|
buffer = bufnr,
|
||
|
callback = function()
|
||
|
vim.lsp.buf.format()
|
||
|
end,
|
||
|
})
|
||
|
end
|
||
|
|
||
|
-- 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, {})
|
||
|
end
|
||
|
end
|
||
|
|
||
|
local nvim_lsp = require('lspconfig')
|
||
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||
|
|
||
|
-- LSPs
|
||
|
local servers = {
|
||
|
"clangd",
|
||
|
"dartls",
|
||
|
"gleam",
|
||
|
"lua_ls",
|
||
|
"ocamllsp",
|
||
|
"pyright",
|
||
|
"rnix",
|
||
|
"terraformls",
|
||
|
"vimls",
|
||
|
}
|
||
|
for _, lsp in ipairs(servers) do
|
||
|
nvim_lsp[lsp].setup { capabilities = capabilities, on_attach = common_on_attach }
|
||
|
end
|
||
|
|
||
|
nvim_lsp.rust_analyzer.setup({
|
||
|
on_attach = common_on_attach,
|
||
|
capabilities = capabilities,
|
||
|
settings = {
|
||
|
["rust-analyzer"] = {
|
||
|
imports = {
|
||
|
granularity = {
|
||
|
group = "module",
|
||
|
},
|
||
|
prefix = "self",
|
||
|
},
|
||
|
cargo = {
|
||
|
buildScripts = {
|
||
|
enable = true,
|
||
|
},
|
||
|
},
|
||
|
procMacro = {
|
||
|
enable = true
|
||
|
},
|
||
|
checkOnSave = {
|
||
|
command = "clippy",
|
||
|
},
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
|
||
|
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 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
|
||
|
})
|