Git Product home page Git Product logo

Comments (12)

randy3k avatar randy3k commented on May 26, 2024 1

Yes, every extra bit of information will help.

from languageserver.

randy3k avatar randy3k commented on May 26, 2024

It is not trivial. The easy part is to parse an R6 class and inspect its methods. The more tricky part is to deduce if a variable is an R6 object or not. It’s not always as easy as

var <- MyClass$new()

In particular, a variable could be assigned to any thing dynamically. With only lexical analysis, it’s not 100% guaranteed that the inspected result is correct (or even possible). An simple example could be

var <- if (condition) MyClass$new() else AnotherClass$new()

Not to mention that the variable could be a result of a complicated chain of actions.

One resolution that I am thinking is manual explicit annotations via roxygen

@param x MyClass
@return AnotherClass
foo <- function(x) {
      AnotherClass$new(x)
}

Of course, this method also comes with its problems.

from languageserver.

hongyuanjia avatar hongyuanjia commented on May 26, 2024

Thanks for the explanation.

Sorry I did not know the internal implementation of auto-completion. I am not sure if current implementation is totally different from what RStudio does. Probably I am underestimate the difficulty.

from languageserver.

randy3k avatar randy3k commented on May 26, 2024

What you are pointing to is related to console auto completion. In a console, we know exactly if an object is R6 or not. However, we are working with editors and we don’t actually run the code. All the analysis are done lexically which makes the job difficult.

from languageserver.

hongyuanjia avatar hongyuanjia commented on May 26, 2024

Oh I see where the difficulty comes from. This is probably a restriction when working on lsp. Anyway, still want to thank you for this amazing work and hope this feature can be implemented in the future.

from languageserver.

hongyuanjia avatar hongyuanjia commented on May 26, 2024

One resolution that I am thinking is manual explicit annotations via roxygen

@param x MyClass
@return AnotherClass
foo <- function(x) {
      AnotherClass$new(x)
}

Just see that roxygen2 now supports more intuitive documentation via r-lib/roxygen2#922. Will it help to implement R6 autocomplete?

from languageserver.

renkun-ken avatar renkun-ken commented on May 26, 2024

@hongyuanjia If you are using VSCode, REditorSupport/vscode-R#165 is my initial attempt for session symbol completion which is able to complete list, environments, S4 objects. R6 objects are basically environments so it works with R6 too.

If you are interested, you may have a try with my cutting edge testing build of vscode-R at https://github.com/renkun-ken/vscode-R/releases, which tracks my test branch with all my PRs at https://github.com/Ikuyadeu/vscode-R/pulls merged.

from languageserver.

hongyuanjia avatar hongyuanjia commented on May 26, 2024

@renkun-ken thanks for the info! I will test if it works with current vscode-R release and yours and post here the results.

from languageserver.

hongyuanjia avatar hongyuanjia commented on May 26, 2024

@renkun-ken unfortunately, neither current vscode-R release and your cutting-edge version can do the completion for my use case.

Here is a reproducible example.

library(eplusr)
path_idf <- system.file("extdata/1ZoneUncontrolled.idf", package = "eplusr")
idf <- read_idf(path_idf, use_idd("auto"))
#> IDD v8.8.0 has not been parsed before.
#> Try to locate `Energy+.idd` in EnergyPlus v8.8.0 installation folder 'C:/EnergyPlusV8-8-0'.
#> IDD file found: 'C:\EnergyPlusV8-8-0\Energy+.idd'.
#> Start parsing...
#> Parsing completed.

class(idf)
#> [1] "Idf" "R6" 

names(idf)
#>  [1] ".__enclos_env__"     "clone"               "print"              
#>  [4] "run"                 "save"                "is_unsaved"         
#>  [7] "to_table"            "string"              "to_string"          
#> [10] "is_valid"            "validate"            "replace_value"      
#> [13] "search_value"        "del_object"          "ins_object"         
#> [16] "set_object"          "add_object"          "dup_object"         
#> [19] "paste"               "update"              "load"               
#> [22] "insert"              "rename"              "del"                
#> [25] "set"                 "add"                 "dup"                
#> [28] "search_object"       "object_in_class"     "objects_in_relation"
#> [31] "object_relation"     "objects_in_group"    "objects_in_class"   
#> [34] "objects"             "object_unique"       "object"             
#> [37] "object_num"          "is_valid_name"       "is_valid_id"        
#> [40] "object_name"         "object_id"           "definition"         
#> [43] "is_valid_class"      "is_valid_group"      "class_name"         
#> [46] "group_name"          "path"                "version"            
#> [49] "initialize"

Created on 2020-01-01 by the reprex package (v0.3.0)

In vscode, when I type idf$, nothing from the names pops up.

from languageserver.

renkun-ken avatar renkun-ken commented on May 26, 2024

@hongyuanjia Thanks for testing. Do you mind commenting at REditorSupport/vscode-R#165, which is more relevant.

from languageserver.

hongyuanjia avatar hongyuanjia commented on May 26, 2024

@renkun-ken Sure thing

from languageserver.

renkun-ken avatar renkun-ken commented on May 26, 2024

This package only does static analysis at the moment and is not intended to provide any information related to a user's live session. However, we could still provide completion for classes defined in packages because their structures are known. It's a special case of #158. In this case, it is more of auto-completion for R6 classes or instances defined in packages than for R6 objects (or instances) living in a user session.

from languageserver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.