Skip to content

Commit d2225ad

Browse files
jrentlezdribic
authored andcommitted
fix: regression introduced in db78c0b (nvim-lua#1367)
Signed-off-by: Dejan Ribič <dejan.ribic@gmail.com>
1 parent 19307bb commit d2225ad

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
@@ -561,13 +561,26 @@ require('lazy').setup({
561561
-- For example, in C this would take you to the header.
562562
map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
563563

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

0 commit comments

Comments
 (0)