Skip to content

Commit 17f7e6a

Browse files
committed
refactor(nvim): sync with kickstart-nvim 0.11 lsp settings
Use same keymaps as 0.11: nvim-lua/kickstart.nvim#1427 Signed-off-by: Tom Saeger <tom.saeger@gmail.com>
1 parent 963f17d commit 17f7e6a

File tree

1 file changed

+43
-22
lines changed

1 file changed

+43
-22
lines changed

lua/plugins/lsp.lua

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,53 +36,74 @@ return {
3636
vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
3737
end
3838

39-
-- Jump to the definition of the word under your cursor.
40-
-- This is where a variable was first declared, or where a function is defined, etc.
41-
-- To jump back, press <C-t>.
42-
map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
43-
map('<leader>cgd', require('telescope.builtin').lsp_definitions, '[C]ode [G]oto [D]efinition')
39+
-- Rename the variable under your cursor.
40+
-- Most Language Servers support renaming across files, etc.
41+
map('grn', vim.lsp.buf.rename, '[R]e[n]ame')
42+
map('<leader>cn', vim.lsp.buf.rename, '[C]ode Re[n]ame')
43+
44+
-- Execute a code action, usually your cursor needs to be on top of an error
45+
-- or a suggestion from your LSP for this to activate.
46+
map('gra', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' })
47+
map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' })
4448

4549
-- Find references for the word under your cursor.
46-
map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
50+
map('grr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
4751
map('<leader>cgr', require('telescope.builtin').lsp_references, '[C]ode [G]oto [R]eferences')
4852

4953
-- Jump to the implementation of the word under your cursor.
5054
-- Useful when your language has ways of declaring types without an actual implementation.
51-
map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
55+
map('gri', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
5256
map('<leader>cgI', require('telescope.builtin').lsp_implementations, '[C]ode [G]oto [I]mplementation')
5357

58+
-- Jump to the definition of the word under your cursor.
59+
-- This is where a variable was first declared, or where a function is defined, etc.
60+
-- To jump back, press <C-t>.
61+
map('grd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
62+
map('<leader>cgd', require('telescope.builtin').lsp_definitions, '[C]ode [G]oto [D]efinition')
63+
5464
-- This is not Goto Definition, this is Goto Declaration.
5565
-- For example, in C this would take you to the header.
56-
map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
66+
map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
5767
map('<leader>cgD', vim.lsp.buf.declaration, '[C]ode [G]oto [D]eclaration')
5868

59-
-- Jump to the type of the word under your cursor.
60-
-- Useful when you're not sure what type a variable is and you want to see
61-
-- the definition of its *type*, not where it was *defined*.
62-
map('<leader>cgt', require('telescope.builtin').lsp_type_definitions, '[C]ode [G]oto [T]ype Definition')
63-
6469
-- Fuzzy find all the symbols in your current document.
6570
-- Symbols are things like variables, functions, types, etc.
71+
map('gO', require('telescope.builtin').lsp_document_symbols, 'Open Document Symbols')
6672
map('<leader>cds', require('telescope.builtin').lsp_document_symbols, '[C]ode [D]ocument [S]ymbols')
6773

6874
-- Fuzzy find all the symbols in your current workspace.
6975
-- Similar to document symbols, except searches over your entire project.
76+
map('gW', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Open Workspace Symbols')
7077
map('<leader>cws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[C]ode [W]orkspace [S]ymbols')
7178

72-
-- Rename the variable under your cursor.
73-
-- Most Language Servers support renaming across files, etc.
74-
map('<leader>cn', vim.lsp.buf.rename, '[C]ode Re[n]ame')
79+
-- Jump to the type of the word under your cursor.
80+
-- Useful when you're not sure what type a variable is and you want to see
81+
-- the definition of its *type*, not where it was *defined*.
82+
map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definition')
83+
map('<leader>cgt', require('telescope.builtin').lsp_type_definitions, '[C]ode [G]oto [T]ype Definition')
7584

76-
-- Execute a code action, usually your cursor needs to be on top of an error
77-
-- or a suggestion from your LSP for this to activate.
78-
map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' })
85+
-- This function resolves a difference between neovim nightly (version 0.11) and stable (version 0.10)
86+
---@param client vim.lsp.Client
87+
---@param method vim.lsp.protocol.Method
88+
---@param bufnr? integer some lsp support methods only in specific files
89+
---@return boolean
90+
local function client_supports_method(client, method, bufnr)
91+
if vim.fn.has 'nvim-0.11' == 1 then
92+
return client:supports_method(method, bufnr)
93+
else
94+
return client.supports_method(method, { bufnr = bufnr })
95+
end
96+
end
7997

8098
-- The following two autocommands are used to highlight references of the
8199
-- word under your cursor when your cursor rests there for a little while.
82100
-- See `:help CursorHold` for information about when this is executed
101+
--
83102
-- When you move your cursor, the highlights will be cleared (the second autocommand).
84103
local client = vim.lsp.get_client_by_id(event.data.client_id)
85-
if client and client:supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) then
104+
if
105+
client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf)
106+
then
86107
local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false })
87108
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
88109
buffer = event.buf,
@@ -106,7 +127,7 @@ return {
106127
end
107128

108129
-- keymap for inlay hint toggle if supported by LSP
109-
if client and client:supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint, event.buf) then
130+
if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_inlayHint, event.buf) then
110131
map('<leader>ch', function()
111132
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf })
112133
end, '[C]ode Toggle Inlay [H]ints')
@@ -145,7 +166,7 @@ return {
145166
-- },
146167
},
147168
-- gopls = {},
148-
basedpyright = { enabled = false },
169+
basedpyright = { enabled = true },
149170
rust_analyzer = {
150171
-- prevent auto-config of rust_analyzer which interferes with rustaceanvim
151172
skip_autoconfigure = true,

0 commit comments

Comments
 (0)