You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parse document and capture function and symbol definitions #19
At the moment, this package is not designed for providing completions from attached R session (like RStudio), local symbol/function completion for currently editing file is missing.
One simple approach to implement this is to parse the file or document being edited and extract all expressions like
fun<-function(a, b, c)
fun=function(a, b, c)
x<-list(1, 2, 3)
that is, top-level expression with an assignment operator (<- or =), and LHS is a symbol. If RHS is function, then function completion will be provided, or otherwise it is regarded as a variable.
It is actually on my radar. We are not going to execute the R code but rather to analyze it lexically. codewalk may be something that we need to capture the top level expressions. I have not played with it. If it is too slow, we might need to write a c parser at some point.
A starting point would be using parse() directly which however assumes correct syntax of the file or document. The parsing, like searching library() calls, can be done only when file is saved, so that the performance of the native R parser should not make a noticeable impact.
The document is read by readLines() as well as parsed by parse() (if successful), then the parsed expression is used to capture top-level variable and function definitions.
Activity
randy3k commentedon Jun 24, 2018
It is actually on my radar. We are not going to execute the R code but rather to analyze it lexically.
codewalkmay be something that we need to capture the top level expressions. I have not played with it. If it is too slow, we might need to write a c parser at some point.renkun-ken commentedon Jun 24, 2018
Glad to know that!
A starting point would be using
parse()directly which however assumes correct syntax of the file or document. The parsing, like searchinglibrary()calls, can be done only when file is saved, so that the performance of the native R parser should not make a noticeable impact.What do you think of it?
renkun-ken commentedon Jun 26, 2018
languageserver@document-completion is an initial attempt to providing completions of variables and functions defined in document.
The document is read by
readLines()as well as parsed byparse()(if successful), then the parsed expression is used to capture top-level variable and function definitions.randy3k commentedon Jun 26, 2018
Thanks for the initiative work. I’ll take a look tomorrow.
randy3k commentedon Aug 27, 2018
closed by v0.2.4
randy3k commentedon Aug 27, 2018
Ai, there are actually a few bugs in v0.2.4. Check out current master instead.