Experimental* custom language server parser hook for
{box}
modules.
This package is an attempt to provide
{box}
-compatibility for {languageserver}
used
in VS Code.
The code is based on initial work by Pavel Demin.
box::use() |
Code completion | Param completion | Tooltip help | As of version | Notes |
---|---|---|---|---|---|
pkg[...] |
✓ | ✓ | ✓ | 0.1.0 | Full support |
pkg[attach_list] |
✓ | ✓ | ✓ | 0.1.0 | Link to documentation |
pkg |
|||||
prefix/mod[...] |
✓ | ✓ | ✓ | 0.1.0 | No documentation |
prefix/mod[attach_list] |
✓ | ✓ | ✓ | 0.1.0 | No documentation |
prefix/mod |
|||||
alias = pkg |
|||||
alias = prefix/mod |
|||||
pkg[alias = fun] |
✓ | ✓ | ✓ | 0.1.0 | No documentation |
prefix/mod[alias = fun] |
✓ | ✓ | ✓ | 0.1.0 | No documentation |
box.lsp
and langaugeserver
(languageserver
is not going to be installed by
default!).NOTE: In Rhino, install
box.lsp
withrhino::pkg_install("box.lsp")
andlanguageserver
withrenv::install("languageserver")
.box.lsp
needs to be added todependencies.R
and stored inrenv.lock
, as it will be used in.Rprofile
. On the other hand, installinglanguageserver
makes sense only if one uses VSCode or Vim, and should be used on the level of the developer’s environment.
box.lsp::use_box_lsp()
to configure your project’s
.Rprofile
file..Rprofile
.Imports
and Suggests
packages
are installed.R_LANGSVR_LOG=./lsp.log
in .Renviron
to start logging.Rprofile
and
.Renviron
.devtools::load_all()
to load all development
functions.box_use_parser()
<- list(
action assign = function(symbol, value) {
cat(paste("ASSIGN: ", symbol, value, "\n"))
},update = function(packages) {
cat(paste("Packages: ", packages, "\n"))
},parse = function(expr) {
cat(paste("Parse: ", expr, "\n"))
}
)
<- c("box::use(stringr, dplyr[alias = filter, mutate], xml2[...])", "filt", "stringr$str_c")
content <- parse(text = content, keep.source = TRUE)
expr box_use_parser(expr[[1]], action)
Lines and characters are index zero.
source("./tests/testthat/helper-utils.R")
<- language_client()
client
<- withr::local_tempfile(fileext = ".R")
temp_file writeLines(
c(
"box::use(stringr[...])",
"str_c",
"str_m"
),
temp_file
)
%>% did_save(temp_file)
client
%>% respond_completion(
client c(1, 5)) temp_file,
tcplspclient
An interactive client for
{languageserver}
.
::pkg_install("milesmcbain/tcplspclient")
pak::install_github("milesmcbain/tcplspclient") devtools
library(tcplspclient)
<- TCPLanguageClient$new(host = "localhost", port = 8888) client
{languageserver}
package repo openCopy
source(".Rprofile") # custom parsers, custom lsp config
# Add `browser()` statements inside `{languageserver}` functions, or
# Add debug breakpoints in the RStudio editor.
::load_all()
devtools# Run `debugonce()`/`debug()` if needed.
run(port = 8888)
# tcp_test.R
::use(stringr[...])
box
str_c
<- list(
some_list aaa = "A",
bbb = "B"
)
$a some_list
# Check connection
$handshake()
client
<- "tcp_test.R"
doc_path
# With every change made to the test document:
$send_notification(
clientmethod = "textDocument/didSave",
params = list(
textDocument = list(uri = languageserver:::path_to_uri(doc_path)),
text = paste0(stringi::stri_read_lines(doc_path), collapse = "\n")
)
)
# To trigger a completion request:
# line and character are index 0
$send_message(
clientmethod = "textDocument/completion",
params = list(
textDocument = list(
uri = languageserver:::path_to_uri(doc_path)
),position = list(line = 2, character = 5)
) )
The interactive debugger runs in Instance B.
If you want to contribute to this project, please submit a regular PR, once you’re done with the new feature or bug fix.
Reporting a bug is also helpful - please use Github issues and describe your problem as detailed as possible.
Appsilon is a Posit (formerly RStudio) Full Service Certified
Partner.
Learn more at appsilon.com.
Get in touch opensource@appsilon.com
Explore the Rhinoverse - a family of R packages built around Rhino!