Repository navigation
Run cells of any language with a Positron runtime - #1237
michaelmayer2 wants to merge 3 commits into
Conversation
In Positron, only R, Python, Julia and C# cells ran in the console.
Cells for runtimes that other extensions register, such as {sas} from
the SAS extension, got no Run Cell lens, and the run commands did
nothing on them.
Track the languages of registered Positron runtimes and treat them as
executable, running their cells with the same executor as the built-in
languages.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
juliasilge
left a comment
There was a problem hiding this comment.
Thank you for this PR and for the detailed write-up! We're excited to get SAS working well in Positron. 🙌
When inline output is off, the Quarto extension does decide which cells can run, so we do need a change here in this extension. We actually have the same problem for {ggsql} cells as well. For example, with inline output off, Cmd+Enter and the code lenses do nothing for either a ggsql or SAS document.
This PR is not quite the right approach yet for Quarto support, though. Right now, this fills the list from getRegisteredRuntimes() and onDidRegisterRuntime, but a runtime registers only after its extension activates and discovers an interpreter or a profile. For SAS, this occurs only after a connection profile exists. Before that, {sas} cells get no lenses, and the lenses come back only on the next lens refresh. When inline output is on, Positron uses a different source to decide this, the languageRuntimes contribution in the package.json of each extension (hasLanguageRuntimeProvider in runtimeStartup.ts). As a result, the two modes can disagree.
A better approach is to change the source of the language list, so that both modes agree on which cells can run:
- Read the
languageRuntimescontributions in the Quarto extension. CollectpackageJSON.contributes.languageRuntimes[].languageIdfromvscode.extensions.all, and refresh the list onvscode.extensions.onDidChange. This is synchronous, it is available before other extensions activate, and it matches the source that Positron uses for inline output. - Keep the registered runtimes from this PR as a second source, and use the union of the two lists. This covers an extension that registers a runtime but has no manifest entry.
- Test in a Positron dev build with inline output off, with
{ggsql}and{sas}cells. Test the lenses, Run Above, Run Next Cell, and Cmd+Enter.
I logged posit-dev/positron#17432 for us to improve this situation, but this PR doesn't need to wait for that.
For SAS, the SAS extension needs to also add this contribution to its package.json (ggsql already does this):
"contributes": {
"languageRuntimes": [{ "languageId": "sas" }]
}After a Quarto extension release includes this PR, the SAS extension will need to hide the {sas} lenses from posit-dev/positron-sas-extension#163 for that Quarto version. If it doesn't, each {sas} cell will show two Run Cell lenses.
One more item to think through is that right now codeWithoutOptionsFromBlock removes option lines only for languages that use #|. Please make sure that the option lines in {ggsql} cells do not cause errors when they go to the console.
Use the `languageRuntimes` contributions in the extensions' package.json
as the main source of languages whose cells run in a Positron console,
as Positron does for inline output (`hasLanguageRuntimeProvider`), and
keep the registered runtimes as a second source. The contributions are
known before the extensions activate or discover a runtime, so e.g.
`{sas}` cells are runnable before a SAS connection profile exists, and
both modes agree on which cells can run.
Strip the leading option lines of these languages before sending the
code to the console, using each language's own comment characters
(`#|` for ggsql, where `#` isn't a comment, and `*| ...;` for sas). The
matching is shared with cellOptions().
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the careful review! I've reworked the PR along those lines (c75a7a4):
Thanks for logging posit-dev/positron#17432! |
Problem
In Positron with inline output off, Quarto runs cells only for
julia,python,csharpandr, the hard-coded cases incellExecutorForLanguageinsrc/host/positron.ts. Other languages fall back to the static executor list. So cells for runtimes that extensions add, such as{ggsql}(ggsql extension) or{sas}(SAS extension, common through the sasquatch R package), get no Run Cell lens.quarto.runCurrentCelland the other run commands do nothing on them. With inline output on, Positron decides instead, from thelanguageRuntimescontributions (hasLanguageRuntimeProvider), so the two modes disagree.Change
Languages with a Positron runtime (
positron.ts) come from two sources, as inhasLanguageRuntimeProvider:languageRuntimescontributions in thepackage.jsonof the installed extensions (vscode.extensions.all), re-read onvscode.extensions.onDidChange. This read is synchronous and known before those extensions activate or discover a runtime. The parsing is the purecontributedRuntimeLanguages().getRegisteredRuntimes()andonDidRegisterRuntime), for an extension that registers a runtime without the contribution.Both are cached because
hasExecutor()is synchronous. They are filled only in Positron, so VS Code is unaffected even with such extensions installed.The existing Positron executor moves unchanged into
positronRuntimeExecutor(). The built-in languages use it as before, and in thedefault:branch any language with a Positron runtime uses it too.hasExecutor()and the host'sexecutableLanguagesinclude these languages, so lenses, Run Above / Run Next Cell and the shortcuts work for them.Option lines:
codeWithoutOptionsFromBlockalso strips the leading option lines of languages with a Positron runtime, using each language's comment characters fromkLangCommentChars:#|, and its docs use#|too. But#isn't a comment in ggsql (--,//and/* */are), so those lines used to reach the console as code.*| …;.The matching is the one
cellOptions()uses, now shared asleadingOptionYaml(). Languages without a runtime behave as before.Positron's longer-term fix is tracked in posit-dev/positron#17432.
Testing
tsc --noEmitand eslint pass.cellExecutors.test.tspass. In the fullmainsuite, the only failures are 4 Convert.qmd→.ipynbtests, which also fail on this branch's base on my machine.languageRuntimescontribution (Positron: declare the SAS language runtime in the manifest posit-dev/positron-sas-extension#167), and ggsql 0.5.2:{ggsql}and{sas}cells show lenses before any console exists.🤖 Generated with Claude Code