33
44import * as cp from "child_process" ;
55import * as fs from "fs" ;
6+ import { registerDefaultFontFaces } from "office-ui-fabric-react" ;
67import * as open from "open" ;
78import * as os from "os" ;
89import * as path from "path" ;
@@ -25,13 +26,12 @@ import * as utils from "./extension_utils/utils";
2526import { SerialMonitor } from "./serialMonitor" ;
2627import { DebuggerCommunicationService } from "./service/debuggerCommunicationService" ;
2728import { MessagingService } from "./service/messagingService" ;
29+ import { PopupService } from "./service/PopupService" ;
2830import { SimulatorDebugConfigurationProvider } from "./simulatorDebugConfigurationProvider" ;
31+ import getPackageInfo from "./telemetry/getPackageInfo" ;
2932import TelemetryAI from "./telemetry/telemetryAI" ;
3033import { UsbDetector } from "./usbDetector" ;
3134import { 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
3636let currentFileAbsPath : string = "" ;
3737let 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+ } ;
10701096const updateCurrentFileIfPython = async (
10711097 activeTextDocument : vscode . TextDocument | undefined ,
10721098 currentPanel : vscode . WebviewPanel
0 commit comments