Add descriptions for lsp-shortcuts
Since I use which-key I can actually benefit a lot from meaningful descriptions of my custom shortcuts. Whenever I feel like I forgot a multi-key shortcut I can simply type the first letter (in my case usually "Space" or "g") and peek into the preview of whichkey. It lists all possible additional keystrokes and their descriptions, so this change makes it a lot easier for me to find the command I'm looking for.
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
local on_attach = function(_, bufnr)
|
||||
local desc = function (desc)
|
||||
return { noremap = true, silent = true, buffer = bufnr, desc = desc }
|
||||
end
|
||||
local ts = require("telescope.builtin")
|
||||
local opts = { noremap = true, silent = true, buffer = bufnr }
|
||||
vim.keymap.set("n", "<Leader>rn", vim.lsp.buf.rename, opts)
|
||||
vim.keymap.set("n", "<Leader>ca", vim.lsp.buf.code_action, opts)
|
||||
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
|
||||
vim.keymap.set("n", "ge", vim.diagnostic.open_float, opts)
|
||||
vim.keymap.set("n", "gf", function() vim.lsp.buf.format { async = true } end, opts)
|
||||
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
|
||||
vim.keymap.set("n", "gk", vim.lsp.buf.hover, opts)
|
||||
vim.keymap.set("n", "gK", vim.lsp.buf.signature_help, opts)
|
||||
vim.keymap.set("n", "gn", function() vim.diagnostic.jump({ count = 1, float = true }) end, opts)
|
||||
vim.keymap.set("n", "gN", function() vim.diagnostic.jump({ count = -1, float = true }) end, opts)
|
||||
vim.keymap.set("n", "gr", ts.lsp_references, opts)
|
||||
vim.keymap.set("n", "<Leader>rn", vim.lsp.buf.rename, desc("Rename identifier"))
|
||||
vim.keymap.set("n", "<Leader>ca", vim.lsp.buf.code_action, desc("Code actions"))
|
||||
vim.keymap.set("n", "gd", vim.lsp.buf.definition, desc("Jump to definition"))
|
||||
vim.keymap.set("n", "ge", vim.diagnostic.open_float, desc("Open diagnostics, show errors"))
|
||||
vim.keymap.set("n", "gf", function() vim.lsp.buf.format { async = true } end, desc("Format code"))
|
||||
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, desc("Jump to implementation"))
|
||||
vim.keymap.set("n", "gk", vim.lsp.buf.hover, desc("Show quick-docs"))
|
||||
vim.keymap.set("n", "gK", vim.lsp.buf.signature_help, desc("Show signature"))
|
||||
vim.keymap.set("n", "gn", function() vim.diagnostic.jump({ count = 1, float = true }) end, desc("Jump to next occurence"))
|
||||
vim.keymap.set("n", "gN", function() vim.diagnostic.jump({ count = -1, float = true }) end, desc("Jump to previous occurence"))
|
||||
vim.keymap.set("n", "gr", ts.lsp_references, desc("Search references"))
|
||||
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
|
||||
end
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ vim.api.nvim_create_autocmd("FileType", {
|
||||
vim.opt_local.wrap = true
|
||||
vim.opt_local.number = false
|
||||
vim.opt_local.relativenumber = false
|
||||
vim.keymap.set("n", "<Leader>ws", "<Cmd>Gw | G commit-and-push<CR>")
|
||||
vim.keymap.set("n", "<Leader>ws", "<Cmd>Gw | G commit-and-push<CR>", { desc = "Save, commit & push" })
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user