Skip to content

Commit d086c89

Browse files
authored
fix: replace deprecated LSP client method calls with colon syntax (#1546)
* fix: replace deprecated LSP client method calls with colon syntax Replaces deprecated dot notation with colon notation for LSP client methods: - client.supports_method() → client:supports_method() - client.request() → client:request() - client.request_sync() → client:request_sync() This addresses deprecation warnings in Neovim 0.11+ as documented in :help deprecated.txt Backwards compatible: Colon syntax is just Lua syntactic sugar supported since Neovim 0.5+. No functionality changes, only modernized syntax. Fixes: #1543 * fix: make LSP client calls version-aware * fix(ci): stabilize luajit version and format symbols
1 parent 8efe00d commit d086c89

9 files changed

Lines changed: 58 additions & 24 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
- name: luajit
5656
uses: leafo/gh-actions-lua@v10
5757
with:
58-
luaVersion: "luajit-2.1.0-beta3"
58+
luaVersion: "luajit-2.1"
5959

6060
- name: luarocks
6161
uses: leafo/gh-actions-luarocks@v4

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: 12 additions & 6 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 = {}
@@ -70,9 +71,11 @@ function symbol:buf_watcher(bufnr, group)
7071
end
7172

7273
function symbol:do_request(buf, client_id)
73-
local params = { textDocument = {
74-
uri = vim.uri_from_bufnr(buf),
75-
} }
74+
local params = {
75+
textDocument = {
76+
uri = vim.uri_from_bufnr(buf),
77+
},
78+
}
7679

7780
local client = vim.lsp.get_client_by_id(client_id)
7881
if not client then
@@ -86,7 +89,7 @@ function symbol:do_request(buf, client_id)
8689
}
8790
end
8891

89-
client.request('textDocument/documentSymbol', params, function(err, result, ctx)
92+
util.client_request(client, 'textDocument/documentSymbol', params, function(err, result, ctx)
9093
if not api.nvim_buf_is_loaded(ctx.bufnr) or not self[ctx.bufnr] then
9194
return
9295
end
@@ -170,7 +173,7 @@ function symbol:register_module()
170173
end
171174

172175
local client = lsp.get_client_by_id(args.data.client_id)
173-
if not client or not client.supports_method('textDocument/documentSymbol') then
176+
if not client or not util.client_supports_method(client, 'textDocument/documentSymbol') then
174177
return
175178
end
176179

@@ -183,7 +186,10 @@ function symbol:register_module()
183186
end
184187
self:buf_watcher(args.buf, group)
185188

186-
if config.implement.enable and client.supports_method('textDocument/implementation') then
189+
if
190+
config.implement.enable
191+
and util.client_supports_method(client, 'textDocument/implementation')
192+
then
187193
require('lspsaga.implement').start()
188194
end
189195
end,

lua/lspsaga/symbol/init.lua

Lines changed: 12 additions & 6 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 = {}
@@ -90,9 +91,11 @@ function symbol:do_request(buf, client_id)
9091
return
9192
end
9293

93-
local params = { textDocument = {
94-
uri = vim.uri_from_bufnr(buf),
95-
} }
94+
local params = {
95+
textDocument = {
96+
uri = vim.uri_from_bufnr(buf),
97+
},
98+
}
9699

97100
local client = vim.lsp.get_client_by_id(client_id)
98101
if not client then
@@ -106,7 +109,7 @@ function symbol:do_request(buf, client_id)
106109

107110
self[buf].pending_request = true
108111

109-
client.request('textDocument/documentSymbol', params, function(err, result, ctx)
112+
util.client_request(client, 'textDocument/documentSymbol', params, function(err, result, ctx)
110113
if not api.nvim_buf_is_loaded(ctx.bufnr) or not self[ctx.bufnr] then
111114
return
112115
end
@@ -190,7 +193,7 @@ function symbol:register_module()
190193
end
191194

192195
local client = lsp.get_client_by_id(args.data.client_id)
193-
if not client or not client.supports_method('textDocument/documentSymbol') then
196+
if not client or not util.client_supports_method(client, 'textDocument/documentSymbol') then
194197
return
195198
end
196199
self:do_request(args.buf, args.data.client_id)
@@ -199,7 +202,10 @@ function symbol:register_module()
199202
require('lspsaga.symbol.winbar').init_winbar(args.buf)
200203
end
201204

202-
if config.implement.enable and client.supports_method('textDocument/implementation') then
205+
if
206+
config.implement.enable
207+
and util.client_supports_method(client, 'textDocument/implementation')
208+
then
203209
require('lspsaga.implement').start()
204210
end
205211
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)