R-nvim / R.nvim

Neovim plugin to edit R files
GNU General Public License v3.0
155 stars 16 forks source link

some issues and questions mainly csv_app after testing it #39

Closed bassamsdata closed 7 months ago

bassamsdata commented 7 months ago

Congratulations on the new plugin refactoring! and thank you for the hard work. After testing it, I'd like to highlight a few points:

  1. It's noticeably faster than the old one, especially when opening plots and sending commands.
  2. Opening and closing the console is much snappier, which is a big improvement. Overall, there are many enhancements.

However, I noticed a few things:

opts = {
csv_app = "terminal: vd"
}

\rv output in the echo area:

Screenshot 2024-02-19 at 3 39 23 PM

to the plugin config, but it complained about it. So, I'm not sure how this will work, even though I saw it in the source code.

Overall, great job on the plugin!

Thank you

jalvesaq commented 7 months ago

This plugin doesn't auto-format when saving. As before, you have to manually select some lines and do :RFormat.

I will look at the other two bugs.

jalvesaq commented 7 months ago

The csv_app options should be fixed now.

I can't replicate the Object Browser bug, but if you still see the problem, I can add a "redraw" to see if it is fixed.

bassamsdata commented 7 months ago

The csv_app options should be fixed now.

Yes, it worked. Thank you. However, I'm trying to make it more interactive since it accepts a function like this:

csv_app = function(tsv_file)
    local app = vim.fn.input("Enter the application name: ")
    if app == "" then
        app = "tad"
    end
    vim.cmd("tabnew | terminal " .. app .. " " .. tsv_file)
    vim.cmd("startinsert")
end,

But this didn't work. I'm not sure if this is how we should set it up, but the app complains that the file tsv doesn't exist, even though the app gets the name correctly.

I can't replicate the Object Browser bug, but if you still see the problem, I can add a "redraw" to see if it is fixed.

I still have the issue, but that's okay. It's just a bit inconvenient; I can get used to it.

jalvesaq commented 7 months ago

Your function worked for me, but, while converting VimScript to Lua, in some cases, I had to call more interactive functions through vim.schedule. So, you could try:

                csv_app = function(tsv_file)
                    vim.schedule(function ()
                        vim.ui.input({ prompt = "Enter the application name: "}, function (input)
                            if input == "" then
                                input = "vd"
                            end
                            vim.cmd("tabnew | terminal " .. input .. " " .. tsv_file)
                            vim.cmd("startinsert")
                        end)
                    end)
                end,
jalvesaq commented 7 months ago
  • The rbrowser (<localleader>ro) doesn't refresh when I open it until I perform some assignment (like if I was working and open it, it shows nothing until I do some assignment).

Could you try this:

                hook = {
                    after_ob_open = function ()
                        vim.cmd("redraw")
                    end,
                },

If it solves the issue, I will add vim.cmd("redraw") to lua/r/browser.lua.

bassamsdata commented 7 months ago

Your function worked for me, but, while converting VimScript to Lua, in some cases, I had to call more interactive functions through vim.schedule.

Thank you for your feedback. Actually, both of them didn't work for me, and they produced the same result on Neovim stable 0.9.5 and nightly. I initially avoided using vim.ui.input because of its async nature, but even with vim.schedule, I had the same experience.

If it solves the issue, I will add vim.cmd("redraw") to lua/r/browser.lua.

Unfortunately, didn't solve the issue for me. I even tried calling redraw on rbrowser manually, but nothing happened until I performed a different assignment, after which it refreshed.

I'll try to create a minimal repro today and update here. It might be a configuration issue, but I'm not sure yet.

jalvesaq commented 7 months ago

I'm sorry! I was using a very small data.frame (only two lines) and didn't note that vd created an empty sheet. In fact, the data.frame wasn't being saved for the hook function. It should work now.

jalvesaq commented 7 months ago

I've also replaced some VimScript functions with Lua ones in browser.lua, but I don't believe that this will make any difference.

bassamsdata commented 7 months ago

In fact, the data.frame wasn't being saved for the hook function. It should work now.

It works like a charm right now, thank you.

I've also replaced some VimScript functions with Lua ones in browser.lua, but I don't believe that this will make any difference.

Unfortunately, the issue persists. Even after reopening the rbrowser and applying assignments, nothing appears. Here's a minimal reproducible code:

Steps to reproduce:

  1. Create a minimal.lua file as described below.
  2. Run 'nvim --clean -u minimal.lua'.
  3. Open any R file, perform some assignments, then use '\ro'.
  4. Repeat the process of doing assignments and then again '\ro' to hide and then \ro to show, and notice that nothing appears in this session again.

minimal.lua:

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "https://github.com/folke/lazy.nvim.git",
        "--branch=stable", -- latest stable release
        lazypath,
    })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
    {
        "jalvesaq/tmp-R-nvim",
        lazy = false,
        config = function()
            local opts = {
                csv_app = function(tsv_file)
                    vim.schedule(function()
                        vim.ui.input({ prompt = "Enter the application name: " }, function(input)
                            if input == "" then
                                input = "vd"
                            end
                            vim.cmd("tabnew | terminal " .. input .. " " .. tsv_file)
                            vim.cmd("startinsert")
                        end)
                    end)
                end,
                R_args = { "--quiet", "--no-save" },
                hook = {
                    after_ob_open = function()
                        vim.cmd("redraw")
                    end,
                    after_config = function()
                        if vim.o.syntax ~= "rbrowser" then
                            vim.api.nvim_buf_set_keymap(0, "n", "<Enter>", "<Plug>RDSendLine", {})
                            vim.api.nvim_buf_set_keymap(0, "v", "<Enter>", "<Plug>RSendSelection", {})
                        end
                    end,
                },
            }
            require("r").setup(opts)
        end,
    },
}, {})

here is a video for minimal rero, describing the issue:

https://github.com/jalvesaq/tmp-R-Nvim/assets/105807570/5b474aad-a7f6-4e8a-9574-c7ec51d31d8c

jalvesaq commented 7 months ago

I figured out what was the problem. It was updating immediately only when cmp-r was installed. Should be fixed now.

bassamsdata commented 7 months ago

thank you for the hard work. yes it worked and objects will show up in the first time you open it.

However, have you attempted to close and reopen it? After doing so, it fails to display anything, regardless of the actions taken thereafter.

bassamsdata commented 7 months ago

When closing it, I believe there's a message in the echo area. I've now noticed this. It's in the job.lua:58 file.

jalvesaq commented 7 months ago

It's fixed now.

bassamsdata commented 7 months ago

It works perfectly now, thank you. I really appreciated!

jalvesaq commented 7 months ago

Thanks for reporting the issue and all the feedback!

jalvesaq commented 7 months ago

Note: the immediate update will not work on Windows.

PMassicotte commented 7 months ago

Just my 2 cents, tidy-viewer is also working great

https://github.com/alexhallam/tv