-
Notifications
You must be signed in to change notification settings - Fork 101
R: approach snippets in a more conventional VS Code way #7234
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
Comments
The official docs for snippets clarify the
|
The Python extension contributes only 2 snippets, which is consistent with my hunch that perhaps positron-r / ark should provide no snippets (or almost none?): positron/extensions/positron-python/snippets/python.code-snippets Lines 1 to 12 in 6e40bda
|
It would be great to see support for snippets with executable R code similar to RStudio. As an example, snippets in RStudio allow expressions like |
Since I'm advocating for the removal of built-in R snippets, that doesn't bode well for a feature request for even more capable R snippets. I just want to note that VS Code and, therefore, Positron offer another snippet-y way of doing things like "insert the current date", e.g.: https://mattferderer.com/create-a-snippet-or-shortcut-in-vs-code-to-insert-the-current-date-time I think this is a great example of the benefits of building on VS Code: we get a lot of features "for free" and this could be one of them. |
If we remove built-in snippets from ark, we could still shape the user's experience of configuring R snippets by providing some examples. Here's where the content of a bare language-specific snippet file lives: positron/src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts Lines 202 to 224 in 6af5bd8
Currently, the selected language just gets inserted for the |
This appears to be the landscape for user-defined snippet files:
|
Part of #7234 In posit-dev/ark#782, I remove the so-called snippet source of completions in ark. Previously, the completions coming from the snippet source were a mix of snippets related to R reserved words (such as `if`, `while`, or `for`) and a collection of other snippets relating to various functions in base R (such as `matrix()` or `lapply()`). This was an eclectic mix of snippets inherited from RStudio. After [#782](posit-dev/ark#782), completion handling for reserved words lives with ark's keyword source. The usual snippets still appear (or do not), in the same contexts, just via a different internal mechanism. Functions like `matrix()` or `lapply()`, however, no longer have special handling and receive the same completion treatment as any other function on the search path. If users want such snippets, we're going to follow the existing VS Code vibe, which is to recommend that the user configure custom snippets, via the command palette and *Snippets: Configure Snippets*: <img width="218" alt="Screenshot 2025-04-25 at 3 34 23 PM" src="https://github.com/user-attachments/assets/0b167aec-5ae8-4798-843f-4691027842fb" /> A newly created snippet file using this interface is pre-populated with a big comment that explains what sort of content to place in the file. Snippet files comes in 2 main flavors: * "global": contains snippets that are not limited to one language. Individual snippets in such a global file can have a `scope` which specifies one or more languages. Created via `createSnippetFile()`. <img width="607" alt="Screenshot 2025-04-25 at 3 38 00 PM" src="https://github.com/user-attachments/assets/b2c039a3-65dc-451a-9b3a-fd162d08e537" /> * language-specific: contains snippets for one specific language. Created via `createLanguageSnippetFile()`. <img width="301" alt="Screenshot 2025-04-25 at 3 45 05 PM" src="https://github.com/user-attachments/assets/facb30ca-4e20-4c84-8741-68fe30e235f7" /> This PR modifies the placeholder content for both functions. The main idea is to give examples for R and Python, instead of javascript/typescript. This PR is similar in spirit to other changes we've made to make default or example content more data science / R / Python oriented. The mechanics are pretty bone-headed, but that is motivated by our overlay strategy and making things as easy as possible for upstream merges. *I plan to complement this PR with a companion PR to the website aimed at helping snippet users coming from RStudio.*
For posit-dev/ark#782 Addresses #7234 Addresses #3108 ### Release Notes #### New Features - R snippets are now handled in the conventional way for VS Code, i.e. via optional `.code-snippets` files at the user or workspace level or an R-specific `r.json` file. Newly configured snippet files contain examples for R and Python. The only R snippets that remain built-in are those relating to reserved words (#7234). #### Bug Fixes - It is now possible to get completions via `?` for functions, e.g., in the `apply()` family or for `switch()` (#3108). ### QA Notes <!-- Add additional information for QA on how to validate the change, paying special attention to the level of risk, adjacent areas that could be affected by the change, and any important contextual information not present in the linked issues. -->
QA Notes: Relevant instructions have been newly added to the docs: https://positron.posit.co/r-snippets.html Ideas for verification:
|
Verified Fixed
Test scenario(s)Tried all types of snippets and everything looks good. Link(s) to TestRail test cases run or created: |
Uh oh!
There was an error while loading. Please reload this page.
Currently ark provides, unconditionally, a fixed set of R snippets:
https://github.com/posit-dev/ark/blob/main/crates/ark/resources/snippets/r.code-snippets
Thoughts about how to improve this area:
.code-snippets
file (more below). These snippets appear to be combined with the snippet completions coming from the LSP. I can confirm that if you use"r"
as the scope, these snippets are thrown into the mix along with those coming from ark.Here is the initial content of a snippet file initiated with VS Code / Positron:
Issue inspired by #7101 and general work on R completions.
The text was updated successfully, but these errors were encountered: