Skip to content

R: approach snippets in a more conventional VS Code way #7234

@jennybc

Description

@jennybc

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:

  • The existing snippets were ported from RStudio and, to some of us, contain a rather peculiar set of snippets. It feels like we might be on autopilot, maintaining something created a long time ago, without re-examining and curating it? I don't think these would be the top snippets we'd create if we were starting from scratch. Also the completion landscape has changed dramatically since these snippets were created, now that we've got a true LSP and also given code completion from LLMs.
  • There's no way to turn the built-in ark snippets off. So there's no recourse if you find them to be a net negative to your completion life. And they do tend to show up near the top of the list, conceivably squatting on the coveted top spot.
  • In RStudio, you either get the default snippets or your custom snippets. There is no combining of them. If you want custom snippets AND you like some of the default snippets, you copy those defaults into your custom snippets. We should at least consider this design for Positron as well. What I mostly mean is: maybe we should get out of the snippet business entirely, but we help people to develop their own custom snippets. For example, by providing some great example content when the user first start their own snippet file.
    • Personally, I never use any of the snippets that ark is currently providing and anecdotally this is also true for various colleagues I consulted. Instead, those of us who use snippets use custom ones we've created for ourselves.
  • Currently, it is possible to augment the built-in snippets by using a VS Code mechanism. The entry point is Snippets: Configure Snippets in the command palette. That allows snippet customization at the user or workspace level, via a dedicated .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:

{
	// Place your r_testing workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and 
	// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope 
	// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is 
	// used to trigger the snippet and the body will be expanded and inserted. Possible variables are: 
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. 
	// Placeholders with the same ids are connected.
	// Example:
	// "Print to console": {
	// 	"scope": "javascript,typescript",
	// 	"prefix": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
	// }
}

Issue inspired by #7101 and general work on R completions.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions