@@ -37,19 +37,24 @@ export class Lama2Panel {
37
37
public static render ( extensionUri : vscode . Uri ) {
38
38
if ( Lama2Panel . currentPanel ) {
39
39
// If the webview panel already exists reveal it
40
- Lama2Panel . currentPanel . _panel . reveal ( vscode . ViewColumn . Two )
40
+ console . log ( "revealing existing panel" )
41
+ Lama2Panel . currentPanel . _panel . reveal ( vscode . ViewColumn . Two , true )
41
42
} else {
43
+ console . log ( "opening new panel" )
42
44
// If a webview panel does not already exist create and show a new one
43
45
const panel = vscode . window . createWebviewPanel (
44
46
// Panel view type
45
47
"showLama2Output" ,
46
48
// Panel title
47
49
"Lama2 Output" ,
48
50
// The editor column the panel should be displayed in
49
- vscode . ViewColumn . Two ,
51
+
52
+ { preserveFocus : true , viewColumn : vscode . ViewColumn . Two } ,
53
+
50
54
// Extra panel configurations
51
55
{
52
56
// Enable JavaScript in the webview
57
+
53
58
enableScripts : true ,
54
59
// Restrict the webview to only load resources from the `out` and `webview-ui/build` directories
55
60
localResourceRoots : [
@@ -68,58 +73,58 @@ export class Lama2Panel {
68
73
}
69
74
70
75
public async executeLama2Command ( ) {
71
- this . _panel . webview . postMessage ( {
72
- command : "update" ,
73
- status : "starting" ,
74
- } )
75
-
76
- const lama2Command = getLama2Command ( ) ;
77
- if ( ! lama2Command ) {
78
- console . error ( "Failed to generate Lama2 command" ) ;
79
- return ;
80
- }
81
-
82
- const { cmd, rflag, rfile, rlog } = lama2Command ;
83
- this . rfile = rfile ;
84
- this . rlog = rlog ;
85
- this . setLama2Watch ( rflag ) ;
86
-
87
-
88
- // Execute command and capture output
89
- let terminal = getShowLama2Term ( "AutoLama2" )
90
- terminal . sendText ( cmd , true )
91
- let isVisible = false
92
-
93
- this . _panel . webview . onDidReceiveMessage ( ( message ) => {
94
- switch ( message . command ) {
95
- case "toggleTerminal" :
96
- console . log ( "isVisble" , isVisible )
97
- if ( isVisible ) {
98
- terminal . hide ( )
99
- isVisible = false
100
- } else {
101
- terminal . show ( )
102
- isVisible = true
103
- }
104
- this . _panel . webview . postMessage ( { type : "terminalVisibility" , isVisible } )
105
- return
76
+ try {
77
+ this . _panel . webview . postMessage ( {
78
+ command : "update" ,
79
+ status : "starting" ,
80
+ } )
81
+
82
+ const lama2Command = getLama2Command ( )
83
+ if ( ! lama2Command ) {
84
+ console . error ( "Failed to generate Lama2 command" )
85
+ return
106
86
}
107
- } , undefined )
108
87
109
- vscode . window . onDidCloseTerminal ( t => {
110
- if ( t . exitStatus && t . exitStatus . code ) {
111
- vscode . window . showInformationMessage ( `Exit code: ${ t . exitStatus . code } ` ) ;
112
- }
113
- } ) ;
88
+ const { cmd, rflag, rfile, rlog } = lama2Command
89
+ this . rfile = rfile
90
+ this . rlog = rlog
91
+ this . setLama2Watch ( rflag )
114
92
93
+ // Execute command and capture output
94
+ let terminal = getShowLama2Term ( "AutoLama2" )
95
+ terminal . sendText ( cmd , true )
96
+ let isVisible = false
115
97
98
+ this . _panel . webview . onDidReceiveMessage ( ( message ) => {
99
+ switch ( message . command ) {
100
+ case "toggleTerminal" :
101
+ console . log ( "isVisble" , isVisible )
102
+ if ( isVisible ) {
103
+ terminal . hide ( )
104
+ isVisible = false
105
+ } else {
106
+ terminal . show ( )
107
+ isVisible = true
108
+ }
109
+ this . _panel . webview . postMessage ( { type : "terminalVisibility" , isVisible } )
110
+ return
111
+ }
112
+ } , undefined )
113
+
114
+ vscode . window . onDidCloseTerminal ( ( t ) => {
115
+ if ( t . exitStatus && t . exitStatus . code ) {
116
+ vscode . window . showInformationMessage ( `Exit code: ${ t . exitStatus . code } ` )
117
+ }
118
+ } )
119
+ } catch ( error ) {
120
+ console . error ( "Error executing Lama2 command:" , error )
121
+ }
116
122
}
117
123
118
124
private setLama2Watch ( rflag : string ) {
119
125
let c = new ChokiExtension ( )
120
126
c . pathAddTrigger ( rflag , this . onLama2Finish , this )
121
127
}
122
-
123
128
124
129
private handleCommandError ( errorMessage : string ) {
125
130
// Remove ANSI color codes and other formatting
@@ -170,9 +175,9 @@ export class Lama2Panel {
170
175
}
171
176
} catch ( error ) {
172
177
console . log ( this . rlog )
173
- const stderr = await vscode . workspace . fs . readFile ( vscode . Uri . file ( this . rlog ) ) ;
174
- const stderrString = new TextDecoder ( ) . decode ( stderr ) ;
175
- console . error ( "Error processing Lama2 output:" , stderrString ) ;
178
+ const stderr = await vscode . workspace . fs . readFile ( vscode . Uri . file ( this . rlog ) )
179
+ const stderrString = new TextDecoder ( ) . decode ( stderr )
180
+ console . error ( "Error processing Lama2 output:" , stderrString )
176
181
this . handleCommandError (
177
182
error instanceof Error ? stderrString : "An error occurred while processing the Lama2 output"
178
183
)
@@ -236,9 +241,9 @@ export class Lama2Panel {
236
241
case "alert" :
237
242
vscode . window . showErrorMessage ( message . text )
238
243
return
239
- case ' showNotification' :
240
- vscode . window . showInformationMessage ( message . text ) ;
241
- break ;
244
+ case " showNotification" :
245
+ vscode . window . showInformationMessage ( message . text )
246
+ break
242
247
}
243
248
} ,
244
249
undefined ,
@@ -247,54 +252,54 @@ export class Lama2Panel {
247
252
}
248
253
}
249
254
250
- // fs.access(rfile, fs.constants.F_OK, (err) => {
251
- // console.log('Checking if output file exists', err);
252
- // if (err) {
253
- // console.log('Output file does not exist');
254
- // this.handleCommandError("Output file not created");
255
- // } else {
256
- // this.onLama2Finish(rfile);
257
- // }
258
- // });
259
- // return;
260
-
261
- // exec(cmd, (error, stdout, stderr) => {
262
- // console.log('exec', cmd)
263
- // console.log('stdout', stdout)
264
- // console.log('stderr', stderr)
265
-
266
- // // Send the command to the terminal
267
-
268
- // if (stdout) {
269
- // // Check if stdout is HTML
270
- // if (stdout.trim().startsWith('<')) {
271
- // // If it's HTML, call onLama2Finish directly with stdout
272
- // this.onLama2Finish(stdout);
273
- // return;
274
- // }
275
-
276
- // // If it's not HTML, proceed with the file check
277
- // fs.access(rfile, fs.constants.F_OK, (err) => {
278
- // console.log('Checking if output file exists', err);
279
- // if (err) {
280
- // console.log('Output file does not exist');
281
- // this.handleCommandError("Output file not created");
282
- // } else {
283
- // this.onLama2Finish(rfile);
284
- // }
285
- // });
286
- // return;
287
- // }
288
-
289
- // if (error) {
290
- // console.error(`exec error: ${error}`);
291
- // this.handleCommandError(stderr);
292
- // return;
293
- // }
294
-
295
- // if (stderr) {
296
- // console.error(`stderr: ${stderr}`);
297
- // this.handleCommandError(stderr);
298
- // return;
299
- // }
300
- // });
255
+ // fs.access(rfile, fs.constants.F_OK, (err) => {
256
+ // console.log('Checking if output file exists', err);
257
+ // if (err) {
258
+ // console.log('Output file does not exist');
259
+ // this.handleCommandError("Output file not created");
260
+ // } else {
261
+ // this.onLama2Finish(rfile);
262
+ // }
263
+ // });
264
+ // return;
265
+
266
+ // exec(cmd, (error, stdout, stderr) => {
267
+ // console.log('exec', cmd)
268
+ // console.log('stdout', stdout)
269
+ // console.log('stderr', stderr)
270
+
271
+ // // Send the command to the terminal
272
+
273
+ // if (stdout) {
274
+ // // Check if stdout is HTML
275
+ // if (stdout.trim().startsWith('<')) {
276
+ // // If it's HTML, call onLama2Finish directly with stdout
277
+ // this.onLama2Finish(stdout);
278
+ // return;
279
+ // }
280
+
281
+ // // If it's not HTML, proceed with the file check
282
+ // fs.access(rfile, fs.constants.F_OK, (err) => {
283
+ // console.log('Checking if output file exists', err);
284
+ // if (err) {
285
+ // console.log('Output file does not exist');
286
+ // this.handleCommandError("Output file not created");
287
+ // } else {
288
+ // this.onLama2Finish(rfile);
289
+ // }
290
+ // });
291
+ // return;
292
+ // }
293
+
294
+ // if (error) {
295
+ // console.error(`exec error: ${error}`);
296
+ // this.handleCommandError(stderr);
297
+ // return;
298
+ // }
299
+
300
+ // if (stderr) {
301
+ // console.error(`stderr: ${stderr}`);
302
+ // this.handleCommandError(stderr);
303
+ // return;
304
+ // }
305
+ // });
0 commit comments