Skip to content

Commit 62a99c2

Browse files
committed
fix: make LSP client calls version-aware
1 parent 4173557 commit 62a99c2

8 files changed

Lines changed: 41 additions & 17 deletions

File tree

lua/lspsaga/callhierarchy.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ end
361361

362362
function ch:call_hierarchy(item, client, timer_close, curlnum)
363363
self.pending_request = true
364-
client:request(self.method, { item = item }, function(_, res)
364+
util.client_request(client, self.method, { item = item }, function(_, res)
365365
self.pending_request = false
366366
curlnum = curlnum or 0
367367
local inlevel = curlnum == 0 and 2 or fn.indent(curlnum)
@@ -471,7 +471,7 @@ function ch:send_prepare_call()
471471
self.list = slist.new()
472472

473473
local params = lsp.util.make_position_params(0, util.get_offset_encoding({ client = client }))
474-
client:request(get_method(1), params, function(_, result, ctx)
474+
util.client_request(client, get_method(1), params, function(_, result, ctx)
475475
if api.nvim_get_current_buf() ~= ctx.bufnr then
476476
return
477477
end

lua/lspsaga/codeaction/init.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ local function apply_action(action, client, enriched_ctx)
244244
arguments = command.arguments,
245245
workDoneToken = command.workDoneToken,
246246
}
247-
client:request('workspace/executeCommand', params, nil, enriched_ctx.bufnr)
247+
util.client_request(client, 'workspace/executeCommand', params, nil, enriched_ctx.bufnr)
248248
end
249249
end
250250
clean_ctx()
@@ -254,7 +254,7 @@ function act:support_resolve(client)
254254
if vim.version().minor >= 10 then
255255
local reg = client.dynamic_capabilities:get('textDocument/codeAction', { bufnr = ctx.bufnr })
256256
return vim.tbl_get(reg or {}, 'registerOptions', 'resolveProvider')
257-
or client:supports_method('codeAction/resolve')
257+
or util.client_supports_method(client, 'codeAction/resolve')
258258
end
259259
return vim.tbl_get(client.server_capabilities, 'codeActionProvider', 'resolveProvider')
260260
end
@@ -263,12 +263,12 @@ function act:get_resolve_action(client, action, bufnr)
263263
if not self:support_resolve(client) then
264264
return
265265
end
266-
return client:request_sync('codeAction/resolve', action, 1500, bufnr).result
266+
return util.client_request_sync(client, 'codeAction/resolve', action, 1500, bufnr).result
267267
end
268268

269269
function act:do_code_action(action, client, enriched_ctx)
270270
if not action.edit and client and self:support_resolve(client) then
271-
client:request('codeAction/resolve', action, function(err, resolved_action)
271+
util.client_request(client, 'codeAction/resolve', action, function(err, resolved_action)
272272
if err then
273273
vim.notify(err.code .. ': ' .. err.message, vim.log.levels.ERROR)
274274
return

lua/lspsaga/codeaction/lightbulb.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ local function lb_autocmd()
150150
if not client then
151151
return
152152
end
153-
if not client:supports_method('textDocument/codeAction') then
153+
if not util.client_supports_method(client, 'textDocument/codeAction') then
154154
return
155155
end
156156
if vim.tbl_contains(config.lightbulb.ignore.clients, client.name) then

lua/lspsaga/implement/init.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local api, fn = vim.api, vim.fn
33
local uv = vim.version().minor >= 10 and vim.uv or vim.loop
44
local config = require('lspsaga').config.implement
55
local ui = require('lspsaga').config.ui
6+
local util = require('lspsaga.util')
67
local ns = api.nvim_create_namespace('SagaImp')
78
local defined = false
89
local name = 'SagaImpIcon'
@@ -37,7 +38,7 @@ local function try_render(client_id, bufnr, pos, data)
3738
return
3839
end
3940
---@diagnostic disable-next-line: invisible
40-
client:request('textDocument/implementation', params, function(err, result)
41+
util.client_request(client, 'textDocument/implementation', params, function(err, result)
4142
if err or api.nvim_get_current_buf() ~= bufnr then
4243
return
4344
end

lua/lspsaga/symbol/head.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local api, lsp = vim.api, vim.lsp
33
local config = require('lspsaga').config
44
---@diagnostic disable-next-line: deprecated
55
local uv = vim.version().minor >= 10 and vim.uv or vim.loop
6+
local util = require('lspsaga.util')
67
local symbol = {}
78

89
local cache = {}
@@ -86,7 +87,7 @@ function symbol:do_request(buf, client_id)
8687
}
8788
end
8889

89-
client:request('textDocument/documentSymbol', params, function(err, result, ctx)
90+
util.client_request(client, 'textDocument/documentSymbol', params, function(err, result, ctx)
9091
if not api.nvim_buf_is_loaded(ctx.bufnr) or not self[ctx.bufnr] then
9192
return
9293
end
@@ -170,7 +171,7 @@ function symbol:register_module()
170171
end
171172

172173
local client = lsp.get_client_by_id(args.data.client_id)
173-
if not client or not client:supports_method('textDocument/documentSymbol') then
174+
if not client or not util.client_supports_method(client, 'textDocument/documentSymbol') then
174175
return
175176
end
176177

@@ -183,7 +184,7 @@ function symbol:register_module()
183184
end
184185
self:buf_watcher(args.buf, group)
185186

186-
if config.implement.enable and client:supports_method('textDocument/implementation') then
187+
if config.implement.enable and util.client_supports_method(client, 'textDocument/implementation') then
187188
require('lspsaga.implement').start()
188189
end
189190
end,

lua/lspsaga/symbol/init.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local api, lsp = vim.api, vim.lsp
22
---@diagnostic disable-next-line: deprecated
33
local uv = vim.version().minor >= 10 and vim.uv or vim.loop
44
local config = require('lspsaga').config
5+
local util = require('lspsaga.util')
56
local symbol = {}
67

78
local cache = {}
@@ -106,7 +107,7 @@ function symbol:do_request(buf, client_id)
106107

107108
self[buf].pending_request = true
108109

109-
client:request('textDocument/documentSymbol', params, function(err, result, ctx)
110+
util.client_request(client, 'textDocument/documentSymbol', params, function(err, result, ctx)
110111
if not api.nvim_buf_is_loaded(ctx.bufnr) or not self[ctx.bufnr] then
111112
return
112113
end
@@ -190,7 +191,7 @@ function symbol:register_module()
190191
end
191192

192193
local client = lsp.get_client_by_id(args.data.client_id)
193-
if not client or not client:supports_method('textDocument/documentSymbol') then
194+
if not client or not util.client_supports_method(client, 'textDocument/documentSymbol') then
194195
return
195196
end
196197
self:do_request(args.buf, args.data.client_id)
@@ -199,7 +200,7 @@ function symbol:register_module()
199200
require('lspsaga.symbol.winbar').init_winbar(args.buf)
200201
end
201202

202-
if config.implement.enable and client:supports_method('textDocument/implementation') then
203+
if config.implement.enable and util.client_supports_method(client, 'textDocument/implementation') then
203204
require('lspsaga.implement').start()
204205
end
205206
end,

lua/lspsaga/typehierarchy.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ end
361361

362362
function ch:type_hierarchy(item, client, timer_close, curlnum)
363363
self.pending_request = true
364-
client:request(self.method, { item = item }, function(_, res)
364+
util.client_request(client, self.method, { item = item }, function(_, res)
365365
self.pending_request = false
366366
curlnum = curlnum or 0
367367
local inlevel = curlnum == 0 and 2 or fn.indent(curlnum)
@@ -472,7 +472,7 @@ function ch:send_prepare_type()
472472
self.list = slist.new()
473473

474474
local params = lsp.util.make_position_params()
475-
client:request(get_method(1), params, function(_, result, ctx)
475+
util.client_request(client, get_method(1), params, function(_, result, ctx)
476476
if api.nvim_get_current_buf() ~= ctx.bufnr then
477477
return
478478
end

lua/lspsaga/util.lua

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,34 @@ local M = {}
66
M.iswin = uv.os_uname().sysname:match('Windows')
77
M.ismac = uv.os_uname().sysname == 'Darwin'
88
M.is_ten = vim.version().minor >= 10
9+
M.is_eleven = vim.version().minor >= 11
910

1011
M.path_sep = M.iswin and '\\' or '/'
1112

1213
function M.path_join(...)
1314
return table.concat({ ... }, M.path_sep)
1415
end
1516

17+
-- 0.11+ warns on dot calls; 0.10- breaks on colon calls.
18+
local function client_method_wrapper(client, name, ...)
19+
if M.is_eleven then
20+
return client[name](client, ...)
21+
end
22+
return client[name](...)
23+
end
24+
25+
function M.client_request(client, ...)
26+
return client_method_wrapper(client, 'request', ...)
27+
end
28+
29+
function M.client_request_sync(client, ...)
30+
return client_method_wrapper(client, 'request_sync', ...)
31+
end
32+
33+
function M.client_supports_method(client, ...)
34+
return client_method_wrapper(client, 'supports_method', ...)
35+
end
36+
1637
function M.path_itera(buf)
1738
local parts = vim.split(api.nvim_buf_get_name(buf), M.path_sep, { trimempty = true })
1839
local index = #parts + 1
@@ -66,7 +87,7 @@ function M.get_client_by_method(method)
6687
local supports = {}
6788

6889
for _, client in ipairs(clients or {}) do
69-
if client:supports_method(method) then
90+
if M.client_supports_method(client, method) then
7091
supports[#supports + 1] = client
7192
end
7293
end

0 commit comments

Comments
 (0)