Closed hongyuanjia closed 7 months ago
It's working for me after these changes:
diff --git a/lua/r/utils.lua b/lua/r/utils.lua
index f3267f3..6993046 100644
--- a/lua/r/utils.lua
+++ b/lua/r/utils.lua
@@ -193,8 +193,8 @@ function M.system(cmd, opts)
{
args = vim.list_slice(cmd, 2),
stdio = { nil, stdout, stderr },
- cwd = opts.cwd,
- detach = opts.detach,
+ cwd = (opts and opts.cwd) and opts.cwd or ".",
+ detach = (opts and opts.detach) and opts.detach or false,
hide = true
},
function(code, signal)
@@ -216,7 +216,7 @@ function M.system(cmd, opts)
if err then error(err) end
if data ~= nil then
- if opts.text then
+ if opts and opts.text then
data = data:gsub("\r\n", "\n")
table.insert(store, data)
else
@@ -235,7 +235,7 @@ function M.system(cmd, opts)
end
if stderr then
stderr_data = {}
- stderr:read_start(stdio_handler(state.stderr, stdout_data))
+ stderr:read_start(stdio_handler(state.stderr, stderr_data))
end
local methods = {}
@@ -248,6 +248,7 @@ function M.system(cmd, opts)
local err = string.format("Command timed out: %s", table.concat(cmd, " "))
return { code = 0, signal = 2, stdout = "", stderr = err }
end
+ return state.result
end
return setmetatable({ pid = state.pid, _state = state }, { __index = methods })
I'm not sure if using "." as the default value for cwd
is correct...
Thanks for the catch!
I still lack a proper setup for developing Vim/Lua plugins. I need to learn how to test submodules despite relaunching Neovim.
I'm not sure if using "." as the default value for
cwd
is correct...
Will nil
give an error? If not, I think we can leave it as is to follow the same behavior as vim.system()
?
It's working on Linux. Can I merge it now?
I checked it on Windows and macOS. Both work ok. I think we can merge it.
Pull request overview
system()
function to mimickvim.system()
's behavior. This fixes #36.