Skip to content

Commit

Permalink
feat(executors): support commands without cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Dec 1, 2023
1 parent 48801fe commit 86d1683
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions .neoconf.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"enabled": true,
"plugins": [
"nvim-dap",
"toggleterm.nvim",
]
}
},
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- `:RustLsp logFile` command, which opens the rust-analyzer log file.
- Executors: Support commands without `cwd`.

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion lua/rustaceanvim/executors/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local vimux = require('rustaceanvim.executors.vimux')
local M = {}

---@class RustaceanExecutor
---@field execute_command fun(cmd:string, args:string[], cwd:string)
---@field execute_command fun(cmd:string, args:string[], cwd:string|nil)

M.termopen = termopen
M.quickfix = quickfix
Expand Down
4 changes: 2 additions & 2 deletions lua/rustaceanvim/executors/quickfix.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ function M.execute_command(command, args, cwd)
-- open quickfix
copen()
-- go back to the previous window
vim.cmd('wincmd p')
vim.cmd.wincmd('p')
-- clear the quickfix
clear_qf()

-- start compiling
local cmd = vim.list_extend({ command }, args)
compat.system(
cmd,
{ cwd = cwd },
cwd and { cwd = cwd } or {},
vim.schedule_wrap(function(sc)
---@cast sc vim.SystemCompleted
local data = sc.stdout or sc.stderr
Expand Down
10 changes: 6 additions & 4 deletions lua/rustaceanvim/executors/termopen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ local latest_buf_id = nil
function M.execute_command(command, args, cwd)
local shell = require('rustaceanvim.shell')
local ui = require('rustaceanvim.ui')
local full_command = shell.chain_commands {
shell.make_command_from_args('cd', { cwd }),
shell.make_command_from_args(command, args),
}
local commands = {}
if cwd then
table.insert(commands, shell.make_command_from_args('cd', { cwd }))
end
table.insert(commands, shell.make_command_from_args(command, args))
local full_command = shell.chain_commands(commands)

-- check if a buffer with the latest id is already open, if it is then
-- delete it and continue
Expand Down
11 changes: 6 additions & 5 deletions lua/rustaceanvim/executors/vimux.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ local shell = require('rustaceanvim.shell')
local M = {}

function M.execute_command(command, args, cwd)
local full_command = shell.chain_commands {
shell.make_command_from_args('cd', { cwd }),
shell.make_command_from_args(command, args),
}

local commands = {}
if cwd then
table.insert(commands, shell.make_command_from_args('cd', { cwd }))
end
table.insert(commands, shell.make_command_from_args(command, args))
local full_command = shell.chain_commands(commands)
vim.fn.VimuxRunCommand(full_command)
end

Expand Down

0 comments on commit 86d1683

Please sign in to comment.