Learn R Programming

⚠️There's a newer version (0.3.16) of this package.Take me there.

languageserver: An implementation of the Language Server Protocol for R

languageserver is an implement of the Microsoft's Language Server Protocol for the language of R.

It is released on CRAN and can be easily installed by

install.packages("languageserver")

The development version of languageserver could be installed by running the following in R

source("https://install-github.me/REditorSupport/languageserver")

Rmarkdown

The R package knitr is required to enable languageserver for Rmarkdown files. languageserver doesn't specify knitr as a dependency however, users may need to install it manually.

Language Clients

These editors are supported by installing the corresponding package.

let g:LanguageClient_serverCommands = {
    \ 'r': ['R', '--slave', '-e', 'languageserver::run()'],
    \ }
(lsp-register-client
    (make-lsp-client :new-connection
        (lsp-stdio-connection '("R" "--slave" "-e" "languageserver::run()"))
        :major-modes '(ess-r-mode inferior-ess-r-mode)
        :server-id 'lsp-R))

Services Implemented

languageserver is still under active development, the following services have been implemented:

  • textDocumentSync (diagnostics)
  • hoverProvider
  • completionProvider
  • signatureHelpProvider
  • definitionProvider
  • referencesProvider
  • documentHighlightProvider
  • documentSymbolProvider
  • workspaceSymbolProvider
  • codeActionProvider
  • codeLensProvider
  • documentFormattingProvider
  • documentRangeFormattingProvider
  • documentOnTypeFormattingProvider
  • renameProvider
  • documentLinkProvider
  • executeCommandProvider

Settings

languageserver exposes the following settings via workspace/didChangeConfiguration

{
    "r.lsp.debug": {
      "type": "boolean",
      "default": false,
      "description": "Debug R Language Server"
    },
    "r.lsp.diagnostics": {
      "type": "boolean",
      "default": true,
      "description": "Enable Diagnostics"
    }
}

FAQ

Linters

With lintr v2.0.0, the linters can be specified by creating the .lintr file at the project or home directory. Details can be found at lintr documentation. The option languageserver.default_linters is now deprecated in favor of the .lintr approach.

Customizing formatting style

The language server uses styler to perform code formatting. It uses styler::tidyverse_style(indent_by = options$tabSize) as the default style where options is the formatting options.

The formatting style can be customized by specifying languageserver.formatting_style option which is suppoed to be a function that accepts an options argument mentioned above. You could consider to put the code in .Rprofile.

styler::tidyverse_style provides numerous arguments to customize the formatting behavior. For example, to make it only work at indention scope:

options(languageserver.formatting_style = function(options) {
    styler::tidyverse_style(scope = "indention", indent_by = options$tabSize)
})

To disable assignment operator fix (replacing = with <-):

options(languageserver.formatting_style = function(options) {
    style <- styler::tidyverse_style(indent_by = options$tabSize)
    style$token$force_assignment_op <- NULL
    style
})

To further customize the formatting style, please refer to Customizing styler.

Copy Link

Version

Install

install.packages('languageserver')

Monthly Downloads

15,797

Version

0.3.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Randy Lai

Last Published

October 26th, 2019

Functions in languageserver (0.3.2)

code_lens_params

Parameters for code lens requests
completion_item_resolve

completionItem/resolve request handler
document_symbol_params

Parameters for document symbol requests
reference_params

Parameters for reference requests
document_range_formatting_params

Parameters for document range formatting requests
range_formatting_reply

Format a part of a document
code_point_to_unit

Determinal code units given code points
symbol_information

Non-hierachical symbol information
text_document_code_action

textDocument/codeAction request handler
arg_completion

Complete a function argument
code_lens_resolve

codeLens/resolve request handler
document_uri

A document URI
document_symbol_reply

Get all the symbols in the document
diagnose_file

Run diagnostic on a file
Workspace

A data structure for a session workspace
definition_reply

Get the location of a specified function definition
did_open_text_document_params

Parameters for didOpen notifications
did_save_text_document_params

Parameters for didSave notifications
text_document_on_type_formatting

textDocument/onTypeFormatting request handler
formatting_reply

Format a document
check_scope

Check if a token is in a R code block in an Rmarkdown file
completion_params

Parameters for completion requests
cancel_request

cancel request notification handler
constant_completion

Complete language constants
document_formatting_params

Parameters for document formatting requests
is_directory

Check if a path is a directory
document_link_params

Parameters for document link requests
text_document_position_params

A text document and a position inside that document
text_document_signature_help

textDocument/signatureHelp request handler
content_backward_search

Search backwards in a document content for a specific character
merge_list

Merge two lists
code_action_params

Parameters for code action requests
text_document_type_definition

textDocument/typeDefinition request handler
workspace_execute_command

workspace/executeCommand request handler
workspace_symbol

workspace/symbol request handler
style_file

Style a file
ncodeunit

Calculate character offset based on the protocol
path_from_uri

Paths and uris
style_text

Edit code style
position

A position in a text document
is_package

check if an URI is a package folder
diagnostics

diagnostics
did_change_configuration_params

Parameters for workspace/didChangeConfiguration notifications
document_link_resolve

documentLink/resolve request handler
location

A location inside a resource
document_on_type_formatting_params

Parameters for document on type formatting requests
text_document_document_highlight

textDocument/documentHighlight request handler
text_document_document_color

textDocument/documentColor request handler
did_close_text_document_params

Parameters for didClose notifications
find_config

Find the lintr config file
completion_reply

The response to a textDocument/completion request
did_change_text_document_params

Parameters for didChange notifications
find_package

Find the root package folder
text_edit

A textual edit applicable to a text document
throttle

throttle a function execution
log_write

Write to log
hover_reply

The response to a textDocument/hover Request
on_initialized

initialized handler
sanitize_names

sanitize package objects names
is_rmarkdown

Check if a file is an RMarkdown file
on_shutdown

shutdown request handler
languageserver-package

languageserver: Language Server Protocol
on_exit

exit notification handler
workspace_did_change_configuration

workspace/didChangeConfiguration notification handler
workspace_completion

Complete any object in the workspace
signature_reply

the response to a textDocument/signatureHelp Request
text_document_did_open

textDocument/didOpen notification handler
on_initialize

initialize handler
package_completion

Complete a package name
text_document_code_lens

textDocument/codeLens request handler
text_document_did_save

textDocument/didSave notification handler
parse_document

Parse a document
rename_params

Parameters for rename requests
process_is_detached

check if the current process becomes an orphan
text_document_document_symbol

textDocument/documentSymbol request handler
text_document_color_presentation

textDocument/colorPresentation request handler
text_document_document_link

textDocument/documentLink request handler
stdin_read_line

read a line from stdin
text_document_did_close

textDocument/didClose notification handler
stdin_read_char

read a character from stdin
text_document_did_change

textDocument/didChange notification handler
range

A range in a text document
text_document_references

textDocument/references request handler
text_document_will_save

textDocument/willSave notification handler
text_document_rename

textDocument/rename request handler
workspace_symbol_reply

Get all the symbols in the workspace matching a query
workspace_sync

Determine workspace information for a given file
to_string

Transform any object to a string
will_save_text_document_params

Parameters for willSave notifications
text_document_will_save_wait_until

textDocument/willSaveWaitUntil notification handler
text_document_hover

textDocument/hover request handler
text_document_implementation

textDocument/implementation request handler
workspace_did_change_watched_files

workspace/didChangeWatchedFiles notification handler
run

Run the R language server
text_document_completion

textDocument/completion request handler
workspace_did_change_workspace_folder_params

workspace/didChangeWorkspaceFolders notification handler
text_document_folding_range

textDocument/foldingRange request handler
text_document_definition

textDocument/definition request handler
text_document_formatting

textDocument/formatting request handler
text_document_range_formatting

textDocument/rangeFormatting request handler
text_document_prepare_rename

textDocument/prepareRename request handler
Message

Base Message class
Notification

Notification Message class
Request

Request Message class
ResponseErrorMessage

Response Error Message class
Response

Response Message class
Logger

A basic logger class
Namespace

A data structure for package namespaces
DefinitionCache

A data structure to hold function definition locations
LanguageServer

The language server