Nvim-R icon indicating copy to clipboard operation
Nvim-R copied to clipboard

Autocomplete with non-loaded library

Open PMassicotte opened this issue 1 year ago • 4 comments

I often use helper functions, like janitor::clean_names(), when processing data. I have looked in the documentation and I could not find if it was possible to trigger autocomplete from non-loaded library using :: .

Peek 2023-12-21 07-17

Thank you

PMassicotte avatar Dec 21 '23 12:12 PMassicotte

Currently, it's not possible to autocomplete the names of objects from non-loaded libraries because nvimrserver only loads from Nvim-R's cache directory data from loaded libraries. Moreover, Nvim-R only builds the cache files when a library is loaded.

jalvesaq avatar Dec 22 '23 08:12 jalvesaq

Ok thank you!

PMassicotte avatar Dec 22 '23 11:12 PMassicotte

Just noticed that it works if R is closed and if I am using this:

 vim.g.R_start_libs = 'base,stats,graphics,grDevices,utils,methods,janitor'

However, it stops working when R starts

Peek 2023-12-22 09-13

PMassicotte avatar Dec 22 '23 14:12 PMassicotte

Yes, this is documented in section 6.3. of doc/Nvim-R.txt (Omnicompletion and syntax highlighting). It will even work for libraries that were never loaded because their data will be cached at Nvim-R initialization.

The implementation of what you requested when opened the issue is:

  1. Build or update the cache data of all installed libraries on Nvim-R startup.
  2. In addition to the currently existing list of loaded libraries, create in nvimrserver a list of unloaded libraries.
  3. When the completion of the kind package:: is required, load the library data on the list of unloaded libraries and do the completion from this data.

Notes:

  • Because caching the data of all installed libraries is going to be slow, it should happen asynchronously.
  • It would be necessary some kind of lock file to prevent nvimrserver from loading incomplete data.
  • If a library's data is not cached yet when the completion is requested, the completion should simply fail (silently?).
  • Lock files are problematic because they will linger around if the R process creating them is killed before finishing its job (for example, if you reboot the computer). That's why I prefer to build the chance data synchronously.

jalvesaq avatar Dec 22 '23 20:12 jalvesaq

This is an issue for our new R.vim when it's inaugurated...

jalvesaq avatar Feb 18 '24 15:02 jalvesaq