Skip to content

Commit

Permalink
Merge branch 'main' into update-vscode-ext-formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
juliasilge authored Oct 28, 2024
2 parents 7e8109e + 7d1582d commit 2896aec
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 2 additions & 0 deletions apps/vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 1.117.0 (unreleased)

- Improved statement execution for Python `.qmd` files in Positron (<https://github.com/quarto-dev/quarto/pull/589>)

## 1.116.0 (Release on 2024-10-08)

- Fix issue with raw html blocks being removed from document by Visual Editor (<https://github.com/quarto-dev/quarto/issues/552>)
Expand Down
13 changes: 10 additions & 3 deletions apps/vscode/src/host/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import { ExtensionHost, HostWebviewPanel, HostStatementRangeProvider } from '.';
import { CellExecutor, cellExecutorForLanguage, executableLanguages, isKnitrDocument, pythonWithReticulate } from './executors';
import { ExecuteQueue } from './execute-queue';
import { MarkdownEngine } from '../markdown/engine';
import { virtualDoc, virtualDocUri, adjustedPosition } from "../vdoc/vdoc";
import { virtualDoc, virtualDocUri, adjustedPosition, unadjustedRange } from "../vdoc/vdoc";
import { EmbeddedLanguage } from '../vdoc/languages';

declare global {
function acquirePositronApi(): hooks.PositronApi;
Expand Down Expand Up @@ -155,7 +156,11 @@ class EmbeddedStatementRangeProvider implements HostStatementRangeProvider {
if (vdoc) {
const vdocUri = await virtualDocUri(vdoc, document.uri, "statementRange");
try {
return getStatementRange(vdocUri.uri, adjustedPosition(vdoc.language, position));
return getStatementRange(
vdocUri.uri,
adjustedPosition(vdoc.language, position),
vdoc.language
);
} catch (error) {
return undefined;
} finally {
Expand All @@ -172,10 +177,12 @@ class EmbeddedStatementRangeProvider implements HostStatementRangeProvider {
async function getStatementRange(
uri: vscode.Uri,
position: vscode.Position,
language: EmbeddedLanguage
) {
return await vscode.commands.executeCommand<hooks.StatementRange>(
const result = await vscode.commands.executeCommand<hooks.StatementRange>(
"vscode.executeStatementRangeProvider",
uri,
position
);
return { range: unadjustedRange(language, result.range), code: result.code };
}
18 changes: 12 additions & 6 deletions apps/vscode/src/providers/cell/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
executeSelectionInteractive,
} from "./executors";
import { ExtensionHost } from "../../host";
import { hasHooks } from "../../host/hooks";
import { isKnitrDocument } from "../../host/executors";
import { commands } from "vscode";

Expand Down Expand Up @@ -281,18 +282,23 @@ class RunCurrentCommand extends RunCommand implements Command {
const language = languageNameFromBlock(block);
const executor = await this.cellExecutorForLanguage(language, editor.document, this.engine_);
if (executor && isExecutableLanguageBlock(block)) {

// if the selection is empty and this isn't a knitr document then it resolves to run cell
if (editor.selection.isEmpty && !isKnitrDocument(editor.document, this.engine_) && !this.runSelection_) {

// Resolve this command to "run cell" when we can't find a selection:
// - the selection is empty
// - this is not a knitr document
// - this is not a Python or R document being used in Positron
const resolveToRunCell = editor.selection.isEmpty &&
!this.runSelection_ &&
!isKnitrDocument(editor.document, this.engine_) &&
(!hasHooks() && (language === "python" || language === "r"));

if (resolveToRunCell) {
const code = codeWithoutOptionsFromBlock(block);
await executeInteractive(executor, [code], editor.document);

} else {
// submit
const executed = await executeSelectionInteractive(executor);

// if the executor isn't capable of lenguage aware runSelection
// if the executor isn't capable of language aware runSelection
// then determine the selection manually
if (!executed) {
// if the selection is empty take the whole line, otherwise
Expand Down

0 comments on commit 2896aec

Please sign in to comment.