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

Commit f5fca46

Browse files
committed
Handle active editor undefined
1 parent 0b7e5b4 commit f5fca46

1 file changed

Lines changed: 33 additions & 7 deletions

File tree

src/extension.ts

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import * as cp from "child_process";
55
import * as fs from "fs";
6+
import { registerDefaultFontFaces } from "office-ui-fabric-react";
67
import * as open from "open";
78
import * as os from "os";
89
import * as path from "path";
@@ -25,13 +26,12 @@ import * as utils from "./extension_utils/utils";
2526
import { SerialMonitor } from "./serialMonitor";
2627
import { DebuggerCommunicationService } from "./service/debuggerCommunicationService";
2728
import { MessagingService } from "./service/messagingService";
29+
import { PopupService } from "./service/PopupService";
2830
import { SimulatorDebugConfigurationProvider } from "./simulatorDebugConfigurationProvider";
31+
import getPackageInfo from "./telemetry/getPackageInfo";
2932
import TelemetryAI from "./telemetry/telemetryAI";
3033
import { UsbDetector } from "./usbDetector";
3134
import { VSCODE_MESSAGES_TO_WEBVIEW, WEBVIEW_MESSAGES } from "./view/constants";
32-
import { PopupService } from "./service/PopupService";
33-
import getPackageInfo from "./telemetry/getPackageInfo";
34-
import { registerDefaultFontFaces } from "office-ui-fabric-react";
3535

3636
let currentFileAbsPath: string = "";
3737
let currentTextDocument: vscode.TextDocument;
@@ -453,7 +453,6 @@ export async function activate(context: vscode.ExtensionContext) {
453453
const killProcessIfRunning = () => {
454454
if (childProcess !== undefined) {
455455
if (currentPanel) {
456-
console.info("Sending clearing state command");
457456
currentPanel.webview.postMessage({
458457
command: "reset-state",
459458
active_device: currentActiveDevice,
@@ -510,8 +509,8 @@ export async function activate(context: vscode.ExtensionContext) {
510509

511510
killProcessIfRunning();
512511

513-
await updateCurrentFileIfPython(
514-
vscode.window.activeTextEditor!.document,
512+
await updateCurrentFileFromEditor(
513+
vscode.window.activeTextEditor,
515514
currentPanel
516515
);
517516

@@ -638,7 +637,6 @@ export async function activate(context: vscode.ExtensionContext) {
638637
true
639638
);
640639
if (currentPanel) {
641-
console.log("Sending clearing state command");
642640
currentPanel.webview.postMessage({
643641
active_device: currentActiveDevice,
644642
command: "reset-state",
@@ -1067,6 +1065,34 @@ const getActivePythonFile = () => {
10671065
return activeEditor ? activeEditor.document.fileName : "";
10681066
};
10691067

1068+
const updateCurrentFileFromEditor = async (
1069+
activeTextDocument: vscode.TextEditor | undefined,
1070+
currentPanel: vscode.WebviewPanel
1071+
) => {
1072+
if (
1073+
activeTextDocument &&
1074+
activeTextDocument.document &&
1075+
activeTextDocument.document.languageId === "python"
1076+
) {
1077+
setPathAndSendMessage(
1078+
currentPanel,
1079+
activeTextDocument.document.fileName
1080+
);
1081+
currentTextDocument = activeTextDocument.document;
1082+
} else if (currentFileAbsPath === "") {
1083+
setPathAndSendMessage(currentPanel, getActivePythonFile() || "");
1084+
}
1085+
if (
1086+
currentTextDocument &&
1087+
utils.getActiveEditorFromPath(currentTextDocument.fileName) ===
1088+
undefined
1089+
) {
1090+
await vscode.window.showTextDocument(
1091+
currentTextDocument,
1092+
vscode.ViewColumn.One
1093+
);
1094+
}
1095+
};
10701096
const updateCurrentFileIfPython = async (
10711097
activeTextDocument: vscode.TextDocument | undefined,
10721098
currentPanel: vscode.WebviewPanel

0 commit comments

Comments
 (0)