Skip to content

Commit bb09a0f

Browse files
nvim: better lsp support
1 parent d5d7a26 commit bb09a0f

1 file changed

Lines changed: 32 additions & 9 deletions

File tree

.config/cvim/keymap/03_code_completion.lua

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ vim.api.nvim_create_autocmd('LspAttach', {
1313
-- NOTE:
1414
-- Q1: How to know if vim.lsp.protocol.Methods.textDocument_completion is defined ?
1515
-- A1: See https://raw.githubusercontent.com/neovim/neovim/d2e445e1bd321ea43b976d6aa7759d90b826ce62/runtime/lua/vim/lsp/protocol.lua
16-
16+
-- Q2: How to know the LSP method name ?
17+
-- Q2: See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocument_codeAction
1718

1819
local client = vim.lsp.get_client_by_id(ev.data.client_id)
1920
local buffer = ev.buf
@@ -34,16 +35,15 @@ vim.api.nvim_create_autocmd('LspAttach', {
3435
}
3536
)
3637
end
37-
3838
-- Enable LLM-based completion support
3939
if client:supports_method(vim.lsp.protocol.Methods.textDocument_inlineCompletion) then
4040
vim.opt.completeopt = {'menu', 'menuone', 'noinsert', 'fuzzy', 'popup'}
41-
vim.lsp.inline.completion.enable(true, client.id, buffer, {autotrigger = true})
41+
vim.lsp.inline_completion.enable(true, { client_id = client.id, buffer = buffer})
4242
vim.keymap.set(
4343
'i', '<Tab>',
4444
function()
4545
-- Retrieve LSP completion candidates
46-
if not vim.lsp.completion.get() then
46+
if not vim.lsp.inline_completion.get() then
4747
return "<Tab>"
4848
end
4949
end,
@@ -53,8 +53,6 @@ vim.api.nvim_create_autocmd('LspAttach', {
5353
buffer = buffer
5454
}
5555
)
56-
57-
-- Show next inline completion suggestion
5856
vim.keymap.set(
5957
'i', '<M-n>',
6058
function()
@@ -65,7 +63,6 @@ vim.api.nvim_create_autocmd('LspAttach', {
6563
buffer = buffer
6664
}
6765
)
68-
-- Show previous inline completion suggestion
6966
vim.keymap.set(
7067
'i', '<M-p>',
7168
function()
@@ -77,7 +74,22 @@ vim.api.nvim_create_autocmd('LspAttach', {
7774
}
7875
)
7976
end
80-
77+
-- Enable code lens support
78+
if client:supports_method(vim.lsp.protocol.Methods.textDocument_codeLens) then
79+
local gid = vim.api.nvim_create_augroup("UserLSPDocumentCodeLens", { clear = true })
80+
vim.api.nvim_create_autocmd({"CursorHold","InsertLeave"}, {
81+
group = gid,
82+
buffer = buffer,
83+
callback = function()
84+
vim.lsp.codelens.refresh({ bufnr = buffer })
85+
end,
86+
desc = "Display code lens"
87+
})
88+
end
89+
-- Enable diagonstic support
90+
if client:supports_method(vim.lsp.protocol.Methods.textDocument_diagnostic) then
91+
-- FIXME what to do ?
92+
end
8193
-- Enable declaration support
8294
if client:supports_method(vim.lsp.protocol.Methods.textDocument_declaration) then
8395
vim.keymap.set(
@@ -221,7 +233,6 @@ vim.api.nvim_create_autocmd('LspAttach', {
221233
end,
222234
desc = "Highlight current variable and usage in buffer"
223235
})
224-
225236
vim.api.nvim_create_autocmd("CursorMoved", {
226237
group = gid,
227238
buffer = bufnr,
@@ -231,6 +242,10 @@ vim.api.nvim_create_autocmd('LspAttach', {
231242
desc = "Clear references"
232243
})
233244
end
245+
-- Enable document color support
246+
if client:supports_method(vim.lsp.protocol.Methods.textDocument_documentColor) then
247+
vim.lsp.document_color.enable(true, buffer)
248+
end
234249
-- Enable Inlay hint support
235250
if client.server_capabilities.inlayHintProvider then
236251
vim.lsp.inlay_hint.enable(true, {buffer = buffer})
@@ -281,6 +296,14 @@ vim.api.nvim_create_autocmd('LspAttach', {
281296
}
282297
)
283298
end
299+
-- Enable linked editing range support
300+
if client:supports_method(vim.lsp.protocol.Methods.textDocument_linkedEditingRange) then
301+
vim.lsp.linked_editing_range.enable(true, { client_id = client.id })
302+
end
303+
-- Enable semantic token support
304+
if client:supports_method(vim.lsp.protocol.Methods.textDocument_semanticTokens_full) then
305+
vim.lsp.semantic_tokens.enable(true, { client_id = client.id, buffer = buffer })
306+
end
284307
end,
285308
nested = true,
286309
desc = "Configure buffer keymap and LSP based behaviour"

0 commit comments

Comments
 (0)