Skip to content

Commit ccb4469

Browse files
jrentlezShadowmeister
authored andcommitted
fix: regression introduced in db78c0b (nvim-lua#1367)
1 parent 1e16279 commit ccb4469

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

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

0 commit comments

Comments
 (0)