Editor features and language server providers
Source:R/doc-capabilities.R
languageserver-capabilities.RdChoose an editor action below to see an R example. The workspace server started by
run() uses the capabilities negotiated with your editor. For open documents in an
embedded host, see the features of run_embedded() below. To check a different
package version, compare feature availability.
Which editor features can I use?
For features built on these providers, see the guides to data frames and Polars, classes and methods, roxygen type hints, and R Markdown and Quarto.
Write and read R
Complete a name, argument, value, or member and inspect the selected suggestion.
textDocument/completion,completionItem/resolve.Hover over a symbol for its definition, signature, or documentation.
textDocument/hover.See a call's signature and active parameter.
textDocument/signatureHelp.Show parameter names beside arguments and inspect a hint.
textDocument/inlayHint,inlayHint/resolve.Highlight occurrences of the symbol under the cursor.
textDocument/documentHighlight.Color code by its role in R, across a file, after edits, or in a range.
textDocument/semanticTokens/full,textDocument/semanticTokens/full/delta,textDocument/semanticTokens/range.Show a swatch and choose a new color literal.
textDocument/documentColor,textDocument/colorPresentation.See variable values beside the source during a debugging session.
textDocument/inlineValue.
Explore a file or project
Open the outline and jump to a section or declaration.
textDocument/documentSymbol.Search for symbols across the workspace.
workspace/symbol.Go to a source definition.
textDocument/definition.Go to the source class of an object.
textDocument/typeDefinition.Go to the selected implementation of a generic.
textDocument/implementation.Inspect a generated definition for an installed package function.
workspace/textDocumentContent. The server can requestworkspace/textDocumentContent/refreshwhen the content changes.Find references to a binding.
textDocument/references.Discover callers and callees in Call Hierarchy.
textDocument/prepareCallHierarchy,callHierarchy/incomingCalls,callHierarchy/outgoingCalls.Show and open a call-count CodeLens.
textDocument/codeLens,codeLens/resolve.Browse parent and child classes in Type Hierarchy.
textDocument/prepareTypeHierarchy,typeHierarchy/supertypes,typeHierarchy/subtypes.Detect a file link and open its target.
textDocument/documentLink,documentLink/resolve.Fold code or progressively expand a selection.
textDocument/foldingRange,textDocument/selectionRange.
Change code
Check a rename target and update its uses.
textDocument/prepareRename,textDocument/rename.Edit a roxygen parameter tag and its formal together.
textDocument/linkedEditingRange.Fix or suppress a finding, Fix All, extract, or inline code.
textDocument/codeAction.Open the refactoring guide from a code-action menu.
workspace/executeCommandwith client support forwindow/showDocument.
Diagnose and format
See lint findings in the buffer or the Problems list. The server sends
textDocument/publishDiagnosticsto the editor.Format an entire document.
textDocument/formatting.Format a selection or multiple disjoint selections.
textDocument/rangeFormatting,textDocument/rangesFormatting.Format while typing.
textDocument/onTypeFormatting.
Which features can an embedded host use?
A host such as a dedicated webR worker starts run_embedded()
and exchanges JSON-RPC strings with its editor. The host reads the response to
initialize to discover which capabilities this server advertises.
Reading and writing. Completion and item resolution, hover, Signature Help, document symbols and highlights, folding, and full-document semantic tokens are available. Embedded hosts use full token requests for semantic highlighting.
Navigation and editing. Go to Definition, Find References, and Rename use open documents in the same workspace folder. A client can negotiate generated read-only package definitions and Prepare Rename. A rename that could affect closed files needs client support for confirming an annotated open-document edit.
Diagnostics. The client requests syntax diagnostics with
textDocument/diagnostic. When lintr is available and selected, the server also checks infix spacing. Following a change to the effective diagnostics configuration, a client that supports refresh can receiveworkspace/diagnostic/refresh.Formatting. With styler installed, the host can request whole-document formatting. For workspace indexing, call or type hierarchy, code actions, and additional formatting modes, use the workspace server.
Embedded hosts and webR shows a complete exchange and how to share a separate R session's package search order.
How does the editor keep results up to date?
Open buffers. The editor sends
textDocument/didOpen, incrementaltextDocument/didChange,textDocument/didSave, andtextDocument/didClose. Positions use UTF-16. The server reads unsaved text for completion and navigation and drops superseded work after edits.Projects. Adding or removing a workspace folder sends
workspace/didChangeWorkspaceFolders. Changes to watched files arrive throughworkspace/didChangeWatchedFiles. The server uses these to update project information and lint or formatter configuration. Clients supporting work-done progress can display indexing updates throughwindow/workDoneProgress/createand$/progress. Workspace indexingSettings. The editor sends
workspace/didChangeConfigurationwhen its settings change. For clients supporting dynamic registration, the server usesclient/registerCapabilityandclient/unregisterCapabilityto update the available formatting commands. If a selected backend is unavailable,window/showMessagecan display the reason. Server settingsSession. The editor and server negotiate capabilities with
initializeandinitialized. Clients can cancel a pending request with$/cancelRequest, change protocol tracing with$/setTrace, and end a session withshutdownandexit. Collect a server log
Why can two editors show different results?
Installed package source. Go to Definition can show a generated function body when a definition has no source location. An editor supporting LSP text document content can open it as a read-only virtual document and refresh it. Other clients receive a generated temporary file. Editing that copy has no effect on the installed function.
Formatting commands. With dynamic registration the editor can update its formatting commands when the backend changes. A client with static capabilities learns the available modes when it starts. For that client, set the formatting backend in the server's R profile and restart it. Available formatting modes
Refactoring help. Editors supporting both code-action documentation and opening a URL can show a documentation link in the refactoring menu. Navigation and refactoring
Glue highlighting. An editor that supports
workspace/semanticTokens/refreshcan recolor already-open documents when you change glue highlighting settings. Glue templates
Override an advertised capability
If another tool already supplies a feature, set the corresponding capability in the R
profile read at server startup. For example, to leave Go to Definition to another
provider, add this to .Rprofile and restart the server.
The server's response to initialize shows the capabilities enabled for that client.