From ced67aa0a7c74a701a4f8c4d491fd8b29bbe72ff Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Tue, 30 Apr 2024 22:21:30 -0400 Subject: [PATCH] fix(createFromActiveEditor): don't require a saved file for --- src/shinylive.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/shinylive.ts b/src/shinylive.ts index d5edee3..ed5f94f 100644 --- a/src/shinylive.ts +++ b/src/shinylive.ts @@ -37,8 +37,11 @@ export async function shinyliveCreateFromActiveEditor(): Promise { } 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( @@ -47,13 +50,15 @@ export async function shinyliveCreateFromActiveEditor(): Promise { 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";