R-nvim / R.nvim

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

Some bugs to fix #34

Closed PMassicotte closed 4 months ago

PMassicotte commented 4 months ago

Just listing issues I am finding so we can fix them :)

I think it is coming from these lines:

https://github.com/jalvesaq/tmp-R-Nvim/blob/7fd9fffcc870652bdad1e3e7dd0fee66e879a40a/lua/r/run.lua#L601-L605

PMassicotte commented 4 months ago

An option to send the current object to the terminal:

    if rcmd == "print" then
        send.cmd(vim.fn.expand("<cword>"))
        return
    end
jalvesaq commented 4 months ago

An option to send the current object to the terminal:

The problem is that vim.fn.expand("<cword>") will not catch strings such as listname$element.

jalvesaq commented 4 months ago

But we could try to change the value of vim.o.iskeywords temporarily. It will be much simpler than the complicated algorithm that I have written.

jalvesaq commented 4 months ago

nvimcom and rnvimserver now send Lua tables to R.nvim. You have to update cmp-nvim-r. There are some bugs when completing functions from .GlobalEnv, but I will fix them later.

jalvesaq commented 4 months ago

The problem while running <LocalLeader>rp is the function get_first_obj(). It has to be rewritten from scratch.

PMassicotte commented 4 months ago

Has something about terminal color changed this recently? Looks like a new config is coloring my terminal. Nevermind, I just set hl_term = false and it is all good.

jalvesaq commented 4 months ago

Yes, hl_term is being defined as true, but nvimcom/R/nvimcom.R should detect radian:

    if (length(find.package("colorout", quiet = TRUE, verbose = FALSE)) > 0 || Sys.getenv("RADIAN_VERSION") != "")
        hascolor <- TRUE
PMassicotte commented 4 months ago

It was opening radian, but my console was all green-ish.

jalvesaq commented 4 months ago

I did a minor improvement in get_first_obj. With the following code:

x <- rnorm(100)
y <- rnorm(100)
m <- lm(y ~ x)
summary(x)
summary(m)

If you press <LocalLeader>rp over summary, you should get different results for each summary()

jalvesaq commented 4 months ago

I moved the check for radian to the config. It's working there.

PMassicotte commented 4 months ago

I did a minor improvement in get_first_obj. With the following code:

x <- rnorm(100)
y <- rnorm(100)
m <- lm(y ~ x)
summary(x)
summary(m)

If you press <LocalLeader>rp over summary, you should get different results for each summary()

Is it works if my cursor is either on x or m !

jalvesaq commented 4 months ago

I rewrote get_first_obj() and now it is as good and as bad as Nvim-R's version. I don't want to improve it any further because perhaps it will be possible (and better) to rewrite it using tree-sitter in the future. To quickly test the function, I have put this in my init.lua:

vim.keymap.set("n", "T", function ()
    vim.api.nvim_echo({
        {"{"},
        {require("r.run").get_keyword(), "Function"},
        {"} {"},
        {require("r.cursor").get_first_obj(), "Type"},
        {"}"}}, false, {})
end, { expr = true})
jalvesaq commented 4 months ago

rh (for help) is not working for a namespaced function. For example pack::fun()

I can't replicate this. It works for me, for example doing <LocalLeader>rh over the word vi:

vi
nvimcom::vi
utils::vi
PMassicotte commented 4 months ago

Placing my cursor on library and hitting <LocalLeader>rh does nothing. With the older nrim-r, it opens the help file for the library() function.

image

Now, placing my cursor on vi indeed brings me a topic menu. Then, If I select either 1 for nvimcom or 2 for utils, nothing happens.

image

jalvesaq commented 4 months ago

Maybe you have set options("pager") in your ~/.Rprofile... I couldn't think of another explanation.

jalvesaq commented 4 months ago

Also: \rh only works if R is running, but, if not, R.nvim displays a warning message.

PMassicotte commented 4 months ago

No option about pager in my rprofile.

Even typing ?lm in the console does nothing.

Peek 2024-02-18 03-35

So it looks like that tmp-R-Nvim is not opening a new window properly.

PMassicotte commented 4 months ago

The only pager option I have is this config:

opts = {
   ...
   nvimpager = "horizontal",
   ...
  }
jalvesaq commented 4 months ago

With this option, I receive a warning message:

Invalid nvimpager value: "horizontal". Valid values are: "tab", "split", "float", and "no".

And nothing more happens. Hence, we have to investigate why you are not receiving this warning.

PMassicotte commented 4 months ago

You are right, it works as before when using 'split'. I probably missed the change of the parameter (i.e. using an old value that was working with nvim-r).

PMassicotte commented 4 months ago

What is supposed to be the file type of rdoc?

For me, :set filetype? returns nothing

image

Hence, sending example code in the terminal is not working because not recognized as r code.

jalvesaq commented 4 months ago

The warning should be wrapped by vim.schedule(). This is fixed now.

jalvesaq commented 4 months ago

The filetype rdoc no longer exists; only the syntax is being used.

jalvesaq commented 4 months ago

It was a filetype that I created to display R documentation. Its functions are now in lua/r/rdoc.lua.

PMassicotte commented 4 months ago

The filetype rdoc no longer exists; only the syntax is being used.

Do you have a good strategy to send example code to the console? I found it was a nice thing to do while browsing code example and have the ability to send it to the console.

jalvesaq commented 4 months ago

Yes, please, do git pull to get the warnings. I didn't see the warn bug because I had this in my lazy.nvim config:

    {
        'rcarriga/nvim-notify',
        config = function ()
            -- Overriding vim.notify with fancy notify
            local notify = require("notify")
            vim.notify = notify
            notify.setup()
            vim.keymap.set('',  '<Esc>', "<ESC>:noh<CR>:lua require('notify').dismiss()<CR>", {silent = true})
        end
    },
jalvesaq commented 4 months ago

\re to get the "Examples" section in an R buffer.

PMassicotte commented 4 months ago

Another thing I am just facing is that sending above code does not always work. In this example, moving the cursor 2 lines below give me an error cannot open the connection. Moving back the cursor up, make it works again.

Peek 2024-02-18 06-49

Maybe we can just grab all the lines above and send them directly to the console instead of writing a tmp file.

jalvesaq commented 4 months ago

But you can also send lines from the Example section to R. The rdoc is modifiable to allow you to edit the examples. There was a bug that I fixed just now.

PMassicotte commented 4 months ago

But you can also send lines from the Example section to R. The rdoc is modifiable to allow you to edit the examples. There was a bug that I fixed just now.

You are on fire :)

jalvesaq commented 4 months ago

Another thing I am just facing is that sending above code does not always work. In this example, moving the cursor 2 lines below give me an error cannot open the connection. Moving back the cursor up, make it works again.

Two lines above you were below the threshold of 20 lines to source lines and the lines were sent directly. I introduced the bug yesterday when fixing user config variables not being recognized. It should be fixed now.

PMassicotte commented 4 months ago

All perfect now!