Skip to content

Commit 2d684e4

Browse files
author
Ted Leahy
committed
fix: regression introduced in db78c0b (nvim-lua#1367)
1 parent 8d45c98 commit 2d684e4

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

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

0 commit comments

Comments
 (0)