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

Extend completion with source by recursive parsing #20

Open
renkun-ken opened this issue Jun 24, 2018 · 11 comments
Open

Extend completion with source by recursive parsing #20

renkun-ken opened this issue Jun 24, 2018 · 11 comments

Comments

@renkun-ken
Copy link
Member

renkun-ken commented Jun 24, 2018

It is tricky to provide completion without attaching to the R session being used by user. One simplified approach that I believe can serve most of the purposes is parse the currently editing document and find top-level source functions, and parse those files recursively.

For example, the following code is from several R scripts:

main.R:

library(data.table)
library(glmnet)
source("my_plot.R")
source("data/utils.R")

my_plot.R:

library(ggplot2)

data/utils.R:

library(DBI)
requireNamespace("RMariaDB")

When main.R is being edited, those library expressions are captured. If those source expressions are captured and my_plot.R and data/utils.R are analyzed, where library and source expressions in these files are also captured, the completion will be much better and no less accurate, especially when #19 is implemented.

Also those top-level library(), require(), loadNamespace(), requireNamespace() calls can be used to provide diagnostics when required package is not installed.

@randy3k
Copy link
Member

randy3k commented Jun 24, 2018

Right now, we search for library and require in the current document only and show docs from those packages required. We need to extended it to source and support R package.

We also have to be cautious about infinitely loop while the files are loaded recursively.

@renkun-ken
Copy link
Member Author

Agreed.

A set of files associated with the document can be cached to avoid the infinite loop of source, i.e., each source will update the set of source files before processing the file, so that if a source file is already in the set, it would be ignored.

@randy3k
Copy link
Member

randy3k commented Aug 27, 2018

A related but not entirely the same issue

tidyverse uses a complicated way to load its dependencies rather than just using the Depends field. It would be hard for us to determine what packages need to recursive loaded.

One solution is to open a new R session via callr, load the library (in this case tidyverse) and see what packages are being attached.

callr::r(function(){library(tidyverse); search()})

@renkun-ken
Copy link
Member Author

Seems like a smart approach that avoids most of the complexities.

@syu-id
Copy link

syu-id commented Nov 4, 2019

I'm using the jupyterlab-lsp extension on JupyterLab, and completion for packages introduced by library(tidyverse) are not provided. Support for tidyverse would be great.

@randy3k
Copy link
Member

randy3k commented Nov 4, 2019

It’s has already been done. However, the package dependencies are only resolved when the file is open and saved.

@syu-id
Copy link

syu-id commented Nov 5, 2019

It’s has already been done. However, the package dependencies are only resolved when the file is open and saved.

Hi,
Thanks for the reply! I tried with Vim and completion for tidyverse packages works nicely.
So my previous issue might just be specific to JupyterLab.

@randy3k
Copy link
Member

randy3k commented Nov 5, 2019

It may be related to #15 and #27.

@syu-id
Copy link

syu-id commented Nov 5, 2019

Thank you. I have filed an issue at the jupyterlab-lsp repo and linked your suggestions: https://github.com/krassowski/jupyterlab-lsp/issues/95

@MilesMcBain
Copy link

MilesMcBain commented Oct 26, 2020

This would not work that well if the thing being sourced is lot a literal string. In my own workflow I frequently have something that does a thing like lapply(list.files(...), source, ...).

@siegfried
Copy link

Hi, I got a no visible global function definition for 'dseconds' if I write library(tidyverse). It can be removed by adding library(lubridate). Is it related to this issue?

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

Successfully merging a pull request may close this issue.

5 participants