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

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

16,583

Version

0.2.9

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Randy Lai

Last Published

March 28th, 2019

Functions in languageserver (0.2.9)

Notification

Notification Message class
did_close_text_document_params

parameters for didClose notifications
document_backward_search

search backwards in a document for a specific character
languageserver-package

languageserver: Language Server Protocol
document_formatting_params

parameters for document formatting requests
location

a location inside a resource
package_completion

complete a package name
parse_document

parse a document
stdin_read_line

read a line from stdin
stylize

edit code style
text_document_color_presentation

textDocument/colorPresentation request handler
LanguageServer

the language server
text_document_completion

textDocument/completion request handler
logger

create the logger
completion_item_resolve

completionItem/resolve request handler
completion_params

parameters for completion requests
ServerCapabilities

Server capabilities
detect_token

detect if position contains a valid token
text_document_position_params

a text document and a position inside that document
Workspace

A data structure for a session workspace
text_document_prepare_rename

textDocument/prepareRename request handler
diagnose_file

run diagnostic on a file
completion_reply

the response to a textDocument/completion request
code_lens_params

parameters for code lens requests
document_link_params

parameters for document link requests
range

a range in a text document
document_line

get the contents of a line
Message

base Message class
hover_reply

the response to a textDocument/hover Request
diagnostics

diagnostics
arg_completion

complete a function argument
did_change_configuration_params

parameters for workspace/didChangeConfiguration notifications
Namespace

A data structure for package namespaces
document_range_formatting_params

parameters for document range formatting requests
document_symbol_params

parameters for document symbol requests
cancel_request

cancel request notification handler
detect_closure

detect if the current position is inside a closure
text_document_rename

textDocument/rename request handler
did_open_text_document_params

parameters for didOpen notifications
range_formatting_reply

format a part of a document
did_save_text_document_params

parameters for didSave notifications
detect_function

check if a character vector looks like a function
code_lens_resolve

codeLens/resolve request handler
find_config

find the lintr config file
is_directory

check if a filename is a directory
text_document_signature_help

textDocument/signatureHelp request handler
workspace_did_change_configuration

workspace/didChangeConfiguration notification handler
path_from_uri

paths and uris
signature_reply

the response to a textDocument/signatureHelp Request
workspace_did_change_watched_files

workspace/didChangeWatchedFiles notification handler
Response

Response Message class
stdin_read_char

read a character from stdin
text_document_did_close

textDocument/didClose notification handler
position

a position in a text document
find_package

find the root package folder
ResponseErrorMessage

Response Error Message class
text_document_definition

textDocument/definition request handler
check_scope

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

textDocument/didOpen notification handler
is_package

check if an URI is a package folder
is_rmarkdown

check if a file is an RMarkdown file
text_document_did_change

textDocument/didChange notification handler
text_document_range_formatting

textDocument/rangeFormatting request handler
text_document_formatting

textDocument/formatting request handler
reference_params

parameters for reference requests
detect_hover

detect the token at the current position
text_document_hover

textDocument/hover request handler
formatting_reply

format a document
code_action_params

parameters for code action requests
getppid

get the parent process pid
text_document_references

textDocument/references request handler
on_initialized

initialized handler
document_link_resolve

documentLink/resolve request handler
rename_params

parameters for rename requests
text_document_did_save

textDocument/didSave notification handler
text_document_document_color

textDocument/documentColor request handler
text_document_implementation

textDocument/implementation request handler
text_document_type_definition

textDocument/typeDefinition request handler
on_shutdown

shutdown request handler
document_on_type_formatting_params

parameters for document on type formatting requests
text_document_on_type_formatting

textDocument/onTypeFormatting request handler
text_document_code_action

textDocument/codeAction request handler
will_save_text_document_params

parameters for willSave notifications
text_document_code_lens

textDocument/codeLens request handler
workspace_completion

complete any object in the workspace
log_write

write to log
merge_list

replace elements of a list
text_document_document_highlight

textDocument/documentHighlight request handler
text_document_document_link

textDocument/documentLink request handler
text_document_will_save

textDocument/willSave notification handler
text_document_document_symbol

textDocument/documentSymbol request handler
text_edit

a textual edit applicable to a text document
text_document_will_save_wait_until

textDocument/willSaveWaitUntil notification handler
text_document_folding_range

textDocument/foldingRange request handler
workspace_symbol

workspace/symbol request handler
workspace_sync

Determine workspace information for a given file
on_exit

exit notification handler
on_initialize

initialize handler
run

Run the R language server
sanitize_names

sanitize package objects names
throttle

throttle a function execution
to_string

transform any object to a string
workspace_did_change_workspace_folder_params

workspace/didChangeWorkspaceFolders notification handler
workspace_execute_command

workspace/executeCommand request handler
Request

Request Message class
did_change_text_document_params

parameters for didChange notifications