Skip to content

Commit

Permalink
feat: Save active editor before running the app
Browse files Browse the repository at this point in the history
  • Loading branch information
gadenbuie committed Aug 23, 2024
1 parent 062579e commit a7ff048
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export async function pyRunApp(): Promise<void> {
return;
}

await saveActiveEditorFile();

const python = await getSelectedPythonInterpreter();
if (!python) {
return;
Expand Down Expand Up @@ -103,6 +105,8 @@ export async function pyDebugApp(): Promise<void> {
return;
}

await saveActiveEditorFile();

const python = await getSelectedPythonInterpreter();
if (!python) {
return;
Expand Down Expand Up @@ -137,6 +141,8 @@ export async function rRunApp(): Promise<void> {
return;
}

await saveActiveEditorFile();

const path = isShinyAppRPart(pathFile) ? path_dirname(pathFile) : pathFile;

const port = await getAppPort("run", "r");
Expand Down Expand Up @@ -332,6 +338,12 @@ function getActiveEditorFile(): string | undefined {
return appPath;
}

async function saveActiveEditorFile(): Promise<void> {
if (vscode.window.activeTextEditor?.document.isDirty) {
await vscode.window.activeTextEditor?.document.save();
}
}

function getExtensionPath(): string | undefined {
const extensionPath =
vscode.extensions.getExtension("Posit.shiny")?.extensionPath;
Expand Down

0 comments on commit a7ff048

Please sign in to comment.