Use Positron's active runtime when inserting a code cell#951
Use Positron's active runtime when inserting a code cell#951juliasilge wants to merge 4 commits intomainfrom
Conversation
| cellRanges: vscode.Range[] | ||
| ): Thenable<void>; | ||
|
|
||
| getForegroundSession(): Thenable<LanguageRuntimeSession | undefined>; |
There was a problem hiding this comment.
I'm adding this here to the PositronRuntime interface in along with a minimal LanguageRuntimeSession type.
| // if no language found in document, fall back to Positron's active runtime | ||
| const kSupportedLanguages = ['python', 'r', 'julia', 'ojs', 'sql', 'bash', 'mermaid', 'dot']; | ||
| if (!language) { | ||
| const api = tryAcquirePositronApi() as unknown as PositronApi | undefined; |
There was a problem hiding this comment.
I'm using tryAcquirePositronApi() from @posit-dev/positron here to try to get us moved over to the npm package more, but AFAICT I still have to cast to PositronApi to get typed access to the new method. I feel like we don't quite have the npm package set up perfectly yet to be used in an extension like this one that is supposed to work in both Positron and VS Code.
There was a problem hiding this comment.
I decided this wasn't the right call and changed over in 69f7a7e.
| import * as assert from "assert"; | ||
| import { examplesOutUri, openAndShowExamplesOutTextDocument, WORKSPACE_PATH } from "./test-utils"; | ||
|
|
||
| suite("Insert Code Cell", function () { |
There was a problem hiding this comment.
These tests only test the VS Code behavior, not what would happen in Positron in an empty document. We don't yet have a good way to write tests against Positron APIs.
Closes #480
When using Insert Code Cell in source mode, the extension determines the language for the new cell using a priority chain:
positron.runtime.getForegroundSession()to get the active runtime's language. If it's one of the supported Quarto languages (python,r,julia,ojs,sql,bash,mermaid,dot), that language is used.Steps 1 to 3 all result in the cursor being placed directly inside the new cell (no picker). Step 4 requires the user to make a selection first.
This is a Positron-only improvement; in VS Code, step 3 is skipped and the picker appears for any empty document.