2023-05-04 12:39:25 +01:00
|
|
|
-- Use an on_attach function to only map the following keys
|
|
|
|
-- after the language server attaches to the current buffer
|
2023-05-16 09:22:33 +01:00
|
|
|
local on_attach = function(client, bufnr)
|
2023-05-04 12:39:25 +01:00
|
|
|
-- Mappings.
|
|
|
|
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
|
|
|
local bufopts = { noremap = true, silent = true, buffer = bufnr }
|
2023-05-17 14:57:53 +01:00
|
|
|
vim.keymap.set("n", "gd", vim.lsp.buf.definition, bufopts)
|
|
|
|
vim.keymap.set("n", "gr", vim.lsp.buf.references, bufopts)
|
|
|
|
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, bufopts)
|
2023-05-04 12:39:25 +01:00
|
|
|
vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts)
|
|
|
|
vim.keymap.set("n", "<leader>D", vim.lsp.buf.type_definition, bufopts)
|
|
|
|
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, bufopts)
|
|
|
|
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, bufopts)
|
2023-05-17 17:03:02 +01:00
|
|
|
vim.keymap.set(
|
|
|
|
"n",
|
|
|
|
"<leader>i",
|
|
|
|
function() vim.lsp.buf.format { bufnr = bufnr, timeout_ms = 2000, async = true } end,
|
|
|
|
bufopts
|
|
|
|
)
|
|
|
|
|
|
|
|
-- specific client tweaks
|
|
|
|
if client.name ~= "null-ls" then client.server_capabilities.documentFormattingProvider = false end
|
|
|
|
if client.name == "ruff_lsp" then client.server_capabilities.hoverProvider = false end
|
|
|
|
|
|
|
|
-- Attach navic and navbuddy if applicable
|
2023-05-16 09:22:33 +01:00
|
|
|
if client.server_capabilities.documentSymbolProvider then
|
|
|
|
require("nvim-navic").attach(client, bufnr)
|
|
|
|
require("nvim-navbuddy").attach(client, bufnr)
|
|
|
|
end
|
2023-05-04 12:39:25 +01:00
|
|
|
end
|
|
|
|
return on_attach
|