@@ -9,6 +9,28 @@ local loop = require("null-ls.loop")
9
9
local api = vim .api
10
10
local lsp = vim .lsp
11
11
12
+ -- Inspired by upstream neovim:
13
+ -- <https://github.com/neovim/neovim/blob/43d552c56648bc3125c7509b3d708b6bf6c0c09c/runtime/lua/vim/lsp/client.lua#L234-L249>.
14
+ -- This can go away sometime after neovim drops support for the legacy way
15
+ -- of invoking these functions.
16
+ -- Alternatively, we could get out of the business of monkeypatching Neovim
17
+ -- functions, see <https://github.com/nvimtools/none-ls.nvim/discussions/229>.
18
+ --- @param obj table<string,any>
19
+ --- @param cls table<string,function>
20
+ --- @param name string
21
+ local function method_wrapper (obj , cls , name )
22
+ local func = assert (obj [name ], " couldn't find " .. name .. " function" )
23
+ obj [name ] = function (maybe_self , ...)
24
+ if maybe_self and getmetatable (maybe_self ) == cls then
25
+ -- First argument is self. Drop it and call `func` directly.
26
+ return func (... )
27
+ end
28
+ vim .deprecate (" client." .. name , " client:" .. name , " 0.13" )
29
+ -- First argument is not self, include it when calling `func`.
30
+ return func (maybe_self , ... )
31
+ end
32
+ end
33
+
12
34
--- @type vim.lsp.Client ?, integer ?
13
35
local client , id
14
36
@@ -75,12 +97,9 @@ local on_init = function(new_client, initialize_result)
75
97
return methods .lsp [method ] ~= nil
76
98
end
77
99
100
+ new_client .supports_method = supports_method
78
101
if vim .fn .has (" nvim-0.11" ) == 1 then
79
- new_client .supports_method = function (_ , method )
80
- return supports_method (method )
81
- end
82
- else
83
- new_client .supports_method = supports_method
102
+ method_wrapper (new_client , vim .lsp .client , " supports_method" )
84
103
end
85
104
86
105
if c .get ().on_init then
0 commit comments