-
Notifications
You must be signed in to change notification settings - Fork 55
Use Positron's active runtime when inserting a code cell #951
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
Open
juliasilge
wants to merge
4
commits into
main
Choose a base branch
from
positron-active-runtime-insert-code-cell
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+117
−2
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import * as vscode from "vscode"; | ||
| import * as assert from "assert"; | ||
| import { examplesOutUri, openAndShowExamplesOutTextDocument, WORKSPACE_PATH } from "./test-utils"; | ||
|
|
||
| suite("Insert Code Cell", function () { | ||
|
Collaborator
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. 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. |
||
| suiteSetup(async function () { | ||
| await vscode.workspace.fs.delete(examplesOutUri(), { recursive: true }); | ||
| await vscode.workspace.fs.copy(vscode.Uri.file(WORKSPACE_PATH), examplesOutUri()); | ||
| }); | ||
|
|
||
| teardown(async function () { | ||
| await vscode.commands.executeCommand("undo"); | ||
| }); | ||
|
|
||
| // format/basics.qmd (0-indexed lines): | ||
| // 9: ```{python} | ||
| // 10: x = 1 + 1 <- inside python block | ||
| // 11: ``` | ||
| // 13: More markdown text. <- between blocks | ||
| // 15: ```{r} | ||
| // 16: y <- 1 + 1 <- inside r block | ||
| // 17: ``` | ||
| // 19: Final line. <- after all blocks | ||
| // 7: Some regular text here. <- before all blocks | ||
|
|
||
| suite("Language from cursor context", function () { | ||
| test("Uses language of block when cursor is inside a Python block", async function () { | ||
| const { doc, editor } = await openAndShowExamplesOutTextDocument("format/basics.qmd"); | ||
| const before = countOccurrences(doc.getText(), "```{python}"); | ||
|
|
||
| editor.selection = new vscode.Selection(10, 0, 10, 0); | ||
| await vscode.commands.executeCommand("quarto.insertCodeCell"); | ||
|
|
||
| assert.strictEqual(countOccurrences(doc.getText(), "```{python}"), before + 1); | ||
| }); | ||
|
|
||
| test("Uses language of block when cursor is inside an R block", async function () { | ||
| const { doc, editor } = await openAndShowExamplesOutTextDocument("format/basics.qmd"); | ||
| const before = countOccurrences(doc.getText(), "```{r}"); | ||
|
|
||
| editor.selection = new vscode.Selection(16, 0, 16, 0); | ||
| await vscode.commands.executeCommand("quarto.insertCodeCell"); | ||
|
|
||
| assert.strictEqual(countOccurrences(doc.getText(), "```{r}"), before + 1); | ||
| }); | ||
|
|
||
| test("Uses language of nearest preceding block when cursor is between blocks", async function () { | ||
| const { doc, editor } = await openAndShowExamplesOutTextDocument("format/basics.qmd"); | ||
| const before = countOccurrences(doc.getText(), "```{python}"); | ||
|
|
||
| editor.selection = new vscode.Selection(13, 0, 13, 0); | ||
| await vscode.commands.executeCommand("quarto.insertCodeCell"); | ||
|
|
||
| assert.strictEqual(countOccurrences(doc.getText(), "```{python}"), before + 1); | ||
| }); | ||
|
|
||
| test("Uses language of first following block when cursor precedes all blocks", async function () { | ||
| const { doc, editor } = await openAndShowExamplesOutTextDocument("format/basics.qmd"); | ||
| const before = countOccurrences(doc.getText(), "```{python}"); | ||
|
|
||
| editor.selection = new vscode.Selection(7, 0, 7, 0); | ||
| await vscode.commands.executeCommand("quarto.insertCodeCell"); | ||
|
|
||
| assert.strictEqual(countOccurrences(doc.getText(), "```{python}"), before + 1); | ||
| }); | ||
|
|
||
| test("Uses language of last block when cursor follows all blocks", async function () { | ||
| const { doc, editor } = await openAndShowExamplesOutTextDocument("format/basics.qmd"); | ||
| const before = countOccurrences(doc.getText(), "```{r}"); | ||
|
|
||
| editor.selection = new vscode.Selection(19, 0, 19, 0); | ||
| await vscode.commands.executeCommand("quarto.insertCodeCell"); | ||
|
|
||
| assert.strictEqual(countOccurrences(doc.getText(), "```{r}"), before + 1); | ||
| }); | ||
| }); | ||
|
|
||
| suite("Language picker fallback", function () { | ||
| test("Inserts a code fence when document has no executable code cells", async function () { | ||
| const content = "---\ntitle: Test\n---\n\nJust some markdown.\n"; | ||
| const uri = examplesOutUri("insert-test-empty.qmd"); | ||
| await vscode.workspace.fs.writeFile(uri, Buffer.from(content, "utf8") as Uint8Array); | ||
|
|
||
| const doc = await vscode.workspace.openTextDocument(uri); | ||
| const editor = await vscode.window.showTextDocument(doc); | ||
| editor.selection = new vscode.Selection(4, 0, 4, 0); | ||
| await vscode.commands.executeCommand("quarto.insertCodeCell"); | ||
|
|
||
| assert.ok(doc.getText().includes("```{")); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| function countOccurrences(text: string, substring: string): number { | ||
| return text.split(substring).length - 1; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm adding this here to the
PositronRuntimeinterface in along with a minimalLanguageRuntimeSessiontype.