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 master branch, the linters can be specified by creating the .lintr file at the project or home directory. Details can be found at lintr documentation.

Until a new version of lintr is released, you could consider the following settings in .Rprofile:

setHook(
    packageEvent("languageserver", "onLoad"),
    function(...) {
        options(languageserver.default_linters = lintr::with_defaults(
            line_length_linter = lintr::line_length_linter(100),
            object_usage_linter = NULL
        ))
    }
)

Copy Link

Version

Install

install.packages('languageserver')

Monthly Downloads

15,797

Version

0.3.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Randy Lai

Last Published

September 27th, 2019

Functions in languageserver (0.3.1)

did_change_configuration_params

parameters for workspace/didChangeConfiguration notifications
is_directory

check if a filename is a directory
hover_reply

the response to a textDocument/hover Request
ResponseErrorMessage

Response Error Message class
content_backward_search

search backwards in a document content for a specific character
completion_params

parameters for completion requests
parse_document

parse a document
definition_reply

Get the location of a specified function definition
ServerCapabilities

Server capabilities
completion_reply

the response to a textDocument/completion request
code_lens_params

parameters for code lens requests
document_symbol_params

parameters for document symbol requests
did_change_text_document_params

parameters for didChange notifications
did_close_text_document_params

parameters for didClose notifications
check_scope

check if a token is in a R code block in an Rmarkdown file
LanguageServer

the language server
code_action_params

parameters for code action requests
did_open_text_document_params

parameters for didOpen notifications
document_link_resolve

documentLink/resolve request handler
document_link_params

parameters for document link requests
path_from_uri

paths and uris
range

a range in a text document
position

a position in a text document
text_document_did_change

textDocument/didChange notification handler
text_document_did_close

textDocument/didClose notification handler
workspace_symbol

workspace/symbol request handler
text_document_folding_range

textDocument/foldingRange request handler
text_document_formatting

textDocument/formatting request handler
text_document_signature_help

textDocument/signatureHelp request handler
text_document_type_definition

textDocument/typeDefinition request handler
Namespace

A data structure for package namespaces
Notification

Notification Message class
languageserver-package

languageserver: Language Server Protocol
did_save_text_document_params

parameters for didSave notifications
location

a location inside a resource
document_symbol_reply

Get all the symbols in the document
arg_completion

complete a function argument
Workspace

A data structure for a session workspace
document_on_type_formatting_params

parameters for document on type formatting requests
sanitize_names

sanitize package objects names
text_document_completion

textDocument/completion request handler
signature_reply

the response to a textDocument/signatureHelp Request
on_shutdown

shutdown request handler
document_formatting_params

parameters for document formatting requests
text_document_definition

textDocument/definition request handler
package_completion

complete a package name
log_write

write to log
document_range_formatting_params

parameters for document range formatting requests
text_document_document_link

textDocument/documentLink request handler
on_initialize

initialize handler
merge_list

replace elements of a list
on_initialized

initialized handler
code_lens_resolve

codeLens/resolve request handler
style_text

edit code style
diagnose_file

run diagnostic on a file
diagnostics

diagnostics
document_uri

a document URI
style_file

style a file
is_package

check if an URI is a package folder
text_edit

a textual edit applicable to a text document
text_document_document_symbol

textDocument/documentSymbol request handler
is_rmarkdown

check if a file is an RMarkdown file
symbol_information

non-hierachical symbol information
run

Run the R language server
rename_params

parameters for rename requests
workspace_symbol_reply

Get all the symbols in the workspace matching a query
text_document_position_params

a text document and a position inside that document
text_document_on_type_formatting

textDocument/onTypeFormatting request handler
text_document_code_action

textDocument/codeAction request handler
workspace_execute_command

workspace/executeCommand request handler
text_document_implementation

textDocument/implementation request handler
text_document_hover

textDocument/hover request handler
workspace_did_change_workspace_folder_params

workspace/didChangeWorkspaceFolders notification handler
throttle

throttle a function execution
find_config

find the lintr config file
workspace_did_change_configuration

workspace/didChangeConfiguration notification handler
workspace_did_change_watched_files

workspace/didChangeWatchedFiles notification handler
find_package

find the root package folder
range_formatting_reply

format a part of a document
text_document_will_save_wait_until

textDocument/willSaveWaitUntil notification handler
text_document_will_save

textDocument/willSave notification handler
text_document_did_save

textDocument/didSave notification handler
text_document_range_formatting

textDocument/rangeFormatting request handler
workspace_sync

Determine workspace information for a given file
text_document_prepare_rename

textDocument/prepareRename request handler
text_document_did_open

textDocument/didOpen notification handler
reference_params

parameters for reference requests
will_save_text_document_params

parameters for willSave notifications
workspace_completion

complete any object in the workspace
stdin_read_char

read a character from stdin
ncodeunit

calculate character offset based on the protocol
on_exit

exit notification handler
stdin_read_line

read a line from stdin
formatting_reply

format a document
text_document_code_lens

textDocument/codeLens request handler
text_document_references

textDocument/references request handler
text_document_document_color

textDocument/documentColor request handler
text_document_document_highlight

textDocument/documentHighlight request handler
text_document_color_presentation

textDocument/colorPresentation request handler
text_document_rename

textDocument/rename request handler
to_string

transform any object to a string
utf8_to_utf16_code_point

determinal utf16 code points given utf8 code points
DefinitionCache

A data structure to hold function definition locations
Logger

a basic logger class
Request

Request Message class
Response

Response Message class
completion_item_resolve

completionItem/resolve request handler
code_point_to_unit

determinal code units given code points
cancel_request

cancel request notification handler
become_orphan

check if the current process become an orphan
Message

base Message class