Skip to content

Commit

Permalink
fix(lsp/nightly): avoid deprecations with no alternative in stable (╯…
Browse files Browse the repository at this point in the history
…°□°)╯︵ ┻━┻ (#587)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
mrcjkb and github-actions[bot] authored Nov 29, 2024
1 parent b2df0ca commit f116a55
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 131 deletions.
54 changes: 27 additions & 27 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions lua/rustaceanvim/commands/code_action_group.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local ui = require('rustaceanvim.ui')
local config = require('rustaceanvim.config.internal')
local compat = require('rustaceanvim.compat')
local M = {}

---@class rustaceanvim.RACodeAction
Expand Down Expand Up @@ -47,7 +48,7 @@ function M.on_user_choice(action_tuple, ctx)
return
end
if not action.edit and type(code_action_provider) == 'table' and code_action_provider.resolveProvider then
client.request('codeAction/resolve', action, function(err, resolved_action)
compat.client_request(client, 'codeAction/resolve', action, function(err, resolved_action)
---@cast resolved_action rustaceanvim.RACodeAction|rustaceanvim.RACommand
if err then
vim.notify(err.code .. ': ' .. err.message, vim.log.levels.ERROR)
Expand Down Expand Up @@ -377,7 +378,13 @@ M.state = {
M.code_action_group = function()
local context = {}
context.diagnostics = require('rustaceanvim.compat').get_line_diagnostics()
local params = vim.lsp.util.make_range_params()
local ra = require('rustaceanvim.rust_analyzer')
local clients = ra.get_active_rustaceanvim_clients(0)
if #clients == 0 then
return
end
local params = vim.lsp.util.make_range_params(0, clients[1].offset_encoding)
---@diagnostic disable-next-line: inject-field
params.context = context

vim.lsp.buf_request_all(0, 'textDocument/codeAction', params, function(results)
Expand Down
14 changes: 9 additions & 5 deletions lua/rustaceanvim/commands/expand_macro.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ local ui = require('rustaceanvim.ui')
local M = {}

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

---@type integer | nil
Expand Down Expand Up @@ -70,11 +71,14 @@ local function handler(_, result)
ui.resize(true, '-25')
end

local rl = require('rustaceanvim.rust_analyzer')

--- Sends the request to rust-analyzer to expand the macro under the cursor
function M.expand_macro()
rl.buf_request(0, 'rust-analyzer/expandMacro', get_params(), handler)
local ra = require('rustaceanvim.rust_analyzer')
local clients = ra.get_active_rustaceanvim_clients(0)
if #clients == 0 then
return
end
ra.buf_request(0, 'rust-analyzer/expandMacro', get_params(clients[1].offset_encoding), handler)
end

return M.expand_macro
22 changes: 15 additions & 7 deletions lua/rustaceanvim/commands/external_docs.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
local M = {}

local rl = require('rustaceanvim.rust_analyzer')

function M.open_external_docs()
rl.buf_request(0, 'experimental/externalDocs', vim.lsp.util.make_position_params(), function(_, url)
if url then
local config = require('rustaceanvim.config.internal')
config.tools.open_url(url)
local ra = require('rustaceanvim.rust_analyzer')
local clients = ra.get_active_rustaceanvim_clients(0)
if #clients == 0 then
return
end
ra.buf_request(
0,
'experimental/externalDocs',
vim.lsp.util.make_position_params(0, clients[1].offset_encoding),
function(_, url)
if url then
local config = require('rustaceanvim.config.internal')
config.tools.open_url(url)
end
end
end)
)
end

return M.open_external_docs
19 changes: 9 additions & 10 deletions lua/rustaceanvim/commands/hover_range.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,17 @@ local function get_visual_selected_range()
return make_lsp_position(row1, math.min(col1, col2), row1, math.max(col1, col2))
end

---@return lsp_range_params
local function get_opts()
local params = vim.lsp.util.make_range_params()
function M.hover_range()
local ra = require('rustaceanvim.rust_analyzer')
local clients = ra.get_active_rustaceanvim_clients(0)
if #clients == 0 then
return
end
local params = vim.lsp.util.make_range_params(0, clients[1].offset_encoding)
---@diagnostic disable-next-line: inject-field
params.position = get_visual_selected_range()
params.range = nil
return params
end

local rl = require('rustaceanvim.rust_analyzer')

function M.hover_range()
rl.buf_request(0, 'textDocument/hover', get_opts())
ra.buf_request(0, 'textDocument/hover', params)
end

return M.hover_range
20 changes: 14 additions & 6 deletions lua/rustaceanvim/commands/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,13 @@ local rustlsp_command_tbl = {
},
joinLines = {
impl = function(_, opts)
local cmds = require('rustaceanvim.commands.join_lines')
---@cast opts vim.api.keyset.user_command
local visual_mode = opts.range and opts.range ~= 0 or false
require('rustaceanvim.commands.join_lines')(visual_mode)
if opts.range and opts.range ~= 0 then
cmds.join_lines_visual()
else
cmds.join_lines()
end
end,
},
moveItem = {
Expand All @@ -171,9 +175,9 @@ local rustlsp_command_tbl = {
return
end
if args[1] == 'down' then
require('rustaceanvim.commands.move_item')()
require('rustaceanvim.commands.move_item')('Down')
elseif args[1] == 'up' then
require('rustaceanvim.commands.move_item')(true)
require('rustaceanvim.commands.move_item')('Up')
else
vim.notify(
'moveItem: unexpected argument: ' .. vim.inspect(args) .. " expected 'up' or 'down'",
Expand Down Expand Up @@ -203,9 +207,13 @@ local rustlsp_command_tbl = {
ssr = {
impl = function(args, opts)
---@cast opts vim.api.keyset.user_command
local visual_mode = opts.range and opts.range > 0 or false
local query = args and #args > 0 and table.concat(args, ' ') or nil
require('rustaceanvim.commands.ssr')(query, visual_mode)
local cmds = require('rustaceanvim.commands.ssr')
if opts.range and opts.range > 0 then
cmds.ssr_visual(query)
else
cmds.ssr(query)
end
end,
},
reloadWorkspace = {
Expand Down
38 changes: 25 additions & 13 deletions lua/rustaceanvim/commands/join_lines.lua
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
local M = {}

---@alias lsp_join_lines_params { textDocument: lsp_text_document, ranges: lsp_range[] }

---@param visual_mode boolean
---@return lsp_join_lines_params
local function get_params(visual_mode)
local params = visual_mode and vim.lsp.util.make_given_range_params() or vim.lsp.util.make_range_params()
---@param params { textDocument: lsp_text_document, range: lsp_range }
---@return { textDocument: lsp_text_document, ranges: lsp_range[] }
local function modify_params(params)
local range = params.range

params.range = nil
---@diagnostic disable-next-line: inject-field
params.ranges = { range }

---@diagnostic disable-next-line: return-type-mismatch
return params
end

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

local rl = require('rustaceanvim.rust_analyzer')
local ra = require('rustaceanvim.rust_analyzer')

--- Sends the request to rust-analyzer to get the TextEdits to join the lines
--- under the cursor and applies them (for use in visual mode)
function M.join_lines_visual()
local clients = ra.get_active_rustaceanvim_clients(0)
if #clients == 0 then
return
end
local params = modify_params(vim.lsp.util.make_given_range_params(nil, nil, 0, clients[1].offset_encoding))
ra.buf_request(0, 'experimental/joinLines', params, handler)
end

--- Sends the request to rust-analyzer to get the TextEdits to join the lines
--- under the cursor and applies them
---@param visual_mode boolean
function M.join_lines(visual_mode)
rl.buf_request(0, 'experimental/joinLines', get_params(visual_mode), handler)
function M.join_lines()
local clients = ra.get_active_rustaceanvim_clients(0)
if #clients == 0 then
return
end
local params = modify_params(vim.lsp.util.make_range_params(0, clients[1].offset_encoding))
ra.buf_request(0, 'experimental/joinLines', params, handler)
end

return M.join_lines
return M
25 changes: 11 additions & 14 deletions lua/rustaceanvim/commands/move_item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@ local M = {}

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

---@param up boolean
---@return lsp_move_items_params
local function get_params(up)
local direction = up and 'Up' or 'Down'
local params = vim.lsp.util.make_range_params()
params.direction = direction

return params
end

---@param prev_text_edit rustaceanvim.lsp.TextEdit
---@param text_edit rustaceanvim.lsp.TextEdit
local function text_edit_line_range_diff(prev_text_edit, text_edit)
Expand Down Expand Up @@ -55,11 +45,18 @@ local function handler(_, text_edits, ctx)
vim.api.nvim_win_set_cursor(0, cursor)
end

local rl = require('rustaceanvim.rust_analyzer')

-- Sends the request to rust-analyzer to move the item and handle the response
function M.move_item(up)
rl.buf_request(0, 'experimental/moveItem', get_params(up or false), handler)
---@param direction 'Up' | 'Down'
function M.move_item(direction)
local ra = require('rustaceanvim.rust_analyzer')
local clients = ra.get_active_rustaceanvim_clients(0)
if #clients == 0 then
return
end
local params = vim.lsp.util.make_range_params(0, clients[1].offset_encoding)
---@diagnostic disable-next-line: inject-field
params.direction = direction
ra.buf_request(0, 'experimental/moveItem', params, handler)
end

return M.move_item
Loading

0 comments on commit f116a55

Please sign in to comment.