Skip to content

Commit f116a55

Browse files
fix(lsp/nightly): avoid deprecations with no alternative in stable (╯°□°)╯︵ ┻━┻ (#587)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent b2df0ca commit f116a55

17 files changed

+247
-131
lines changed

flake.lock

+27-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lua/rustaceanvim/commands/code_action_group.lua

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local ui = require('rustaceanvim.ui')
22
local config = require('rustaceanvim.config.internal')
3+
local compat = require('rustaceanvim.compat')
34
local M = {}
45

56
---@class rustaceanvim.RACodeAction
@@ -47,7 +48,7 @@ function M.on_user_choice(action_tuple, ctx)
4748
return
4849
end
4950
if not action.edit and type(code_action_provider) == 'table' and code_action_provider.resolveProvider then
50-
client.request('codeAction/resolve', action, function(err, resolved_action)
51+
compat.client_request(client, 'codeAction/resolve', action, function(err, resolved_action)
5152
---@cast resolved_action rustaceanvim.RACodeAction|rustaceanvim.RACommand
5253
if err then
5354
vim.notify(err.code .. ': ' .. err.message, vim.log.levels.ERROR)
@@ -377,7 +378,13 @@ M.state = {
377378
M.code_action_group = function()
378379
local context = {}
379380
context.diagnostics = require('rustaceanvim.compat').get_line_diagnostics()
380-
local params = vim.lsp.util.make_range_params()
381+
local ra = require('rustaceanvim.rust_analyzer')
382+
local clients = ra.get_active_rustaceanvim_clients(0)
383+
if #clients == 0 then
384+
return
385+
end
386+
local params = vim.lsp.util.make_range_params(0, clients[1].offset_encoding)
387+
---@diagnostic disable-next-line: inject-field
381388
params.context = context
382389

383390
vim.lsp.buf_request_all(0, 'textDocument/codeAction', params, function(results)

lua/rustaceanvim/commands/expand_macro.lua

+9-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ local ui = require('rustaceanvim.ui')
33
local M = {}
44

55
---@return lsp_position_params
6-
local function get_params()
7-
return vim.lsp.util.make_position_params()
6+
---@param offset_encoding 'utf-8'|'utf-16'|'utf-32'
7+
local function get_params(offset_encoding)
8+
return vim.lsp.util.make_position_params(0, offset_encoding)
89
end
910

1011
---@type integer | nil
@@ -70,11 +71,14 @@ local function handler(_, result)
7071
ui.resize(true, '-25')
7172
end
7273

73-
local rl = require('rustaceanvim.rust_analyzer')
74-
7574
--- Sends the request to rust-analyzer to expand the macro under the cursor
7675
function M.expand_macro()
77-
rl.buf_request(0, 'rust-analyzer/expandMacro', get_params(), handler)
76+
local ra = require('rustaceanvim.rust_analyzer')
77+
local clients = ra.get_active_rustaceanvim_clients(0)
78+
if #clients == 0 then
79+
return
80+
end
81+
ra.buf_request(0, 'rust-analyzer/expandMacro', get_params(clients[1].offset_encoding), handler)
7882
end
7983

8084
return M.expand_macro
+15-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
local M = {}
22

3-
local rl = require('rustaceanvim.rust_analyzer')
4-
53
function M.open_external_docs()
6-
rl.buf_request(0, 'experimental/externalDocs', vim.lsp.util.make_position_params(), function(_, url)
7-
if url then
8-
local config = require('rustaceanvim.config.internal')
9-
config.tools.open_url(url)
4+
local ra = require('rustaceanvim.rust_analyzer')
5+
local clients = ra.get_active_rustaceanvim_clients(0)
6+
if #clients == 0 then
7+
return
8+
end
9+
ra.buf_request(
10+
0,
11+
'experimental/externalDocs',
12+
vim.lsp.util.make_position_params(0, clients[1].offset_encoding),
13+
function(_, url)
14+
if url then
15+
local config = require('rustaceanvim.config.internal')
16+
config.tools.open_url(url)
17+
end
1018
end
11-
end)
19+
)
1220
end
1321

1422
return M.open_external_docs

lua/rustaceanvim/commands/hover_range.lua

+9-10
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,17 @@ local function get_visual_selected_range()
4242
return make_lsp_position(row1, math.min(col1, col2), row1, math.max(col1, col2))
4343
end
4444

45-
---@return lsp_range_params
46-
local function get_opts()
47-
local params = vim.lsp.util.make_range_params()
45+
function M.hover_range()
46+
local ra = require('rustaceanvim.rust_analyzer')
47+
local clients = ra.get_active_rustaceanvim_clients(0)
48+
if #clients == 0 then
49+
return
50+
end
51+
local params = vim.lsp.util.make_range_params(0, clients[1].offset_encoding)
52+
---@diagnostic disable-next-line: inject-field
4853
params.position = get_visual_selected_range()
4954
params.range = nil
50-
return params
51-
end
52-
53-
local rl = require('rustaceanvim.rust_analyzer')
54-
55-
function M.hover_range()
56-
rl.buf_request(0, 'textDocument/hover', get_opts())
55+
ra.buf_request(0, 'textDocument/hover', params)
5756
end
5857

5958
return M.hover_range

lua/rustaceanvim/commands/init.lua

+14-6
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,13 @@ local rustlsp_command_tbl = {
159159
},
160160
joinLines = {
161161
impl = function(_, opts)
162+
local cmds = require('rustaceanvim.commands.join_lines')
162163
---@cast opts vim.api.keyset.user_command
163-
local visual_mode = opts.range and opts.range ~= 0 or false
164-
require('rustaceanvim.commands.join_lines')(visual_mode)
164+
if opts.range and opts.range ~= 0 then
165+
cmds.join_lines_visual()
166+
else
167+
cmds.join_lines()
168+
end
165169
end,
166170
},
167171
moveItem = {
@@ -171,9 +175,9 @@ local rustlsp_command_tbl = {
171175
return
172176
end
173177
if args[1] == 'down' then
174-
require('rustaceanvim.commands.move_item')()
178+
require('rustaceanvim.commands.move_item')('Down')
175179
elseif args[1] == 'up' then
176-
require('rustaceanvim.commands.move_item')(true)
180+
require('rustaceanvim.commands.move_item')('Up')
177181
else
178182
vim.notify(
179183
'moveItem: unexpected argument: ' .. vim.inspect(args) .. " expected 'up' or 'down'",
@@ -203,9 +207,13 @@ local rustlsp_command_tbl = {
203207
ssr = {
204208
impl = function(args, opts)
205209
---@cast opts vim.api.keyset.user_command
206-
local visual_mode = opts.range and opts.range > 0 or false
207210
local query = args and #args > 0 and table.concat(args, ' ') or nil
208-
require('rustaceanvim.commands.ssr')(query, visual_mode)
211+
local cmds = require('rustaceanvim.commands.ssr')
212+
if opts.range and opts.range > 0 then
213+
cmds.ssr_visual(query)
214+
else
215+
cmds.ssr(query)
216+
end
209217
end,
210218
},
211219
reloadWorkspace = {
+25-13
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,42 @@
11
local M = {}
22

3-
---@alias lsp_join_lines_params { textDocument: lsp_text_document, ranges: lsp_range[] }
4-
5-
---@param visual_mode boolean
6-
---@return lsp_join_lines_params
7-
local function get_params(visual_mode)
8-
local params = visual_mode and vim.lsp.util.make_given_range_params() or vim.lsp.util.make_range_params()
3+
---@param params { textDocument: lsp_text_document, range: lsp_range }
4+
---@return { textDocument: lsp_text_document, ranges: lsp_range[] }
5+
local function modify_params(params)
96
local range = params.range
10-
117
params.range = nil
8+
---@diagnostic disable-next-line: inject-field
129
params.ranges = { range }
13-
10+
---@diagnostic disable-next-line: return-type-mismatch
1411
return params
1512
end
1613

1714
local function handler(_, result, ctx)
1815
vim.lsp.util.apply_text_edits(result, ctx.bufnr, vim.lsp.get_client_by_id(ctx.client_id).offset_encoding)
1916
end
2017

21-
local rl = require('rustaceanvim.rust_analyzer')
18+
local ra = require('rustaceanvim.rust_analyzer')
19+
20+
--- Sends the request to rust-analyzer to get the TextEdits to join the lines
21+
--- under the cursor and applies them (for use in visual mode)
22+
function M.join_lines_visual()
23+
local clients = ra.get_active_rustaceanvim_clients(0)
24+
if #clients == 0 then
25+
return
26+
end
27+
local params = modify_params(vim.lsp.util.make_given_range_params(nil, nil, 0, clients[1].offset_encoding))
28+
ra.buf_request(0, 'experimental/joinLines', params, handler)
29+
end
2230

2331
--- Sends the request to rust-analyzer to get the TextEdits to join the lines
2432
--- under the cursor and applies them
25-
---@param visual_mode boolean
26-
function M.join_lines(visual_mode)
27-
rl.buf_request(0, 'experimental/joinLines', get_params(visual_mode), handler)
33+
function M.join_lines()
34+
local clients = ra.get_active_rustaceanvim_clients(0)
35+
if #clients == 0 then
36+
return
37+
end
38+
local params = modify_params(vim.lsp.util.make_range_params(0, clients[1].offset_encoding))
39+
ra.buf_request(0, 'experimental/joinLines', params, handler)
2840
end
2941

30-
return M.join_lines
42+
return M

lua/rustaceanvim/commands/move_item.lua

+11-14
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@ local M = {}
22

33
---@alias lsp_move_items_params { textDocument: lsp_text_document, range: lsp_range, direction: 'Up' | 'Down' }
44

5-
---@param up boolean
6-
---@return lsp_move_items_params
7-
local function get_params(up)
8-
local direction = up and 'Up' or 'Down'
9-
local params = vim.lsp.util.make_range_params()
10-
params.direction = direction
11-
12-
return params
13-
end
14-
155
---@param prev_text_edit rustaceanvim.lsp.TextEdit
166
---@param text_edit rustaceanvim.lsp.TextEdit
177
local function text_edit_line_range_diff(prev_text_edit, text_edit)
@@ -55,11 +45,18 @@ local function handler(_, text_edits, ctx)
5545
vim.api.nvim_win_set_cursor(0, cursor)
5646
end
5747

58-
local rl = require('rustaceanvim.rust_analyzer')
59-
6048
-- Sends the request to rust-analyzer to move the item and handle the response
61-
function M.move_item(up)
62-
rl.buf_request(0, 'experimental/moveItem', get_params(up or false), handler)
49+
---@param direction 'Up' | 'Down'
50+
function M.move_item(direction)
51+
local ra = require('rustaceanvim.rust_analyzer')
52+
local clients = ra.get_active_rustaceanvim_clients(0)
53+
if #clients == 0 then
54+
return
55+
end
56+
local params = vim.lsp.util.make_range_params(0, clients[1].offset_encoding)
57+
---@diagnostic disable-next-line: inject-field
58+
params.direction = direction
59+
ra.buf_request(0, 'experimental/moveItem', params, handler)
6360
end
6461

6562
return M.move_item

0 commit comments

Comments
 (0)