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

Completion gets worse after turning on R console #95

Open
dinga92 opened this issue Mar 22, 2024 · 4 comments
Open

Completion gets worse after turning on R console #95

dinga92 opened this issue Mar 22, 2024 · 4 comments
Labels

Comments

@dinga92
Copy link

dinga92 commented Mar 22, 2024

Hi, I am not sure if this is an expected behavior, or a bug, or a wrong config on my side, but I am observing the following behavior:

When I open an .R file, the completion works according to what is in the file, so for example, if the file contains library(ggplot2) I will be offered all ggplot variables for the completion, but then I run R using <leader>rf completion no longer works for ggplot, it works only for base R things and it works for ggplot again only after I run the code in the R console. Sorry for a convoluted explanation, I hope it is understandable anyway.

@jalvesaq
Copy link
Member

Yes, this is the expected behavior. We can discuss and change the expected behavior, but, currently, both the Object Browser and auto-completion reflect what is loaded in R's memory. Suppose that you are sending lines one at a time and that a specific library() call is in the middle of the script. It would not work if you tried to call a function of the unloaded library before sending its library() command to R. Consistent with this, auto-completion will not work before the library is loaded. In the rare circumstance when a user detaches a library, it's also unloaded from rnvimserver.

But, as I said, we can change the default behavior to:

  1. Load in rnvimserver the data of all libraries with a corresponding library() command in the script.
  2. After starting R, never unload any library data from rnvimserver.
  3. Load in rnvimserver data of libraries that were not in the script at R startup as they are loaded after R was started.

@dinga92
Copy link
Author

dinga92 commented Mar 22, 2024

Thanks for your reply.

I don't know what the expected behavior should be. I don't think that Rstudio will autocomplete objects not in the memory, on the other hand I wouldn't expect that the scope of autocompletion gets smaller after we call R.

Option 1 won't work because it will not autocomplete variables defined in the script that has not yet been committed to memory.

Anyway, thanks for your work.

@jalvesaq
Copy link
Member

1, 2, and 3 are not options. It's a sequence of how it would behave. Currently, the sequence is:

  1. Load in rnvimserver the data of all libraries with a corresponding library() command in the script.
  2. After starting R, unload all libraries from rnvimserver.
  3. Load in rnvimserver data of libraries as they are loaded after R was started.

Objects created in the R code are not recognized before being created in R's memory because R.nvim analysis of the code is limited to seeking library() commands.

@dinga92
Copy link
Author

dinga92 commented Mar 22, 2024

alright, got it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants