Skip to content

Commit

Permalink
feat: Save active editor before running the app (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
gadenbuie authored Aug 23, 2024
1 parent dc85119 commit ad45e4b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- Improved feedback when waiting for a slow Shiny app to start up. ([#65](https://github.com/posit-dev/shiny-vscode/pull/65))

- The "Run Shiny app" command now saves the active file before running the app. ([#68](https://github.com/posit-dev/shiny-vscode/pull/68))

- The extension can now open Shinylive apps locally from `vscode://posit.shiny/shinylive?url=...` links. ([#70](https://github.com/posit-dev/shiny-vscode/pull/70))

## 1.0.0
Expand Down
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 ad45e4b

Please sign in to comment.