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

15,797

Version

0.3.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Randy Lai

Last Published

September 9th, 2019

Functions in languageserver (0.3.0)

LanguageServer

the language server
Message

base Message class
document_symbol_reply

Get all the symbols in the document
range

a range in a text document
text_document_definition

textDocument/definition request handler
on_initialized

initialized handler
document_on_type_formatting_params

parameters for document on type formatting requests
range_formatting_reply

format a part of a document
document_uri

a document URI
on_shutdown

shutdown request handler
definition_reply

Get the location of a specified function definition
cancel_request

cancel request notification handler
code_lens_params

parameters for code lens requests
code_action_params

parameters for code action requests
check_scope

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

parameters for workspace/didChangeConfiguration notifications
diagnostics

diagnostics
code_lens_resolve

codeLens/resolve request handler
document_formatting_params

parameters for document formatting requests
document_backward_search

search backwards in a document for a specific character
is_package

check if an URI is a package folder
Request

Request Message class
text_document_did_change

textDocument/didChange notification handler
did_change_text_document_params

parameters for didChange notifications
did_close_text_document_params

parameters for didClose notifications
languageserver-package

languageserver: Language Server Protocol
is_rmarkdown

check if a file is an RMarkdown file
text_document_formatting

textDocument/formatting request handler
detect_token

detect if position contains a valid token
completion_item_resolve

completionItem/resolve request handler
run

Run the R language server
location

a location inside a resource
document_range_formatting_params

parameters for document range formatting requests
document_symbol_params

parameters for document symbol requests
Response

Response Message class
did_open_text_document_params

parameters for didOpen notifications
detect_closure

detect if the current position is inside a closure
did_save_text_document_params

parameters for didSave notifications
document_line

get the contents of a line
diagnose_file

run diagnostic on a file
document_link_params

parameters for document link requests
text_document_type_definition

textDocument/typeDefinition request handler
workspace_did_change_configuration

workspace/didChangeConfiguration notification handler
text_document_will_save

textDocument/willSave notification handler
text_document_hover

textDocument/hover request handler
workspace_did_change_watched_files

workspace/didChangeWatchedFiles notification handler
completion_params

parameters for completion requests
formatting_reply

format a document
workspace_sync

Determine workspace information for a given file
completion_reply

the response to a textDocument/completion request
detect_function

check if a character vector looks like a function
detect_hover

detect the token at the current position
sanitize_names

sanitize package objects names
text_document_document_symbol

textDocument/documentSymbol request handler
text_document_folding_range

textDocument/foldingRange request handler
find_config

find the lintr config file
getppid

get the parent process pid
hover_reply

the response to a textDocument/hover Request
on_initialize

initialize handler
on_exit

exit notification handler
package_completion

complete a package name
parse_document

parse a document
reference_params

parameters for reference requests
is_directory

check if a filename is a directory
find_package

find the root package folder
path_from_uri

paths and uris
stdin_read_line

read a line from stdin
position

a position in a text document
style_file

style a file
text_document_implementation

textDocument/implementation request handler
text_document_on_type_formatting

textDocument/onTypeFormatting request handler
text_edit

a textual edit applicable to a text document
text_document_will_save_wait_until

textDocument/willSaveWaitUntil notification handler
workspace_symbol

workspace/symbol request handler
workspace_symbol_reply

Get all the symbols in the workspace matching a query
text_document_did_save

textDocument/didSave notification handler
rename_params

parameters for rename requests
stdin_read_char

read a character from stdin
signature_reply

the response to a textDocument/signatureHelp Request
text_document_document_color

textDocument/documentColor request handler
merge_list

replace elements of a list
log_write

write to log
text_document_color_presentation

textDocument/colorPresentation request handler
text_document_completion

textDocument/completion request handler
text_document_code_lens

textDocument/codeLens request handler
text_document_document_link

textDocument/documentLink request handler
text_document_document_highlight

textDocument/documentHighlight request handler
text_document_code_action

textDocument/codeAction request handler
style_text

edit code style
text_document_rename

textDocument/rename request handler
text_document_signature_help

textDocument/signatureHelp request handler
symbol_information

non-hierachical symbol information
text_document_did_close

textDocument/didClose notification handler
will_save_text_document_params

parameters for willSave notifications
text_document_did_open

textDocument/didOpen notification handler
workspace_completion

complete any object in the workspace
text_document_position_params

a text document and a position inside that document
workspace_did_change_workspace_folder_params

workspace/didChangeWorkspaceFolders notification handler
text_document_prepare_rename

textDocument/prepareRename request handler
text_document_range_formatting

textDocument/rangeFormatting request handler
throttle

throttle a function execution
text_document_references

textDocument/references request handler
workspace_execute_command

workspace/executeCommand request handler
to_string

transform any object to a string
Namespace

A data structure for package namespaces
Logger

a basic logger class
ResponseErrorMessage

Response Error Message class
DefinitionCache

A data structure to hold function definition locations
ServerCapabilities

Server capabilities
document_link_resolve

documentLink/resolve request handler
Notification

Notification Message class
Workspace

A data structure for a session workspace
arg_completion

complete a function argument