Skip to content

Commit e439eb7

Browse files
jrentlezmendoza
authored andcommitted
fix: regression introduced in db78c0b (nvim-lua#1367)
1 parent 9b64e69 commit e439eb7

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

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

0 commit comments

Comments
 (0)