R-nvim / R.nvim

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

Optimize completion infrastructure for Lua #64

Closed jalvesaq closed 4 months ago

jalvesaq commented 4 months ago
jalvesaq commented 4 months ago

This pull request changes the code originally developed for omni-completion and optimizes it to interact with the Lua code. The main goal is to make it easier to eventually convert rnvimserver into a C library for Lua. To test this pull request, please, use it along with the branch optimized of cmp-r.

Part of cmp-r code was converted to C and incorporated into R.nvim.

PMassicotte commented 4 months ago

Using

        "R-nvim/R.nvim",
        commit = "c0c167eddadb6b8aa41cea5f225c202d6aeac83d",

and

return {
    "R-nvim/cmp-r",
    branch = "optimized",
    config = function()
        require("cmp_r").setup({
            filetypes = { "r", "rmd", "quarto" },
            doc_width = 150,
        })
    end,
}

I am getting error when auto complete is triggered:

image

jalvesaq commented 4 months ago

I added a commit to cmp-r postponing the definition of send_to_nvimcom. It should work now.

PMassicotte commented 4 months ago

I am now getting this:

image

PMassicotte commented 4 months ago

It seems to work if I use it in a 1 liner like

lm()

But not on a piped expression.

jalvesaq commented 4 months ago

Thanks! I can replicate the bug here. I will see what's happening.

PMassicotte commented 4 months ago

Peek 2024-03-03 07-03

jalvesaq commented 4 months ago

The code supposes that the data.frame will be in the .GlobalEnv environment. I didn't consider the possibility of the data.frame being from a package. Then, the rnvimserver gets a SIGINT when trying to access a NULL GlobalEnv (because no code creating an object was sent to R yet).

PMassicotte commented 4 months ago

The code supposes that the data.frame will be in the .GlobalEnv environment. I didn't consider the possibility of the data.frame being from a package. Then, the rnvimserver gets a SIGINT when trying to access a NULL GlobalEnv (because no code creating an object was sent to R yet).

Good catch, if I do df <- mtcars it works just fine.

PMassicotte commented 4 months ago

And completion works fine now in scale_x_continuous()

image

This is fixing: https://github.com/R-nvim/cmp-r/issues/3

jalvesaq commented 4 months ago

It should find data.frames in libraries too now.

PMassicotte commented 4 months ago

I am still getting the same error (connection with rnvimserver was lost)

Using:

        "R-nvim/R.nvim",
        commit = "313f6c78ae5b8057ed5933bb1e8d90d6a258d4f0",

If I type :messages I get

"Server" exited with status 139                                                                                                                                                                                                                                 

Press ENTER or type command to continue 
jalvesaq commented 4 months ago

I had forgotten to increase nvimcom version number to force the recompilation of the rnvimserver. I increased it now.

PMassicotte commented 4 months ago

Victory :1st_place_medal:

All good now on my side. These are really nice changes.

PMassicotte commented 4 months ago

I think this can be merged. Good job!

jalvesaq commented 4 months ago

Are you sure? Maybe we could use it for some time. If no bugs appear, we squash and merge it.

PMassicotte commented 4 months ago

I am currently working on an R project using this latest commit. I think I will do it for 2-3h. I can report back and dig up in your code change there after if I can not spot something obvious.

jalvesaq commented 4 months ago

Good! If you don't find bugs in the next couple of hours, we merge it.

PMassicotte commented 4 months ago

I just spent 2h to extensively use the completion in the project I'm working on and no issue at all. It feels snappy and responsive!

jalvesaq commented 4 months ago

So, we can squash and merge...