Skip to content

Commit

Permalink
feat: remove remaining plenary.nvim dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Oct 29, 2023
1 parent f745207 commit 568ee1b
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 107 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [3.2.0] - 2023-10-29

### Added
- Completions for `:RustLsp` subcommands' arguments.

### Changed
- Removed `plenary.nvim` dependency (`dap` and `quickfix` executor).
This plugin now has no `plenary.nvim` dependencies left.
NOTE: As this does **not** lead to a bump in the minimal requirements,
this is not a breaking change.

## [3.1.1] - 2023-10-28

### Fixed
Expand Down
154 changes: 73 additions & 81 deletions lua/rustaceanvim/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,93 +59,85 @@ end

---@param args RADebuggableArgs
function M.start(args)
if not pcall(require, 'plenary.job') then
scheduled_error('plenary.nvim not found.')
return
end

local Job = require('plenary.job')

local cargo_args = get_cargo_args_from_runnables_args(args)

vim.notify('Compiling a debug build for debugging. This might take some time...')

Job
:new({
command = 'cargo',
args = cargo_args,
cwd = args.workspaceRoot,
on_exit = function(j, code)
if code and code > 0 then
scheduled_error('An error occurred while compiling. Please fix all compilation issues and try again.')
return
local cmd = vim.list_extend({ 'cargo' }, cargo_args)
compat.system(cmd, { cwd = args.workspaceRoot }, function(sc)
---@cast sc vim.SystemCompleted
local output = sc.stdout
if sc.code ~= 0 or output == nil then
scheduled_error(
'An error occurred while compiling. Please fix all compilation issues and try again'
.. (sc.stderr and ': ' .. sc.stderr or '.')
)
return
end
vim.schedule(function()
local executables = {}
for value in output:gmatch('([^\n]*)\n?') do
local is_json, artifact = pcall(vim.fn.json_decode, value)
if not is_json then
goto loop_end
end

vim.schedule(function()
local executables = {}

for _, value in pairs(j:result()) do
local artifact = vim.fn.json_decode(value)

-- only process artifact if it's valid json object and it is a compiler artifact
if type(artifact) ~= 'table' or artifact.reason ~= 'compiler-artifact' then
goto loop_end
end

local is_binary = compat.list_contains(artifact.target.crate_types, 'bin')
local is_build_script = compat.list_contains(artifact.target.kind, 'custom-build')
local is_test = ((artifact.profile.test == true) and (artifact.executable ~= nil))
or compat.list_contains(artifact.target.kind, 'test')
-- only add executable to the list if we want a binary debug and it is a binary
-- or if we want a test debug and it is a test
if
(cargo_args[1] == 'build' and is_binary and not is_build_script)
or (cargo_args[1] == 'test' and is_test)
then
table.insert(executables, artifact.executable)
end

::loop_end::
end

-- only 1 executable is allowed for debugging - error out if zero or many were found
if #executables <= 0 then
scheduled_error('No compilation artifacts found.')
return
end
if #executables > 1 then
scheduled_error('Multiple compilation artifacts are not supported.')
return
end

-- create debug configuration
local dap_config = {
name = 'Rust tools debug',
type = 'rt_lldb',
request = 'launch',
program = executables[1],
args = args.executableArgs or {},
cwd = args.workspaceRoot,
stopOnEntry = false,

-- if you change `runInTerminal` to true, you might need to change the yama/ptrace_scope setting:
--
-- echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
--
-- Otherwise you might get the following error:
--
-- Error on launch: Failed to attach to the target process
--
-- But you should be aware of the implications:
-- https://www.kernel.org/doc/html/latest/admin-guide/LSM/Yama.html
runInTerminal = false,
}
-- start debugging
dap.run(dap_config)
end)
end,
})
:start()
-- only process artifact if it's valid json object and it is a compiler artifact
if type(artifact) ~= 'table' or artifact.reason ~= 'compiler-artifact' then
goto loop_end
end

local is_binary = compat.list_contains(artifact.target.crate_types, 'bin')
local is_build_script = compat.list_contains(artifact.target.kind, 'custom-build')
local is_test = ((artifact.profile.test == true) and (artifact.executable ~= nil))
or compat.list_contains(artifact.target.kind, 'test')
-- only add executable to the list if we want a binary debug and it is a binary
-- or if we want a test debug and it is a test
if
(cargo_args[1] == 'build' and is_binary and not is_build_script)
or (cargo_args[1] == 'test' and is_test)
then
table.insert(executables, artifact.executable)
end

::loop_end::
end
-- only 1 executable is allowed for debugging - error out if zero or many were found
if #executables <= 0 then
scheduled_error('No compilation artifacts found.')
return
end
if #executables > 1 then
scheduled_error('Multiple compilation artifacts are not supported.')
return
end

-- create debug configuration
local dap_config = {
name = 'Rust tools debug',
type = 'rt_lldb',
request = 'launch',
program = executables[1],
args = args.executableArgs or {},
cwd = args.workspaceRoot,
stopOnEntry = false,

-- if you change `runInTerminal` to true, you might need to change the yama/ptrace_scope setting:
--
-- echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
--
-- Otherwise you might get the following error:
--
-- Error on launch: Failed to attach to the target process
--
-- But you should be aware of the implications:
-- https://www.kernel.org/doc/html/latest/admin-guide/LSM/Yama.html
runInTerminal = false,
}
-- start debugging
dap.run(dap_config)
end)
end)
end

return M
29 changes: 12 additions & 17 deletions lua/rustaceanvim/executors/quickfix.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local compat = require('rustaceanvim.compat')

---@type RustaceanExecutor
local M = {}

Expand Down Expand Up @@ -29,23 +31,16 @@ function M.execute_command(command, args, cwd)
clear_qf()

-- start compiling
require('plenary.job')
:new({
command = command,
args = args,
cwd = cwd,
on_stdout = function(_, data)
vim.schedule(function()
append_qf(data)
end)
end,
on_stderr = function(_, data)
vim.schedule(function()
append_qf(data)
end)
end,
})
:start()
local cmd = vim.list_extend({ command }, args)
compat.system(
cmd,
{ cwd = cwd },
vim.schedule_wrap(function(sc)
---@cast sc vim.SystemCompleted
local data = sc.stdout or sc.stderr
append_qf(data)
end)
)
end

return M
8 changes: 0 additions & 8 deletions lua/rustaceanvim/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ local warn = h.warn or h.report_warn

---@type LuaDependency[]
local lua_dependencies = {
{
module = 'plenary',
optional = function()
return true
end,
url = '[nvim-lua/plenary.nvim](https://github.com/nvim-lua/plenary.nvim)',
info = 'Needed for debugging features.',
},
{
module = 'dap',
optional = function()
Expand Down

0 comments on commit 568ee1b

Please sign in to comment.