Skip to content

Commit adec717

Browse files
authored
Integrate vscode-r-lsp (#695)
* Integrate vscode-r-lsp * Do not start language service if r-lsp is enabled * Use workbench.extensions.search * Reorganize languageService.ts * Add r.lsp.enabled * Update README
1 parent 545ddd8 commit adec717

File tree

5 files changed

+369
-10
lines changed

5 files changed

+369
-10
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,42 @@
33
[![Badge](https://aka.ms/vsls-badge)](https://aka.ms/vsls)
44

55
This [VS Code](https://code.visualstudio.com/) extension provides support for the [R programming language](https://www.r-project.org), including features such as
6-
extended syntax highlighting, interacting with R terminals, viewing data, plots, workspace variables, help pages, managing packages, and working with [R Markdown](https://rmarkdown.rstudio.com/) documents.
6+
extended syntax highlighting, R language service based on code analysis, interacting with R terminals, viewing data, plots, workspace variables, help pages, managing packages, and working with [R Markdown](https://rmarkdown.rstudio.com/) documents.
77

88
Go to the [wiki](https://github.com/REditorSupport/vscode-R/wiki) to view the documentation of the extension.
99

1010
## Getting started
1111

1212
1. [Install R](https://cloud.r-project.org/) (>= 3.4.0) on your system. For Windows users, Writing R Path to the registry is recommended in the installation.
1313

14-
2. Install [`jsonlite`](https://github.com/jeroen/jsonlite) and [`rlang`](https://github.com/r-lib/rlang) packages in R.
14+
2. Install [`languageserver`](https://github.com/REditorSupport/languageserver) in R.
1515

1616
```r
17-
install.packages(c("jsonlite", "rlang"))
17+
install.packages("languageserver")
1818
```
1919

2020
3. Install the [R extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=Ikuyadeu.r).
2121

2222
4. Create an R file and start coding.
2323

24-
Note that the above steps only provide basic code editing functionalities and features of interacting with R sessions. To get full R development experience such as code completion, linting, formatting, debugging, etc., go to the installation wiki pages ([Windows](https://github.com/REditorSupport/vscode-R/wiki/Installation:-Windows) | [macOS](https://github.com/REditorSupport/vscode-R/wiki/Installation:-macOS) | [Linux](https://github.com/REditorSupport/vscode-R/wiki/Installation:-Linux)) for detailed instructions of installing the following recommended software and extensions:
24+
The following software or extensions are recommended to enhance the experience of using R in VS Code:
2525

2626
* [radian](https://github.com/randy3k/radian): A modern R console that corrects many limitations of the official R terminal and supports many features such as syntax highlighting and auto-completion.
2727

28-
* [languageserver](https://github.com/REditorSupport/languageserver): An R package that implements the Language Server Protocol for R to provide a wide range of language analysis features such as auto-completion, function signature, documentation, symbol highlight, document outline, code formatting, symbol hover, diagnostics, go to definition, find references, etc.
29-
30-
* [vscode-r-lsp](https://marketplace.visualstudio.com/items?itemName=REditorSupport.r-lsp): A VS Code extension of R LSP Client to communicate between VS Code and R Language Server.
31-
3228
* [VSCode-R-Debugger](https://github.com/ManuelHentschel/VSCode-R-Debugger): A VS Code extension to support R debugging capabilities.
3329

3430
* [httpgd](https://github.com/nx10/httpgd): An R package to provide a graphics device that asynchronously serves SVG graphics via HTTP and WebSockets.
3531

32+
Go to the installation wiki pages ([Windows](https://github.com/REditorSupport/vscode-R/wiki/Installation:-Windows) | [macOS](https://github.com/REditorSupport/vscode-R/wiki/Installation:-macOS) | [Linux](https://github.com/REditorSupport/vscode-R/wiki/Installation:-Linux)) for more detailed instructions.
33+
3634
## Features
3735

3836
* Extended syntax highlighting for R, R Markdown, and R Documentation.
3937

4038
* Snippets for R and R Markdown.
4139

40+
* [R Language Service](https://github.com/REditorSupport/vscode-R/wiki/R-Language-Service): Code completion, function signature, symbol highlight, document outline, formatting, definition, refere
41+
4242
* [Interacting with R terminals](https://github.com/REditorSupport/vscode-R/wiki/Interacting-with-R-terminals): Sending code to terminals, running multiple terminals, working with remote servers.
4343

4444
* [Package development](https://github.com/REditorSupport/vscode-R/wiki/Package-development): Build, test, install, load all and other commands from devtools.

package.json

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,36 @@
11961196
"type": "string"
11971197
}
11981198
},
1199+
"r.lsp.enabled": {
1200+
"type": "boolean",
1201+
"default": true,
1202+
"description": "Enable the R language service to provide code analysis features (completion, signature, hover, diagnostics, definition, etc.)"
1203+
},
1204+
"r.lsp.args": {
1205+
"type": "array",
1206+
"default": [],
1207+
"description": "The command line arguments to use when launching R Language Server"
1208+
},
1209+
"r.lsp.debug": {
1210+
"type": "boolean",
1211+
"default": false,
1212+
"description": "Debug R Language Server"
1213+
},
1214+
"r.lsp.diagnostics": {
1215+
"type": "boolean",
1216+
"default": true,
1217+
"description": "Enable Diagnostics"
1218+
},
1219+
"r.lsp.lang": {
1220+
"type": "string",
1221+
"default": "",
1222+
"description": "Override default LANG environment variable"
1223+
},
1224+
"r.lsp.use_stdio": {
1225+
"type": "boolean",
1226+
"default": false,
1227+
"description": "Use STDIO connection instead of TCP. (Unix/macOS users only)"
1228+
},
11991229
"r.rmarkdown.codeLensCommands": {
12001230
"type": "array",
12011231
"items": {
@@ -1449,6 +1479,7 @@
14491479
"tree-kill": "^1.2.2",
14501480
"vsls": "^1.0.3015",
14511481
"winreg": "^1.2.4",
1452-
"ws": "^7.4.6"
1482+
"ws": "^7.4.6",
1483+
"vscode-languageclient": "^7.0.0"
14531484
}
14541485
}

src/extension.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import * as rHelp from './helpViewer';
2020
import * as completions from './completions';
2121
import * as rShare from './liveshare';
2222
import * as httpgdViewer from './plotViewer';
23+
import * as languageService from './languageService';
2324

2425
import { RMarkdownPreviewManager } from './rmarkdown/preview';
2526

@@ -44,7 +45,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<apiImp
4445
extensionContext = context;
4546

4647
// assign session watcher setting to global variable
47-
enableSessionWatcher = util.config().get<boolean>('sessionWatcher', false);
48+
enableSessionWatcher = util.config().get<boolean>('sessionWatcher');
4849

4950
// register commands specified in package.json
5051
const commands = {
@@ -129,6 +130,16 @@ export async function activate(context: vscode.ExtensionContext): Promise<apiImp
129130
// keep track of terminals
130131
context.subscriptions.push(vscode.window.onDidCloseTerminal(rTerminal.deleteTerminal));
131132

133+
// start language service
134+
if (util.config().get<boolean>('lsp.enabled')) {
135+
const lsp = vscode.extensions.getExtension('reditorsupport.r-lsp');
136+
if (lsp) {
137+
void vscode.window.showInformationMessage('The R language server extension has been integrated into vscode-R. You need to disable or uninstall REditorSupport.r-lsp and reload window to use the new version.');
138+
void vscode.commands.executeCommand('workbench.extensions.search', '@installed r-lsp');
139+
} else {
140+
context.subscriptions.push(new languageService.LanguageService());
141+
}
142+
}
132143

133144
// register on-enter rule for roxygen comments
134145
const wordPattern = /(-?\d*\.\d\w*)|([^`~!@$^&*()=+[{\]}\\|;:'",<>/\s]+)/g;

0 commit comments

Comments
 (0)