diff --git a/locales/en/out/constants.i18n.json b/locales/en/out/constants.i18n.json index 7ac3a0b1c..06967abcc 100644 --- a/locales/en/out/constants.i18n.json +++ b/locales/en/out/constants.i18n.json @@ -4,7 +4,8 @@ "dialogResponses.help": "I need help", "dialogResponses.tutorials": "Tutorials on Adafruit", "error.noDevice": "No plugged in boards detected. Please double check if your board is connected and/or properly formatted", - "error.stderr": "[ERROR] {0} \n", + "error.noFileToRun": "\n[ERROR] We can't find the .py file to run on simulator. Open up a new .py file, or browse through some examples", + "error.stderr": "\n[ERROR] {0} \n", "error.unexpectedMessage": "Webview sent an unexpected message", "info.deployDevice": "\n[INFO] Deploying code to the device...\n", "info.deploySimulator": "\n[INFO] Deploying code to the simulator...\n", diff --git a/src/constants.ts b/src/constants.ts index 38f30280a..78b3021bb 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -14,8 +14,12 @@ export const CONSTANTS = { "error.noDevice", "No plugged in boards detected. Please double check if your board is connected and/or properly formatted" ), + NO_FILE_TO_RUN: localize( + "error.noFileToRun", + "\n[ERROR] We can't find the .py file to run. Open up a new .py file, or browse through some examples to start with: https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/tree/master/examples" + ), STDERR: (data: string) => { - return localize("error.stderr", `[ERROR] ${data} \n`); + return localize("error.stderr", `\n[ERROR] ${data} \n`); }, UNEXPECTED_MESSAGE: localize( "error.unexpectedMessage", @@ -101,17 +105,17 @@ export enum TelemetryEventName { export enum WebviewMessages { BUTTON_PRESS = "button-press", PLAY_SIMULATOR = "play-simulator" -} +} // tslint:disable-next-line: no-namespace export namespace DialogResponses { export const HELP: MessageItem = { title: localize("dialogResponses.help", "I need help") - }; + }; export const DONT_SHOW: MessageItem = { title: localize("dialogResponses.dontShowAgain", "Don't Show Again") - }; + }; export const TUTORIALS: MessageItem = { title: localize("dialogResponses.tutorials", "Tutorials on Adafruit") }; diff --git a/src/extension.ts b/src/extension.ts index 61785b09a..9ada825c7 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -9,6 +9,7 @@ import * as open from "open"; import TelemetryAI from "./telemetry/telemetryAI"; import { CONSTANTS, DialogResponses, TelemetryEventName, WebviewMessages } from "./constants"; +let currentFileAbsPath: string = ""; // Notification booleans let firstTimeClosed: boolean = true; let shouldShowNewProject: boolean = true; @@ -188,16 +189,16 @@ export function activate(context: vscode.ExtensionContext) { return; } - TelemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_RUN_SIMULATOR); - console.info(CONSTANTS.INFO.RUNNING_CODE); const activeTextEditor: vscode.TextEditor | undefined = vscode.window.activeTextEditor; - let currentFileAbsPath: string = ""; - if (activeTextEditor) { - currentFileAbsPath = activeTextEditor.document.fileName; - } + updateCurrentFileIfPython(activeTextEditor); + + TelemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_RUN_SIMULATOR); + + + if (currentFileAbsPath === "") { logToOutputChannel(outChannel, CONSTANTS.ERROR.NO_FILE_TO_RUN, true); } // Get the Python script path (And the special URI to use with the webview) const onDiskPath = vscode.Uri.file( @@ -286,11 +287,10 @@ export function activate(context: vscode.ExtensionContext) { const activeTextEditor: vscode.TextEditor | undefined = vscode.window.activeTextEditor; - let currentFileAbsPath: string = ""; - if (activeTextEditor) { - currentFileAbsPath = activeTextEditor.document.fileName; - } + updateCurrentFileIfPython(activeTextEditor); + + if (currentFileAbsPath === "") { logToOutputChannel(outChannel, CONSTANTS.ERROR.NO_FILE_TO_RUN, true); } // Get the Python script path (And the special URI to use with the webview) const onDiskPath = vscode.Uri.file( @@ -370,6 +370,12 @@ export function activate(context: vscode.ExtensionContext) { ); } +const updateCurrentFileIfPython = (activeTextEditor: vscode.TextEditor | undefined) => { + if (activeTextEditor && activeTextEditor.document.languageId === "python") { + currentFileAbsPath = activeTextEditor.document.fileName; + } +} + const handleButtonPressTelemetry = (buttonState: any) => { if (buttonState["button_a"] && buttonState["button_b"]) { TelemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_BUTTON_AB);