Skip to content

Commit

Permalink
fix(createFromActiveEditor): don't require a saved file for
Browse files Browse the repository at this point in the history
  • Loading branch information
gadenbuie committed May 1, 2024
1 parent 753ff5d commit ced67aa
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/shinylive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ export async function shinyliveCreateFromActiveEditor(): Promise<void> {
}

const content = vscode.window.activeTextEditor.document.getText();
const { fileName: filePath, languageId: language } =
vscode.window.activeTextEditor.document;
const {
fileName: filePath,
languageId: language,
isUntitled,
} = vscode.window.activeTextEditor.document;

if (!language || !["r", "python"].includes(language)) {
vscode.window.showErrorMessage(
Expand All @@ -47,13 +50,15 @@ export async function shinyliveCreateFromActiveEditor(): Promise<void> {
return;
}

const { name: fileName } = path.parse(filePath);
if (!isUntitled) {
const { name: fileName } = path.parse(filePath);

if (!/(^app|app$)/i.test(fileName)) {
vscode.window.showErrorMessage(
"A single-file Shiny app is required when sending the current file to Shinylive."
);
return;
if (!/(^app|app$)/i.test(fileName)) {
vscode.window.showErrorMessage(
"A single-file Shiny app is required when sending the current file to Shinylive."
);
return;
}
}

const extension = language === "r" ? "R" : "py";
Expand Down

0 comments on commit ced67aa

Please sign in to comment.