Skip to content
Nathan Kim edited this page Dec 15, 2021 · 7 revisions

The R language server implements the Language Server Protocol and provides a set of language analysis features such as completion, providing function signatures, extended function documentation, locating function implementations, occurrences of a symbol or object, and code diagnostics and formatting. The R language server statically analyzes R code, and vscode-R interfaces with it to provide the core of this extension's functionality.

The R language server is implemented by the languageserver package which performs static code analysis with the latest user documents in R and Rmd languages. Therefore, it does not rely on an active R session and thus does not require the code to be executed.

To install the package from CRAN:

install.packages("languageserver")

To experience the latest features, install the package from GitHub:

remotes::install_github("REditorSupport/languageserver")

Settings

See the extension settings page for information on configuring the language server.

Features

The R language server contributes the following features.


Smart editing


Autocompletion

The R language server provides global and scope-based autocompletion. You can scroll through the suggested signatures with the arrow keys.

Global autocompletion:

Completion

Scope-based autocompletion:

Scope completion

The R language server currently does not provide completion for filenames; see this comment..

Signature preview

The R language server provides popups of function signatures and their short descriptions as you type, which can save a few calls to help().

Package function signature

User function signature

Hover

A larger preview of the documentation is shown when users mouse over R symbols:

Hover

Diagnostics

Diagnostics

Formatting

The language server provides code formatting through the through the styler package in R. See here for configuration.

Formatting

On-type-formatting

Rename symbol

Symbol renaming through the language server allows you to group renaming actions together, letting you refactor code more easily and discard a change on the fly if need be.

Rename symbol


Document organization


Symbol highlight

When the cursor is inside of a symbol, all occurrences of that symbol within the document are highlighted.

Symbol highlight

Document selection

You can expand selections through Shift+Alt+RightArrow. Selections are expanded in steps, following the boundaries of each containing R expression.

Selection range

Code sections

The R language server informs VSCode of code sections, or blocks of code that form coherent R expressions, which can be navigated through the outline or the panel header.

Code section symbols

Sections can also be folded, allowing users to organize the current editor:

Code section and function folding ranges

Call hierarchy

The R language server's static analysis also allows users to see the call sequence and hierarchy within an R expression.

Call Hierarchy


Document navigation


Document and workspace symbols

Users can navigate through the document outline or search for symbols by prepending an @ symbol in the search bar.

Document/workspace symbols

Find all occurrences

Ctrl+Clicking on a user-created R object, pressing Shift+F12 while the cursor is focused on any object, or right-clicking and then selecting Go To References will open a popup showing all of the uses of the object within the current document.

Find references

Document links

Ctrl+Click on a file path takes the user to the referenced document.

Link

Go to definition

Ctrl+Clicking on an R symbol, pressing F12 while the cursor is focused on a symbol, or right-clicking and then selecting Go To Definition will bring up a function's implementation.

Definition


Miscellaneous


Color picker

Strings of text that are recognized as R colors are rendered with a color decoration. Hovering over the decoration brings out a color picker popup that can be used to adjust the referenced color.

Document color