-
Notifications
You must be signed in to change notification settings - Fork 308
use_air() also turns on "format on save" for qmd + other updates #2136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,5 +24,5 @@ | |
| ^internal$ | ||
| ^revdep-cloud$ | ||
| ^CRAN-SUBMISSION$ | ||
| ^[\.]?air\.toml$ | ||
| ^\.vscode$ | ||
| ^[.]?air[.]toml$ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,11 +13,12 @@ | |
| #' used by the Air extension installed through either VS Code or Positron, see | ||
| #' the Installation section for more details. Specifically it: | ||
| #' | ||
| #' - Sets `editor.formatOnSave = true` for R files to enable formatting on | ||
| #' every save. | ||
| #' - Sets `editor.formatOnSave = true` for R and Quarto files to enable | ||
| #' formatting on every save. | ||
| #' | ||
| #' - Sets `editor.defaultFormatter` to Air for R files to ensure that Air is | ||
| #' always selected as the formatter for this project. | ||
| #' always selected as the formatter for this project. Likewise, sets the | ||
| #' default formatter for Quarto. | ||
| #' | ||
| #' - Sets the Air extension as a "recommended" extension for this project, | ||
| #' which triggers a notification for contributors coming to this project | ||
|
|
@@ -31,20 +32,21 @@ | |
| #' may prefer another editor. | ||
| #' | ||
| #' Note that `use_air()` does not actually invoke Air, it just configures your | ||
| #' project with the recommended settings. Consult the [editors | ||
| #' project with the recommended settings. Consult [Air's editors | ||
| #' guide](https://posit-dev.github.io/air/editors.html) to learn how to invoke | ||
| #' Air in your preferred editor. | ||
| #' | ||
| #' ## Installation | ||
| #' | ||
| #' Note that this setup does not install an Air binary, so there is an | ||
| #' Note that this setup does not install an Air binary, so there may be an | ||
| #' additional manual step you must take before using Air for the first time: | ||
| #' | ||
| #' - For RStudio, follow the [installation | ||
| #' guide](https://posit-dev.github.io/air/editor-rstudio.html). | ||
| #' | ||
| #' - For Positron, install the [OpenVSX | ||
| #' Extension](https://open-vsx.org/extension/posit/air-vscode). | ||
| #' - For Positron, the [Air extension](https://open-vsx.org/extension/posit/air-vscode) | ||
| #' is installed by default and that already includes the Air binary. A typical | ||
| #' Positron user does not need to do anything to install Air. | ||
| #' | ||
| #' - For VS Code, install the [VS Code | ||
| #' Extension](https://marketplace.visualstudio.com/items?itemName=Posit.air-vscode). | ||
|
|
@@ -118,7 +120,7 @@ create_air_toml <- function(ignore = FALSE) { | |
|
|
||
| air_toml_regex <- function() { | ||
| # Pre-escaped regex allowing both `air.toml` and `.air.toml` | ||
| "^[\\.]?air\\.toml$" | ||
| "^[.]?air[.]toml$" | ||
| } | ||
|
|
||
| create_vscode_json_file <- function(name) { | ||
|
|
@@ -142,20 +144,19 @@ create_vscode_json_file <- function(name) { | |
| } | ||
|
|
||
| write_air_vscode_settings_json <- function(path) { | ||
| settings <- jsonlite::read_json(path) | ||
| settings_r <- settings[["[r]"]] | ||
|
|
||
| if (is.null(settings_r)) { | ||
| # Mock it | ||
| settings_r <- set_names(list()) | ||
| } | ||
|
|
||
| # Set these regardless of their previous values. Assume that calling | ||
| # `use_air()` is an explicit request to opt in to these settings. | ||
| settings_r[["editor.formatOnSave"]] <- TRUE | ||
| settings_r[["editor.defaultFormatter"]] <- "Posit.air-vscode" | ||
|
|
||
| settings[["[r]"]] <- settings_r | ||
|
Comment on lines
-145
to
-158
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was a little worried And it looks like it preserves that, so that's a win for
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It really is designed for exactly this. |
||
| settings <- jsonlite::read_json(path) %||% set_names(list()) | ||
|
|
||
| patch <- list( | ||
| `[r]` = list( | ||
| "editor.formatOnSave" = TRUE, | ||
| "editor.defaultFormatter" = "Posit.air-vscode" | ||
| ), | ||
| `[quarto]` = list( | ||
| "editor.formatOnSave" = TRUE, | ||
| "editor.defaultFormatter" = "quarto.quarto" | ||
| ) | ||
| ) | ||
| settings <- utils::modifyList(settings, patch) | ||
|
|
||
| write_vscode_json(x = settings, path = path) | ||
| } | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the
\\.was purposeful. i.e. we have^\.vscode$in our Rbuildignore along with many other\.usage.Unless the
[]does something special, I think we should end up with[\.]as well, otherwise doesn't a lone.mean "anything" or something like that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot tells me they are functionally the same, but
\.is probably more common for escaping a literal., and that seems to align with our existing conventions in.Rbuildignore. Thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[]is commonly used as a less heavy quote syntax for single characters. I like it as it's easier to read.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's perhaps a really small hill to die on, but, yes, I am a big fan of using
[]instead of escaping, when possible. (But yes, you'll see some escaping in usethis because history.) I really don't care deeply about this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The [] is fine