Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
Use last selected file for running and add errors (#48)
Browse files Browse the repository at this point in the history
PBI: 30304 
Task: 30960, 30393
* Use last selected file for running and add errors

* refactor pr
  • Loading branch information
LukeSlev authored Jul 15, 2019
1 parent 7587497 commit d03a2b2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
3 changes: 2 additions & 1 deletion locales/en/out/constants.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 8 additions & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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")
};
Expand Down
26 changes: 16 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d03a2b2

Please sign in to comment.