From 78dfe9b1d8ecf739871d5a6717a26ec27d420f8e Mon Sep 17 00:00:00 2001 From: Ricardo Rodrigo Basa Date: Thu, 5 Sep 2024 16:02:57 +0800 Subject: [PATCH] Add box.lsp integration (#612) --- .github/workflows/e2e-test.yml | 6 ++++++ DESCRIPTION | 3 ++- NAMESPACE | 1 + NEWS.md | 1 + R/linters.R | 5 +++++ inst/WORDLIST | 2 ++ inst/templates/renv/dot.Rprofile | 7 +++++++ pkgdown/_pkgdown.yml | 6 +++++- tests/e2e/test-box-lsp.R | 3 +++ vignettes/how-to/box-lsp.Rmd | 23 +++++++++++++++++++++++ 10 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 tests/e2e/test-box-lsp.R create mode 100644 vignettes/how-to/box-lsp.Rmd diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index a30f9e68..52463fa0 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -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: | diff --git a/DESCRIPTION b/DESCRIPTION index d02db3f4..49566328 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 = "opensource+kamil@appsilon.com"), @@ -25,6 +25,7 @@ Depends: Imports: box (>= 1.1.3), box.linters (>= 0.10.4), + box.lsp, cli, config, fs, diff --git a/NAMESPACE b/NAMESPACE index 35179f92..3378e8db 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -18,3 +18,4 @@ export(react_component) export(test_e2e) export(test_r) import(box.linters) +import(box.lsp) diff --git a/NEWS.md b/NEWS.md index 74acf05e..3b3ff5dd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/linters.R b/R/linters.R index ad8e83e4..9465196d 100644 --- a/R/linters.R +++ b/R/linters.R @@ -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 diff --git a/inst/WORDLIST b/inst/WORDLIST index e5e95036..ed5a79f0 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -19,6 +19,7 @@ Rstudio SDK Stylelint UI +VSCode Webpack autoreload blogpost @@ -48,6 +49,7 @@ nodejs npm nvm overridable +parsers pnpm preconfigured renv diff --git a/inst/templates/renv/dot.Rprofile b/inst/templates/renv/dot.Rprofile index 3b081a1c..752a6e32 100644 --- a/inst/templates/renv/dot.Rprofile +++ b/inst/templates/renv/dot.Rprofile @@ -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 + ) +) diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index 1623bb05..57c93f8a 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -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 @@ -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 diff --git a/tests/e2e/test-box-lsp.R b/tests/e2e/test-box-lsp.R new file mode 100644 index 00000000..c00a3bb2 --- /dev/null +++ b/tests/e2e/test-box-lsp.R @@ -0,0 +1,3 @@ +testthat::expect_false( + is.null(getOption("languageserver.parser_hooks")) +) diff --git a/vignettes/how-to/box-lsp.Rmd b/vignettes/how-to/box-lsp.Rmd new file mode 100644 index 00000000..a7ecc609 --- /dev/null +++ b/vignettes/how-to/box-lsp.Rmd @@ -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`.