@@ -21,53 +21,56 @@ export function activate(context: vscode.ExtensionContext) {
21
21
22
22
// Add our library path to settings.json for autocomplete functionality
23
23
updatePythonExtraPaths ( ) ;
24
-
25
- // Opening the output panel
24
+
26
25
if ( outChannel === undefined ) {
27
26
outChannel = vscode . window . createOutputChannel ( CONSTANTS . NAME ) ;
28
27
logToOutputChannel ( outChannel , CONSTANTS . INFO . WELCOME_OUTPUT_TAB , true ) ;
29
28
}
30
29
31
- // Open Simulator on the webview
32
- let openSimulator = vscode . commands . registerCommand (
33
- "pacifica.openSimulator" ,
34
- ( ) => {
35
- if ( currentPanel ) {
36
- currentPanel . reveal ( vscode . ViewColumn . Two ) ;
37
- } else {
38
- currentPanel = vscode . window . createWebviewPanel (
39
- "adafruitSimulator" ,
40
- CONSTANTS . LABEL . WEBVIEW_PANEL ,
41
- vscode . ViewColumn . Two ,
42
- {
43
- // Only allow the webview to access resources in our extension's media directory
44
- localResourceRoots : [
45
- vscode . Uri . file ( path . join ( context . extensionPath , "out" ) )
46
- ] ,
47
- enableScripts : true
48
- }
49
- ) ;
50
-
51
- currentPanel . webview . html = getWebviewContent ( context ) ;
30
+ const openWebview = ( ) => {
31
+ if ( currentPanel ) {
32
+ currentPanel . reveal ( vscode . ViewColumn . Two ) ;
33
+ } else {
34
+ currentPanel = vscode . window . createWebviewPanel (
35
+ "adafruitSimulator" ,
36
+ CONSTANTS . LABEL . WEBVIEW_PANEL ,
37
+ vscode . ViewColumn . Two ,
38
+ {
39
+ // Only allow the webview to access resources in our extension's media directory
40
+ localResourceRoots : [
41
+ vscode . Uri . file ( path . join ( context . extensionPath , "out" ) )
42
+ ] ,
43
+ enableScripts : true
44
+ }
45
+ ) ;
46
+
47
+ currentPanel . webview . html = getWebviewContent ( context ) ;
52
48
53
- currentPanel . onDidDispose (
54
- ( ) => {
55
- currentPanel = undefined ;
56
- } ,
57
- undefined ,
58
- context . subscriptions
59
- ) ;
60
- }
49
+ currentPanel . onDidDispose (
50
+ ( ) => {
51
+ currentPanel = undefined ;
52
+ } ,
53
+ undefined ,
54
+ context . subscriptions
55
+ ) ;
61
56
}
57
+ } ;
58
+
59
+ // Open Simulator on the webview
60
+ const openSimulator = vscode . commands . registerCommand (
61
+ "pacifica.openSimulator" ,
62
+ openWebview
62
63
) ;
63
64
64
- let newProject = vscode . commands . registerCommand (
65
+ const newProject = vscode . commands . registerCommand (
65
66
"pacifica.newProject" ,
66
67
( ) => {
67
68
const fileName = "template.py" ;
68
69
const filePath = __dirname + path . sep + fileName ;
69
70
const file = fs . readFileSync ( filePath , "utf8" ) ;
70
71
72
+ openWebview ( ) ;
73
+
71
74
vscode . workspace
72
75
. openTextDocument ( { content : file , language : "en" } )
73
76
. then ( ( template : vscode . TextDocument ) => {
@@ -83,10 +86,11 @@ export function activate(context: vscode.ExtensionContext) {
83
86
const runSimulator = vscode . commands . registerCommand (
84
87
"pacifica.runSimulator" ,
85
88
( ) => {
89
+ openWebview ( ) ;
90
+
86
91
if ( ! currentPanel ) {
87
92
return ;
88
93
}
89
-
90
94
console . info ( CONSTANTS . INFO . RUNNING_CODE ) ;
91
95
const activeTextEditor : vscode . TextEditor | undefined =
92
96
vscode . window . activeTextEditor ;
0 commit comments