Skip to content

Parse document and capture function and symbol definitions #19

Closed

Description

@renkun-ken

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.

Activity

  1. randy3k commented on Jun 24, 2018

    @randy3k
    Member

    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.

  2. renkun-ken commented on Jun 24, 2018

    @renkun-ken
    MemberAuthor

    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 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.

    What do you think of it?

  3. renkun-ken commented on Jun 26, 2018

    @renkun-ken
    MemberAuthor

    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 by parse() (if successful), then the parsed expression is used to capture top-level variable and function definitions.

  4. randy3k commented on Jun 26, 2018

    @randy3k
    Member

    Thanks for the initiative work. I’ll take a look tomorrow.

  5. randy3k commented on Aug 27, 2018

    @randy3k
    Member

    closed by v0.2.4

  6. randy3k commented on Aug 27, 2018

    @randy3k
    Member

    Ai, there are actually a few bugs in v0.2.4. Check out current master instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions