A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/Appsilon/box.lsp below:

Appsilon/box.lsp: Custom language server parser for box modules

box.lsp

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

  1. Install box.lsp and langaugeserver (languageserver is not going to be installed by default!).

NOTE: In Rhino, install box.lsp with rhino::pkg_install("box.lsp") and languageserver with renv::install("languageserver"). box.lsp needs to be added to dependencies.R and stored in renv.lock, as it will be used in .Rprofile. On the other hand, installing languageserver makes sense only if one uses VSCode or Vim, and should be used on the level of the developer's environment.

  1. box.lsp::use_box_lsp() to configure your project's .Rprofile file.
  2. Restart the R session to load .Rprofile.
  1. Ensure all Imports and Suggests packages are installed.
  2. Set R_LANGSVR_LOG=./lsp.log in .Renviron to start logging
  3. Restart R session to load .Rprofile and .Renviron.
  4. devtools::load_all() to load all development functions.
Development work on box_use_parser()
action <- list(
  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"))
  }
)

content <- c("box::use(stringr, dplyr[alias = filter, mutate], xml2[...])", "filt", "stringr$str_c")
expr <- parse(text = content, keep.source = TRUE)
box_use_parser(expr[[1]], action)

Lines and characters are index zero.

source("./tests/testthat/helper-utils.R")
client <- language_client()

temp_file <- withr::local_tempfile(fileext = ".R")
writeLines(
  c(
    "box::use(stringr[...])",
    "str_c",
    "str_m"
  ),
  temp_file
)

client %>% did_save(temp_file)

client %>% respond_completion(
  temp_file, c(1, 5))
Development and Debugging using TCP LSP Client

An interactive client for {languageserver}.

pak::pkg_install("milesmcbain/tcplspclient")
devtools::install_github("milesmcbain/tcplspclient")
library(tcplspclient)
client <- TCPLanguageClient$new(host = "localhost", port = 8888)
On Instance B with {languageserver} package repo open

Copy

source(".Rprofile")  # custom parsers, custom lsp config
# Add `browser()` statements inside `{languageserver}` functions, or
# Add debug breakpoints in the RStudio editor.
devtools::load_all()
# Run `debugonce()`/`debug()` if needed.
run(port = 8888)
# tcp_test.R
box::use(stringr[...])

str_c

some_list <- list(
  aaa = "A",
  bbb = "B"
)

some_list$a
# Check connection
client$handshake()

doc_path <- "tcp_test.R"

# With every change made to the test document:
client$send_notification(
  method = "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
client$send_message(
  method = "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!


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4