Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use utils.system() instead of vim.system() #41

Merged
merged 3 commits into from
Feb 20, 2024
Merged

Conversation

hongyuanjia
Copy link
Contributor

Pull request overview

@jalvesaq
Copy link
Member

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 })

@jalvesaq
Copy link
Member

I'm not sure if using "." as the default value for cwd is correct...

@hongyuanjia
Copy link
Contributor Author

Thanks for the catch!

@hongyuanjia
Copy link
Contributor Author

I still lack a proper setup for developing Vim/Lua plugins. I need to learn how to test submodules despite relaunching Neovim.

@hongyuanjia
Copy link
Contributor Author

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()?

@jalvesaq
Copy link
Member

It's working on Linux. Can I merge it now?

@hongyuanjia
Copy link
Contributor Author

I checked it on Windows and macOS. Both work ok. I think we can merge it.

@jalvesaq jalvesaq merged commit c0bcbf3 into R-nvim:main Feb 20, 2024
1 check passed
PMassicotte pushed a commit to PMassicotte/tmp-R-Nvim that referenced this pull request Feb 21, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
jalvesaq pushed a commit that referenced this pull request Feb 22, 2024
* Use utils.system() instead of vim.system()
* Use vim.loop instead of vim.uv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vim.system() api did not exist in Neovim current release (v0.9.5)
2 participants