Skip to content

Commit 568ee1b

Browse files
author
Marc Jakobi
committed
feat: remove remaining plenary.nvim dependencies
1 parent f745207 commit 568ee1b

File tree

4 files changed

+92
-107
lines changed

4 files changed

+92
-107
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unreleased]
8+
## [3.2.0] - 2023-10-29
99

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

13+
### Changed
14+
- Removed `plenary.nvim` dependency (`dap` and `quickfix` executor).
15+
This plugin now has no `plenary.nvim` dependencies left.
16+
NOTE: As this does **not** lead to a bump in the minimal requirements,
17+
this is not a breaking change.
18+
1319
## [3.1.1] - 2023-10-28
1420

1521
### Fixed

lua/rustaceanvim/dap.lua

Lines changed: 73 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -59,93 +59,85 @@ end
5959

6060
---@param args RADebuggableArgs
6161
function M.start(args)
62-
if not pcall(require, 'plenary.job') then
63-
scheduled_error('plenary.nvim not found.')
64-
return
65-
end
66-
67-
local Job = require('plenary.job')
68-
6962
local cargo_args = get_cargo_args_from_runnables_args(args)
7063

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

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

84-
vim.schedule(function()
85-
local executables = {}
86-
87-
for _, value in pairs(j:result()) do
88-
local artifact = vim.fn.json_decode(value)
89-
90-
-- only process artifact if it's valid json object and it is a compiler artifact
91-
if type(artifact) ~= 'table' or artifact.reason ~= 'compiler-artifact' then
92-
goto loop_end
93-
end
94-
95-
local is_binary = compat.list_contains(artifact.target.crate_types, 'bin')
96-
local is_build_script = compat.list_contains(artifact.target.kind, 'custom-build')
97-
local is_test = ((artifact.profile.test == true) and (artifact.executable ~= nil))
98-
or compat.list_contains(artifact.target.kind, 'test')
99-
-- only add executable to the list if we want a binary debug and it is a binary
100-
-- or if we want a test debug and it is a test
101-
if
102-
(cargo_args[1] == 'build' and is_binary and not is_build_script)
103-
or (cargo_args[1] == 'test' and is_test)
104-
then
105-
table.insert(executables, artifact.executable)
106-
end
107-
108-
::loop_end::
109-
end
110-
111-
-- only 1 executable is allowed for debugging - error out if zero or many were found
112-
if #executables <= 0 then
113-
scheduled_error('No compilation artifacts found.')
114-
return
115-
end
116-
if #executables > 1 then
117-
scheduled_error('Multiple compilation artifacts are not supported.')
118-
return
119-
end
120-
121-
-- create debug configuration
122-
local dap_config = {
123-
name = 'Rust tools debug',
124-
type = 'rt_lldb',
125-
request = 'launch',
126-
program = executables[1],
127-
args = args.executableArgs or {},
128-
cwd = args.workspaceRoot,
129-
stopOnEntry = false,
130-
131-
-- if you change `runInTerminal` to true, you might need to change the yama/ptrace_scope setting:
132-
--
133-
-- echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
134-
--
135-
-- Otherwise you might get the following error:
136-
--
137-
-- Error on launch: Failed to attach to the target process
138-
--
139-
-- But you should be aware of the implications:
140-
-- https://www.kernel.org/doc/html/latest/admin-guide/LSM/Yama.html
141-
runInTerminal = false,
142-
}
143-
-- start debugging
144-
dap.run(dap_config)
145-
end)
146-
end,
147-
})
148-
:start()
85+
-- only process artifact if it's valid json object and it is a compiler artifact
86+
if type(artifact) ~= 'table' or artifact.reason ~= 'compiler-artifact' then
87+
goto loop_end
88+
end
89+
90+
local is_binary = compat.list_contains(artifact.target.crate_types, 'bin')
91+
local is_build_script = compat.list_contains(artifact.target.kind, 'custom-build')
92+
local is_test = ((artifact.profile.test == true) and (artifact.executable ~= nil))
93+
or compat.list_contains(artifact.target.kind, 'test')
94+
-- only add executable to the list if we want a binary debug and it is a binary
95+
-- or if we want a test debug and it is a test
96+
if
97+
(cargo_args[1] == 'build' and is_binary and not is_build_script)
98+
or (cargo_args[1] == 'test' and is_test)
99+
then
100+
table.insert(executables, artifact.executable)
101+
end
102+
103+
::loop_end::
104+
end
105+
-- only 1 executable is allowed for debugging - error out if zero or many were found
106+
if #executables <= 0 then
107+
scheduled_error('No compilation artifacts found.')
108+
return
109+
end
110+
if #executables > 1 then
111+
scheduled_error('Multiple compilation artifacts are not supported.')
112+
return
113+
end
114+
115+
-- create debug configuration
116+
local dap_config = {
117+
name = 'Rust tools debug',
118+
type = 'rt_lldb',
119+
request = 'launch',
120+
program = executables[1],
121+
args = args.executableArgs or {},
122+
cwd = args.workspaceRoot,
123+
stopOnEntry = false,
124+
125+
-- if you change `runInTerminal` to true, you might need to change the yama/ptrace_scope setting:
126+
--
127+
-- echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
128+
--
129+
-- Otherwise you might get the following error:
130+
--
131+
-- Error on launch: Failed to attach to the target process
132+
--
133+
-- But you should be aware of the implications:
134+
-- https://www.kernel.org/doc/html/latest/admin-guide/LSM/Yama.html
135+
runInTerminal = false,
136+
}
137+
-- start debugging
138+
dap.run(dap_config)
139+
end)
140+
end)
149141
end
150142

151143
return M

lua/rustaceanvim/executors/quickfix.lua

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local compat = require('rustaceanvim.compat')
2+
13
---@type RustaceanExecutor
24
local M = {}
35

@@ -29,23 +31,16 @@ function M.execute_command(command, args, cwd)
2931
clear_qf()
3032

3133
-- start compiling
32-
require('plenary.job')
33-
:new({
34-
command = command,
35-
args = args,
36-
cwd = cwd,
37-
on_stdout = function(_, data)
38-
vim.schedule(function()
39-
append_qf(data)
40-
end)
41-
end,
42-
on_stderr = function(_, data)
43-
vim.schedule(function()
44-
append_qf(data)
45-
end)
46-
end,
47-
})
48-
:start()
34+
local cmd = vim.list_extend({ command }, args)
35+
compat.system(
36+
cmd,
37+
{ cwd = cwd },
38+
vim.schedule_wrap(function(sc)
39+
---@cast sc vim.SystemCompleted
40+
local data = sc.stdout or sc.stderr
41+
append_qf(data)
42+
end)
43+
)
4944
end
5045

5146
return M

lua/rustaceanvim/health.lua

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ local warn = h.warn or h.report_warn
1919

2020
---@type LuaDependency[]
2121
local lua_dependencies = {
22-
{
23-
module = 'plenary',
24-
optional = function()
25-
return true
26-
end,
27-
url = '[nvim-lua/plenary.nvim](https://github.com/nvim-lua/plenary.nvim)',
28-
info = 'Needed for debugging features.',
29-
},
3022
{
3123
module = 'dap',
3224
optional = function()

0 commit comments

Comments
 (0)