Comments (12)
Yes, every extra bit of information will help.
from languageserver.
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.
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.
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.
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.
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.
@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.
@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.
@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.
@hongyuanjia Thanks for testing. Do you mind commenting at REditorSupport/vscode-R#165, which is more relevant.
from languageserver.
@renkun-ken Sure thing
from languageserver.
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)
- Support for old R version HOT 3
- Support for path completions
- Availability of `formatOnType` in quarto
- Roxygen comments soft linebreaks aren't ignored in languageserver hover hints
- Reference support for S4 methods
- No documentSymbol response for Rmarkdown file with helix editor HOT 1
- Variable duplication, one from workspace, another from session
- Autocompletion Bugs in vscode rmd-files
- "glue" function semantic for the expressions inside {}
- spawn: bash failed with exit code 127 and signal 0. HOT 1
- callback error in Neovim: “attempt to compare string with number” HOT 1
- Completion dataframe variable/columns HOT 3
- Neovim lspinstall r-languageserver installation not using .Rprofile CRAN mirror address?
- languageserver crashes with regex in file
- VSCode outline fails in Rmarkdown document if there is pseudo chunk text inside the chunks
- VSCode Perl::LanguageServer causes a process that consumes CPU HOT 2
- Section collapsing issues HOT 1
- Error with renv: Header must provide a Content-Length property
- Hover and Outline do not appear to function
- languageserver and help page viewer not working in windows10 and miniforge environment
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from languageserver.