nixos/home/tui/config/nvim/lua/lsp/attach.lua
Evie Litherland-Smith 9567908cb7 Rewrite keymap definition, add nvim-navbuddy
Move plugin-specific keymaps into init section of plugin definition
Add nvim-navbuddy for breadcrumbs navigation
Remove aerial as replaced by navbuddy
2023-05-11 08:51:35 +01:00

28 lines
1.6 KiB
Lua

-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set("n", "gD", vim.lsp.buf.definition, bufopts)
vim.keymap.set("n", "gd", "<cmd>Trouble lsp_definitions<cr>", bufopts)
vim.keymap.set("n", "gR", vim.lsp.buf.references, bufopts)
vim.keymap.set("n", "gr", "<cmd>Trouble lsp_references<cr>", bufopts)
vim.keymap.set("n", "gI", vim.lsp.buf.implementation, bufopts)
vim.keymap.set("n", "gi", "<cmd>Trouble lsp_implementations<cr>", bufopts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts)
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, bufopts)
vim.keymap.set("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, bufopts)
vim.keymap.set("n", "<leader>wr", vim.lsp.buf.remove_workspace_folder, bufopts)
vim.keymap.set("n", "<leader>wl", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, 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)
vim.keymap.set("n", "<leader>i", require "lsp.formatting", bufopts)
if client.server_capabilities.documentSymbolProvider then
require("nvim-navic").attach(client, bufnr)
require("nvim-navbuddy").attach(client, bufnr)
end
end
return on_attach