Skip to content

Provide completion for session symbols#165

Merged
andycraig merged 9 commits intoREditorSupport:masterfrom
renkun-ken:completion
Jan 24, 2020
Merged

Provide completion for session symbols#165
andycraig merged 9 commits intoREditorSupport:masterfrom
renkun-ken:completion

Conversation

@renkun-ken
Copy link
Copy Markdown
Member

@renkun-ken renkun-ken commented Dec 27, 2019

What problem did you solve?

Closes #164
Closes #170

This PR provides

  • Completion of session symbols, showing symbol str in documentation. The latest languageserver already supports workspace completion (global variables in code), scope completion (local variables in scope). This PR adds session completion as a new kind of completion.
  • Completion of elements in list-like objects (list, environment, S4 objects). As for R6 object, they are basically environments so that they are covered too.
  • Completion of symbols in brackets [], mainly for subsetting and extracting using "col", or accessing elements with dynamic scoping in brackets (usage of data.table).

(If you have)Screenshot

Session symbol completion

image

image

Completion for elements in list-like objects

image

image

image

image

Completion for brackets

Quoted symbol:

image

Element completion for dynamic scoping in data.table:

image

image

@hongyuanjia
Copy link
Copy Markdown

Comments below were original posted in REditorSupport/languageserver#75. @renkun-ken requested to also post them here which are more relavent to this PR.


Neither current vscode-R release and @renkun-ken's 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.

Please note that idf object contains active bindings. Not sure if this may influence the auto-completion.

@renkun-ken
Copy link
Copy Markdown
Member Author

renkun-ken commented Jan 1, 2020

Would you mind check is.list(idf) and is.environment(idf) and take a look at ${workspaceFolder}/.vscode/vscode-R/{pid}/globalenv.json and can you see idf has these names in this file?

I tried with environemnts with active bindings but everything looks normal here.

@hongyuanjia
Copy link
Copy Markdown

It's embarrassing but I noticed that I did not attach the R session. Because R session created from vscode did not respect my .Rprofile under ~/Documents (Windows default). After I attach the session (by manually run the command in vscode-R README), I can confirm the auto-completion works as expected.

Sorry for the bother.

@hongyuanjia
Copy link
Copy Markdown

@renkun-ken I can confirm that is.list(idf) returns FALSE and is.environment(idf) returns TRUE. And below is the contents of file globalenv.json which indeed contains all the names of idf object.

{"path_idf":{"class":["character"],"type":"character","length":1,"str":"chr \"C:/Users/hongy/R/eplusr/extdata/1ZoneUncontrolled.idf\""},"idf":{"class":["Idf","R6"],"type":"environment","length":49,"str":"-- EnergPlus Input Data File ---------------------------------------------------","names":[".__enclos_env__","clone","print","run","save","is_unsaved","to_table","string","to_string","is_valid","validate","replace_value","search_value","del_object","ins_object","set_object","add_object","dup_object","paste","update","load","insert","rename","del","set","add","dup","search_object","object_in_class","objects_in_relation","object_relation","objects_in_group","objects_in_class","objects","object_unique","object","object_num","is_valid_name","is_valid_id","object_name","object_id","definition","is_valid_class","is_valid_group","class_name","group_name","path","version","initialize"]}}

Thanks for your great work!

Wish this feature can be implemented into the language server, because I mainly use Vim with the language server for my R work. Anyway, thanks to you and other contributors, vscode-R indeed becomes a rich-featured R IDE now.

@renkun-ken
Copy link
Copy Markdown
Member Author

@hongyuanjia, Thanks for your testing. As we discussed at REditorSupport/languageserver#75, languageserver is designed to only perform static analysis, i.e., no active R session is assumed. Session-related features are editor-specific at the moment. Maintainers of R support in other editors could implement such features using similar methods (we use a file-based method in vscode) or come up with better methods, or similar with RStudio methods (socket-based method), but anyway it is editor-specific.

@renkun-ken
Copy link
Copy Markdown
Member Author

@Ikuyadeu @andycraig This PR is a LGTM. Please take a look.

@andycraig
Copy link
Copy Markdown
Collaborator

This looks amazing and I will try to review it this weekend.

Copy link
Copy Markdown
Collaborator

@andycraig andycraig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested this on Windows and all the features work. I haven't reviewed the code carefully but I think it is fine to merge. It is a great addition!

@andycraig andycraig merged commit 86c8120 into REditorSupport:master Jan 24, 2020
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 this pull request may close these issues.

Provide completion for elements in list-like objects Provide completion for session symbols

3 participants