mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 14:49:14 +00:00
nvim/lsp: revamp keymaps
This commit is contained in:
parent
eda821bf5e
commit
a644f3c688
1 changed files with 22 additions and 12 deletions
|
|
@ -1,22 +1,30 @@
|
|||
local M = {}
|
||||
|
||||
---@type vim.lsp.client.on_attach_cb
|
||||
M.on_attach = function(client, bufnr)
|
||||
local telescope = require("telescope.builtin")
|
||||
local methods = vim.lsp.protocol.Methods
|
||||
local function nnoremap(bind, callback, userargs)
|
||||
local args = userargs or {}
|
||||
args.buffer = bufnr
|
||||
vim.keymap.set("n", bind, callback, args)
|
||||
|
||||
---@param bind string
|
||||
---@param cmd function | string
|
||||
---@param desc string
|
||||
local function nnoremap(bind, cmd, desc)
|
||||
local args = {
|
||||
buffer = bufnr,
|
||||
desc = "LSP: " .. desc,
|
||||
}
|
||||
vim.keymap.set("n", bind, cmd, args)
|
||||
end
|
||||
|
||||
nnoremap("K", vim.lsp.buf.hover)
|
||||
nnoremap("<C-k>", vim.lsp.buf.signature_help)
|
||||
nnoremap("gd", telescope.lsp_definitions)
|
||||
nnoremap("gu", telescope.lsp_references)
|
||||
nnoremap("<leader>ca", vim.lsp.buf.code_action)
|
||||
nnoremap("<leader>cl", vim.lsp.codelens.run)
|
||||
nnoremap("<leader>r", vim.lsp.buf.rename)
|
||||
nnoremap("<leader>f", function() vim.lsp.buf.format { async = true } end)
|
||||
nnoremap("K", vim.lsp.buf.hover, "hover")
|
||||
nnoremap("<C-k>", vim.lsp.buf.signature_help, "signature help")
|
||||
nnoremap("gd", telescope.lsp_definitions, "goto definition(s) (telescope)")
|
||||
nnoremap("gu", telescope.lsp_references, "goto usage(s) (telescope)")
|
||||
nnoremap("<leader>ca", vim.lsp.buf.code_action, "code action")
|
||||
-- TODO: Maybe remove these or use the defaults?
|
||||
nnoremap("<leader>cl", vim.lsp.codelens.run, "run codelens")
|
||||
nnoremap("<leader>r", vim.lsp.buf.rename, "rename symbol")
|
||||
nnoremap("<leader>f", function() vim.lsp.buf.format { async = true } end, "format buffer")
|
||||
|
||||
local filetype = vim.api.nvim_get_option_value("filetype", { buf = bufnr })
|
||||
if
|
||||
|
|
@ -31,8 +39,10 @@ end
|
|||
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)
|
||||
---@type lsp.ClientCapabilities
|
||||
M.capabilities = capabilities
|
||||
|
||||
---@type string|(string|[string,string])[]
|
||||
M.border = {
|
||||
{ " ", "FloatBorder" },
|
||||
{ " ", "FloatBorder" },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue