Skip to contents

These guides first appeared after the CRAN release of languageserver 0.3.22. If you use that release, the five-minute walkthrough works as written. Use the comparison below when an example elsewhere on the site behaves differently in your editor. For another release, consult its installed help and release notes.

Compare feature availability

Available in 0.3.22 Additions since 0.3.22 illustrated in these guides
Complete ordinary R calls, inspect argument values, and see signatures for statically inferred S3 methods. Complete quoted source paths and members from supported wrapped package attachments, functions assigned to members, and roxygen type hints. Complete and navigate embedded R expressions in glue templates.
Use incremental text synchronization, semantic highlighting, outlines, folds, selections, and hints. Edit R chunks in R Markdown and Quarto. Incremental tree-sitter syntax helps with edits in progress. Newer behavior includes nested function outlines, class-member and glue highlighting, multiline [[ folds, mixed R/prose selections, compound source-path links, and more color-literal spellings. Inlay hints recognize resolved member calls, linked editing covers documented method parameters, and debugger inline values can identify the receiver of a field access.
Follow definitions and literal source() dependencies, search a workspace, use Find References or Rename, and inspect call counts and incoming or outgoing calls. Go to Type Definition and Go to Implementation are additional providers. Go to Definition can find a closed test helper, S4 method registrations, and generated installed member functions. References and Rename can follow the owner of a sourced name, named call arguments, and verified type annotations. Member highlights, hierarchy results, and call counts distinguish same-named methods on different objects.
Complete R6 members, S4 slots, S7 properties, dataset columns, and supported Polars methods. Browse type hierarchies for R6, reference classes, and S4. The classes and methods guide covers S4 constructor and initializer arguments, S7 1.0 method dispatch and inherited properties, S7 type hierarchy, R6 clones, and reference-class methods. In data-masked expressions, the server can find a column’s source declaration and distinguish it from an enclosing variable.
Use lintr and styler, choose Jarl or Air, apply Quick Fix or Fix All, and extract or inline code. Extraction and inlining can use intact scopes in a partially typed file and handle standalone braces, saved reads, and list updates.
Start the server with run() over stdio or TCP. Package workspaces are indexed in the background. Embedded hosts and webR can use run_embedded(), exchange JSON-RPC messages directly, share an execution session’s package context, and request diagnostics for open buffers. The workspace server also reports package metadata progress and can find named callers before indexing finishes.

Settings added after 0.3.22 include glue_highlighting, glue_highlight_functions, project_helpers, roxygen_type_hints, and roxygen_advisory_type_hints. That release also predates the installed quick-start vignette and the dedicated settings, backends, and capabilities help topics. Server settings

Install a development build

To try changes on master, install from r-universe into the R library used by your editor and restart its language server. Check the installation’s repository and commit if it shares a version number with a released build. Identify the installed build

install.packages("languageserver", repos = c(
  reditorsupport = "https://reditorsupport.r-universe.dev",
  CRAN = "https://cloud.r-project.org"
))

To install the current CRAN release, run install.packages("languageserver", repos = "https://cloud.r-project.org") and restart the server. Development builds · Release notes

Version 0.3.22 installed roxygen2 and stringi as dependencies. They later became optional. In a minimal installation, add roxygen2 for structured help from local #' comments, and stringi for ICU-based Unicode matching and detection of legacy-encoded files. The server reads UTF-8 and byte-order-marked UTF-16 and UTF-32 source files with base R.

Edit R inside a glue string

amount <- 42
glue::glue("Total: {price}", price = amount)

Put the cursor on price inside the braces and choose Go to Definition. The target is the named argument price = amount. Rename price to total there and both occurrences change together. The variable supplying its value keeps the name amount.

Inside the braces, you can also request completion, hover help, or Signature Help. Try typing { in a new glue string and requesting completion for amo. In VS Code, Trigger Suggest works on demand. To reopen suggestions automatically as you type inside an existing R string, add this to settings.json. Use the [rmd] block for R Markdown.

{
  "[r]": {
    "editor.quickSuggestions": { "strings": "on" }
  }
}

The server recognizes directly quoted templates with the standard delimiters in glue(), glue_data(), str_glue(), and str_glue_data(), including raw strings. Doubled braces represent literal text. If you wrap glue, you can also ask the editor to color R expressions in your wrapper’s templates. This .Rprofile example identifies the first unnamed argument of my_glue() and the template argument of reports::render().

options(languageserver.glue_highlight_functions = list(
  my_glue = 1L,
  "reports::render" = "template"
))

These registrations apply only to semantic highlighting. Settings

With glue_data(), the data argument can supply a template name. In this example, use Go to Definition on value inside the braces to find the named list entry. Find References also finds record$value. An explicit named glue argument can take precedence over the field. Custom delimiters, transformers, or an unknown evaluation environment can limit which bindings the server can identify.

record <- list(value = 4)
record$value
glue::glue_data(record, "{value}")

Find a helper loaded by your test runner

A test might call a helper without a visible source() line. In a project containing tests/testthat/, save these two files.

# tests/testthat/helper-scores.R
sample_scores <- function() c(3, 7, 8)
# tests/testthat/test-scores.R
mean(sample_scores())

In the project’s .Rprofile, map the calling files to the helper.

options(languageserver.project_helpers = list(
  "tests/testthat/test-*.R" = "tests/testthat/helper-scores.R"
))

Open the project root, restart the server, and leave the helper file closed. Invoke Go to Definition on sample_scores in the test. The server opens the helper’s definition. The caller can be a glob, and helper filenames are literal paths relative to the workspace root. This mapping applies to Go to Definition and works with index modes auto, lazy, and full. Project navigation

Rename a variable used beside a data-frame column

score <- 5
scores <- data.frame(score = c(3, 7, 8))
dplyr::filter(scores, .data$score > .env$score)

Place the cursor on score in the first line and rename it to threshold. The last comparison becomes .data$score > .env$threshold. The .env pronoun explicitly identifies the R variable, and .data identifies the column. A bare name in a data-masked call can be ambiguous. When the server cannot determine which binding a rename would affect, it declines the edit.

Go to Definition for S4 methods

methods::setGeneric("describeSample", function(x) standardGeneric("describeSample"))
methods::setMethod("describeSample", "numeric", function(x) mean(x))
methods::setMethod("describeSample", "character", function(x) unique(x))

summarize <- function(value) describeSample(value)

Invoke Go to Definition on describeSample in the last line. The editor receives three source locations, the generic followed by its two method registrations. Pick a method to inspect its body. This works even when the class of value is unknown. You can also navigate from the generic name in selectMethod("describeSample", "numeric"). Visible declarations can come from the current package’s R files or the script’s static source dependencies.

For an operator such as +, the results can include methods registered for the operator and its Arith and Ops groups. Replacement access, such as value(x)[i] <- y, can lead from value to a registered value<- method.

Use Find References to see the generic’s source registrations and calls that resolve to it. A local function of the same name can have its own callers. Rename declines edits to a registered S4 generic.

Open an S3 implementation or a class declaration

In the S3 signature example, put the cursor on present in present(frame, format = "text"). Go to Definition opens present. Go to Implementation opens present.data.frame, the method selected for frame. Try the same action on present(values, scientific = TRUE) to open present.numeric. The server needs enough information about the input class to identify the method.

To find the class an object comes from, try this R6 example.

Counter <- R6::R6Class("Counter")
counter <- Counter$new()
counter

Invoke Go to Type Definition on the final counter. The editor opens the Counter class declaration. This action can also locate source definitions for reference classes, S4, and S7 when the receiver has one identifiable declaration. Client capabilities

Keep editing an incomplete script

Try Go to Definition on double_score in the last line while the middle line still ends in ::. It can find the declaration on the first line. The outline and semantic highlighting can also use the complete statements around a recoverable syntax error.

double_score <- function(points) points * 2
stats::
report_score <- function(x) double_score(x)

Recovery depends on the enclosing R syntax. An unfinished string or unmatched delimiter can obscure a scope. Rename and refactoring are available where the server can identify which code an edit would affect. In an R Markdown or Quarto file, R chunks recover independently. Mixed-language documents

What changed in large workspaces?

Changes after 0.3.22 speed up large-file parsing, bulk lint fixes, and edits in literate documents. S3 method information becomes available sooner after startup on R versions before 4.6. Closing external Quarto documents releases their temporary state, and shutting down the server stops background work while the editor finishes the protocol handshake. On a slow machine, R_LANGSVR_TIMEOUT_SCALE can give metadata workers more time. Server settings