diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d60f175..6c6e4dc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lua/rustaceanvim/dap.lua b/lua/rustaceanvim/dap.lua index 682a778e..71d58518 100644 --- a/lua/rustaceanvim/dap.lua +++ b/lua/rustaceanvim/dap.lua @@ -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 diff --git a/lua/rustaceanvim/executors/quickfix.lua b/lua/rustaceanvim/executors/quickfix.lua index f4121e42..79ab235c 100644 --- a/lua/rustaceanvim/executors/quickfix.lua +++ b/lua/rustaceanvim/executors/quickfix.lua @@ -1,3 +1,5 @@ +local compat = require('rustaceanvim.compat') + ---@type RustaceanExecutor local M = {} @@ -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 diff --git a/lua/rustaceanvim/health.lua b/lua/rustaceanvim/health.lua index be5c09ea..ffd09bfd 100644 --- a/lua/rustaceanvim/health.lua +++ b/lua/rustaceanvim/health.lua @@ -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()