Skip to content

Commit 3faa601

Browse files
jrentlezandreacanton
authored andcommitted
fix: regression introduced in db78c0b (nvim-lua#1367)
1 parent 410acfa commit 3faa601

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

init.lua

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,13 +565,26 @@ require('lazy').setup({
565565
-- For example, in C this would take you to the header.
566566
map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
567567

568+
-- This function resolves a difference between neovim nightly (version 0.11) and stable (version 0.10)
569+
---@param client vim.lsp.Client
570+
---@param method vim.lsp.protocol.Method
571+
---@param bufnr? integer some lsp support methods only in specific files
572+
---@return boolean
573+
local function client_supports_method(client, method, bufnr)
574+
if vim.fn.has 'nvim-0.11' == 1 then
575+
return client:supports_method(method, bufnr)
576+
else
577+
return client.supports_method(method, { bufnr = bufnr })
578+
end
579+
end
580+
568581
-- The following two autocommands are used to highlight references of the
569582
-- word under your cursor when your cursor rests there for a little while.
570583
-- See `:help CursorHold` for information about when this is executed
571584
--
572585
-- When you move your cursor, the highlights will be cleared (the second autocommand).
573586
local client = vim.lsp.get_client_by_id(event.data.client_id)
574-
if client and client:supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then
587+
if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) then
575588
local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false })
576589
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
577590
buffer = event.buf,
@@ -598,7 +611,7 @@ require('lazy').setup({
598611
-- code, if the language server you are using supports them
599612
--
600613
-- This may be unwanted, since they displace some of your code
601-
if client and client:supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then
614+
if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_inlayHint, event.buf) then
602615
map('<leader>th', function()
603616
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf })
604617
end, '[T]oggle Inlay [H]ints')

0 commit comments

Comments
 (0)