Skip to content

Commit

Permalink
nvim: adpat for upstream change of default mappings for LSP and diagn…
Browse files Browse the repository at this point in the history
  • Loading branch information
rockyzhang24 committed Apr 26, 2024
1 parent 2b87aaf commit 60b559e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions .config/nvim/lua/rockyz/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,34 @@ local function on_attach(client, bufnr)
border = vim.g.border_style,
})
end
--
-- Mappings
--
-- Nvim creates the following default maps:
-- * crr in NORMAL and VISUAL mode maps to vim.lsp.buf.code_action()
-- * crn in NORMAL mode maps to vim.lsp.buf.rename()
-- * gr in NORMAL maps to vim.lsp.buf.references()
-- * <C-s> in INSERT maps to vim.lsp.buf.signature_help()
-- * K in NORMAL mode maps vim.lsp.buf.hover()
-- * ]d and [d in NORMAL mode map to vim.diagnostic.goto_next() and vim.diagnostic.goto_prev()
-- * <C-w>d and <C-w><C-d> map to vim.diagnostic.open_float()
local opts = { buffer = bufnr }
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gy', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', 'gI', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', '<Leader>rn', vim.lsp.buf.rename, opts)
-- Code actions under the cursor
-- TODO: so far vim.lsp.buf.code_action() returns code actions on the entire cursor line, not
-- just right under the cursor. So I extracted only those diagnostics overlapping the cursor and
-- use them to get code actions. Once this issue https://github.com/neovim/neovim/issues/21985
-- is solved, we just need to directly call vim.lsp.buf.code_action().
vim.keymap.set({ 'n', 'x' }, '<Leader>ca', function()
vim.keymap.set({ 'n', 'x' }, 'crr', function()
vim.lsp.buf.code_action({
context = {
diagnostics = require('rockyz.lsp.utils').get_diagnostics_under_cursor(),
},
})
end, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('i', '<C-s>', vim.lsp.buf.signature_help, opts)
-- Diagnostics
vim.keymap.set('n', 'go', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '[d', function()
Expand All @@ -86,8 +92,7 @@ local function on_attach(client, bufnr)
vim.keymap.set('n', ']e', function()
vim.diagnostic.goto_next({ severity = vim.diagnostic.severity.ERROR })
end, opts)
-- Feed all diagnostics to quickfix list, or buffer diagnostics to location
-- list
-- Feed all diagnostics to quickfix list, or buffer diagnostics to location list
vim.keymap.set('n', '<Leader>dq', vim.diagnostic.setqflist, opts)
vim.keymap.set('n', '<Leader>dl', vim.diagnostic.setloclist, opts)
-- Format
Expand Down
2 changes: 1 addition & 1 deletion .config/nvim/lua/rockyz/plugins/conform.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Use conform for gq
-- Make gq use conform to format lines
vim.o.formatexpr = "v:lua.require('conform').formatexpr()"

local conform = require('conform')
Expand Down

0 comments on commit 60b559e

Please sign in to comment.