vscode-R
vscode-R copied to clipboard
Autocompletion of session variables and suggestion in vscode-Jupyter
Describe the bug
I have run R scripts in vscode-Jupyter for some time. Recently after upgrading the extensions, there is somthing wrong with it. The autocompletion suggestions and the names of variables defined previously disappear in .ipynb
files even though the appropriate IRkernel have been installed in Jupyter. But it still works well in .R
files.
To Reproduce Steps to reproduce the behavior:
- Create a
.ipynb
/.R
file - Type some R scripts such as
a <- c(1, 2)
- Start new line with
a
- in the.R
file you'll see variable suggestions, in.ipynb
you won't.
Setting.json
"r.rterm.windows": "C:\\Users\\myusername\\anaconda3\\Scripts\\radian.exe",
"r.rpath.windows": "C:\\Program Files\\R\\R-4.1.3\\bin\\x64\\R.exe"
"r.bracketedPaste": true,
"r.sessionWatcher": true
Screenshot
Autocompletion doesn't see the session variables and suggestions in .ipynb
:
But autocompletion works in .R
:
The log of Extension Host:
Environment:
- OS: Windows 10 x64 (build 22000)
- VSCode Version: 1.66.1
- R Version: 4.1.3 (2022-03-10)
- vscode-R version: v2.4.0
- vscode-Jupyter version: v2022.3.1000901801
Did you try installing the latest development version of languageserver via
remotes::install_github("REditorSupport/languageserver")
and the latest build of vscode-R?
Yes, I have tried the latest version/build of them. It doesn't work.
OK. Let me see if I could reproduce the problem.
I could reproduce the problem.
It looks like the language server only receives document open/save/change events. It never receives anything else such as completion and hover requests. Looks like these providers are somehow not registered or the notebook does not redirect those requests to R language server.
Thanks for your help. The bug is likely from a change in VS code core. I just tried an old version of vscode. It worked fine.
Version: 1.63.2 (user setup) Commit: 899d46d82c4c95423fb7e10e68eba52050e30ba3 Date: 2021-12-15T09:40:02.816Z Electron: 13.5.2 Chromium: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Windows_NT x64 10.0.22000
But I still would like to use the latest version of vscode. Hope someone could fix it.
Thanks for confirming it worked in older vscode versions. Looks like I need to change something in the language client or server to adapt to the latest changes in notebooks api which is broken in this case.
We had to make a similar change for python in the Jupyter extension here: https://github.com/microsoft/vscode-jupyter/commit/362ca2fd842adfe5ce8e78686d5874dd0e085de5
@rchiodo Thanks for the information!
I take a look at the fix and https://github.com/microsoft/vscode-jupyter/pull/9386. It looks like we are missing a document filter like the following:
{ language: 'r', notebookType: 'jupyter-notebook' },
Maybe it is a stupid question, but I'm wondering what should be done to use notebookType
here? Should I depend on proposed api or something?
Looks like I need to depend on a newer vscode.d.ts to include this?
Also there is a mention of this at https://code.visualstudio.com/updates/v1_66#_notebookaware-document-selectors.
I tried to make the fix at https://github.com/REditorSupport/vscode-R/compare/jupyter-notebook but it does not build with the following errors at https://github.com/REditorSupport/vscode-R/runs/6017891653?check_suite_focus=true:
ERROR in /github/workspace/src/languageService.ts
./src/languageService.ts 193:29-61
[tsl] ERROR in /github/workspace/src/languageService.ts(193,30)
TS2322: Type '{ language: string; notebookType: string; pattern: string; }' is not assignable to type 'DocumentFilter'.
Object literal may only specify known properties, and 'notebookType' does not exist in type 'DocumentFilter'.
If I debug anyway with errors, the language providers seem to work for notebooks.
Am I missing something?
Are you updating your vscode.d.ts in your build folder? We use this command to do so:
vscode-dts main
This should download the vscode.d.ts that is the most up to date. The latest one does have the 'notebookType' in the DocumentFilter type.
Yes, vscode.d.ts
contains a definition of DocumentFilter
but we import it from vscode-languageclient/node
, otherwise LanguageClientOptions.documentSelector
does not seem to accept it.
Am I missing something?
Looks like I need to use a newer version of the language client"vscode-languageclient": "^8.0.0-next.14"
.
Now the language server roughly works with notebooks but errors occur when I edit cells:
[2022-04-18 15:08:52.807] internal error: Error: key not found
Call: self$workspace$documents$get(uri)
Stack trace:
1: self$workspace$documents$get(uri)
2: dispatch(self, id, params)
[2022-04-18 15:08:52.808] token: {
"full_token": "read.csv",
"right_token": ".csv",
"package": null,
"accessor": "",
"token": "read.csv"
}
[2022-04-18 15:08:52.809] deliver: ["Response", "Response", "Message", "R6"]
[Error - 3:08:52 PM] Request textDocument/hover failed.
Message: Error: key not found
Call: self$workspace$documents$get(uri)
Stack trace:
1: self$workspace$documents$get(uri)
2: dispatch(self, id, params)
Code: -32603
It looks like the document open requests are not sent before other requests. Is it an intended behavior?
I don't think so as I don't see this for Python. If you upgrade the language client I think the API is different though. @dbaumer would be a good person to ask. He's in the middle of changing the language client API to work better for notebooks, so maybe it's too early to switch the language client module?
As in just type cast the DocumentFilter as 'any' for now and don't update to the latest vscode-languageclient module yet.
I'm been having this issue for some time. Have there been any new developments?
Sorry, this is not related but this is the only place I could find that talks about R with jupyter notebook. So, I just started trying vscode jupyter notebook for R using IRkernal. But, when I plot an image, I got:
You can see the plot is hard to see due to the vscode's dark theme. Anyone can help me? Thanks.
As far as I can see, this is still happening with VS Code 1.73.0:
Version: 1.73.0
Commit: 8fa188b2b301d36553cbc9ce1b0a146ccb93351f
Date: 2022-11-01T15:33:40.745Z
Electron: 19.0.17
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Darwin arm64 22.1.0
Sandboxed: No
This issue is stale because it has been open for 365 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.