Skip to content

Commit

Permalink
fix(lsp): update deprecated API calls (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb authored Sep 21, 2024
1 parent f9ecc0c commit 9a36905
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lua/rustaceanvim/commands/code_action_group.lua
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ M.state = {

M.code_action_group = function()
local context = {}
context.diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
context.diagnostics = require('rustaceanvim.compat').get_line_diagnostics()
local params = vim.lsp.util.make_range_params()
params.context = context

Expand Down
18 changes: 18 additions & 0 deletions lua/rustaceanvim/compat.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---@mod rustaceanvim.compat compativility layer for
---API calls that are deprecated or removed in nvim nightly

local compat = {}

---@return lsp.Diagnostic[]
function compat.get_line_diagnostics()
if vim.lsp.diagnostic.from then
local opts = {
lnum = vim.api.nvim_win_get_cursor(0)[1] - 1,
}
return vim.lsp.diagnostic.from(vim.diagnostic.get(0, opts))
end
---@diagnostic disable-next-line: deprecated
return vim.lsp.diagnostic.get_line_diagnostics()
end

return compat
40 changes: 16 additions & 24 deletions lua/rustaceanvim/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@

local health = {}

local h = vim.health or require('health')
---@diagnostic disable-next-line: deprecated
local start = h.start or h.report_start
---@diagnostic disable-next-line: deprecated
local ok = h.ok or h.report_ok
---@diagnostic disable-next-line: deprecated
local error = h.error or h.report_error
---@diagnostic disable-next-line: deprecated
local warn = h.warn or h.report_warn
local h = vim.health

---@class rustaceanvim.LuaDependency
---@field module string The name of a module
Expand Down Expand Up @@ -43,11 +35,11 @@ local lua_dependencies = {
---@param dep rustaceanvim.LuaDependency
local function check_lua_dependency(dep)
if pcall(require, dep.module) then
ok(dep.url .. ' installed.')
h.ok(dep.url .. ' installed.')
return
end
if dep.optional() then
warn(('%s not installed. %s %s'):format(dep.module, dep.info, dep.url))
h.warn(('%s not installed. %s %s'):format(dep.module, dep.info, dep.url))
else
error(('Lua dependency %s not found: %s'):format(dep.module, dep.url))
end
Expand Down Expand Up @@ -88,14 +80,14 @@ local function check_external_dependency(dep)
local mb_version_len = version_or_err
and (mb_version_newline_idx and mb_version_newline_idx - 1 or version_or_err:len())
version_or_err = version_or_err and version_or_err:sub(0, mb_version_len) or '(unknown version)'
ok(('%s: found %s'):format(dep.name, version_or_err))
h.ok(('%s: found %s'):format(dep.name, version_or_err))
if dep.extra_checks_if_installed then
dep.extra_checks_if_installed(binary)
end
return
end
if dep.optional() then
warn(([[
h.warn(([[
%s: not found.
Install %s for extended capabilities.
%s
Expand All @@ -114,13 +106,13 @@ end

---@param config rustaceanvim.Config
local function check_config(config)
start('Checking config')
h.start('Checking config')
if vim.g.rustaceanvim and not config.was_g_rustaceanvim_sourced then
error('vim.g.rustaceanvim is set, but it was sourced after rustaceanvim was initialized.')
end
local valid, err = require('rustaceanvim.config.check').validate(config)
if valid then
ok('No errors found in config.')
h.ok('No errors found in config.')
else
error(err or '' .. vim.g.rustaceanvim and '' or ' This looks like a plugin bug!')
end
Expand All @@ -136,36 +128,36 @@ local function is_dap_enabled()
end

local function check_for_conflicts()
start('Checking for conflicting plugins')
h.start('Checking for conflicting plugins')
require('rustaceanvim.config.check').check_for_lspconfig_conflict(error)
if package.loaded['rustaceanvim.neotest'] ~= nil and package.loaded['neotest-rust'] ~= nil then
error('rustaceanvim.neotest and neotest-rust are both loaded. This is likely a conflict.')
return
end
ok('No conflicting plugins detected.')
h.ok('No conflicting plugins detected.')
end

local function check_tree_sitter()
start('Checking for tree-sitter parser')
h.start('Checking for tree-sitter parser')
local has_tree_sitter_rust_parser = #vim.api.nvim_get_runtime_file('parser/rust.so', true) > 0
or #vim.api.nvim_get_runtime_file('parser/rust.dll', true) > 0
if has_tree_sitter_rust_parser then
ok('tree-sitter parser for Rust detected.')
h.ok('tree-sitter parser for Rust detected.')
else
warn("No tree-sitter parser for Rust detected. Required by 'Rustc unpretty' command.")
h.warn("No tree-sitter parser for Rust detected. Required by 'Rustc unpretty' command.")
end
end

function health.check()
local types = require('rustaceanvim.types.internal')
local config = require('rustaceanvim.config.internal')

start('Checking for Lua dependencies')
h.start('Checking for Lua dependencies')
for _, dep in ipairs(lua_dependencies) do
check_lua_dependency(dep)
end

start('Checking external dependencies')
h.start('Checking external dependencies')

local adapter = types.evaluate(config.dap.adapter)
---@cast adapter rustaceanvim.dap.executable.Config | rustaceanvim.dap.server.Config | boolean
Expand Down Expand Up @@ -207,7 +199,7 @@ function health.check()
extra_checks_if_not_installed = function()
local bin = get_rust_analyzer_binary()
if vim.fn.executable(bin) == 1 then
warn("rust-analyzer wrapper detected. Run 'rustup component add rust-analyzer' to install rust-analyzer.")
h.warn("rust-analyzer wrapper detected. Run 'rustup component add rust-analyzer' to install rust-analyzer.")
end
end,
},
Expand Down Expand Up @@ -281,7 +273,7 @@ function health.check()
})
end
if adapter == false and is_dap_enabled() then
warn('No debug adapter detected. Make sure either lldb or codelldb is available on the path.')
h.warn('No debug adapter detected. Make sure either lldb or codelldb is available on the path.')
end
for _, dep in ipairs(external_dependencies) do
check_external_dependency(dep)
Expand Down

0 comments on commit 9a36905

Please sign in to comment.