Skip to content

Commit

Permalink
Add box.lsp integration (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
radbasa authored Sep 5, 2024
1 parent 0cc7b57 commit 78dfe9b
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ jobs:
cd RhinoApp
Rscript ../test-build-sass.R
- name: Rprofile should be configured for box.lsp
if: always()
run: |
cd RhinoApp
Rscript ../test-box-lsp.R
- name: test_r() should run testthat tests
if: always()
run: |
Expand Down
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rhino
Title: A Framework for Enterprise Shiny Applications
Version: 1.9.0.9001
Version: 1.9.0.9002
Authors@R:
c(
person("Kamil", "Żyła", role = c("aut", "cre"), email = "[email protected]"),
Expand All @@ -25,6 +25,7 @@ Depends:
Imports:
box (>= 1.1.3),
box.linters (>= 0.10.4),
box.lsp,
cli,
config,
fs,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export(react_component)
export(test_e2e)
export(test_r)
import(box.linters)
import(box.lsp)
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# rhino (development version)

* Integrate `box.lsp` for auto-complete support for `box` modules in VS Code.
* Integrated {box.linters} styling functions to style `box::use()` calls according to the Rhino style guide.
* Added compatibility check for `treesitter` and `treesitter.r` dependencies

Expand Down
5 changes: 5 additions & 0 deletions R/linters.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
# R CMD Check happy.
#' @import box.linters
NULL

# box.lsp is not used in the rhino package. It is used by a rhino app. Need to add this here
# to tell `R CMD Check` or `devtools::check()` we use `box.lsp`
#' @import box.lsp
NULL
2 changes: 2 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Rstudio
SDK
Stylelint
UI
VSCode
Webpack
autoreload
blogpost
Expand Down Expand Up @@ -48,6 +49,7 @@ nodejs
npm
nvm
overridable
parsers
pnpm
preconfigured
renv
Expand Down
7 changes: 7 additions & 0 deletions inst/templates/renv/dot.Rprofile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ if (file.exists("renv")) {

# Allow absolute module imports (relative to the app root).
options(box.path = getwd())

# box.lsp languageserver external hook
options(
languageserver.parser_hooks = list(
"box::use" = box.lsp::box_use_parser
)
)
6 changes: 5 additions & 1 deletion pkgdown/_pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ navbar:
- text: Publish on Hugging Face
href: articles/how-to/publish-on-huggingface.html
- text: -------
- text: User tools
- text: Box-module auto-complete in VSCode
href: articles/how-to/box-lsp.html
- text: -------
- text: Migration guides
- text: Migration to Rhino 1.6
href: articles/how-to/migrate-1-6.html
Expand All @@ -116,7 +120,7 @@ navbar:
href: articles/how-to/migrate-1-8.html
- text: Migration to Rhino 1.9
href: articles/how-to/migrate-1-9.html

faq:
text: FAQ
href: articles/faq.html
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/test-box-lsp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
testthat::expect_false(
is.null(getOption("languageserver.parser_hooks"))
)
23 changes: 23 additions & 0 deletions vignettes/how-to/box-lsp.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: "How-to: Auto-complete in VSCode"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{How-to: Auto-complete in VSCode}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

_Box-module auto-complete only works if one uses VSCode or Vim. It does not have any known adverse effects on RStudio Desktop or Posit Workbench._

# Introduction

Rhino utilizes `{box}` modules to manage large code bases. A disadvantage of `{box}` modules is the lack of syntax auto-complete support in RStudio or VSCode. In VSCode, auto-complete is provided by `{languageserver}` which allows for external parsers. [`{box.lsp}`](https://appsilon.github.io/box.lsp/index.html) is an extension to `{languageserver}` to provide function name and function argument auto-complete support for `{box}` modules. Please refer to the `{box.lsp}` [documentation](https://appsilon.github.io/box.lsp/index.html) for its current capabilities.

# Steps

1. Install `languageserver`: `renv::install("languageserver")`. `languageserver` is a developer tool, it is _not_ advised to add it to `dependencies.R` or to `renv.lock`.
2. If you initialized your Rhino app with version 1.10.0 or later, proceed to step 4.
3. If you are using an existing Rhino app with version < 1.10.0:
1. Install `box.lsp` to project dependencies: `rhino::pkg_install("box.lsp")`.
2. Run [`box.lsp::use_box_lsp()`](https://appsilon.github.io/box.lsp/reference/use_box_lsp.html) to update your project's `.Rprofile` file with `box.lsp` configuration.
4. Restart the R session (restart VSCode) to reload `.Rprofile`.

0 comments on commit 78dfe9b

Please sign in to comment.