@@ -39,6 +39,37 @@ type QuickPickActionItem = {
39
39
action ?( folder ?: vscode . WorkspaceFolder ) : Promise < void > ;
40
40
} ;
41
41
42
+ async function waitForShellIntegration (
43
+ folder : vscode . WorkspaceFolder ,
44
+ terminal : vscode . Terminal ,
45
+ timeout : number = 3000 ,
46
+ ) : Promise < boolean > {
47
+ const config = vscode . workspace . getConfiguration ( "terminal.integrated.shellIntegration" , folder ) ;
48
+ const enabled = config . get ( "enabled" , false ) ;
49
+ if ( ! enabled ) {
50
+ return false ;
51
+ }
52
+
53
+ return new Promise < boolean > ( ( resolve ) => {
54
+ if ( terminal . shellIntegration ) {
55
+ resolve ( true ) ;
56
+ return ;
57
+ }
58
+
59
+ const listener = vscode . window . onDidChangeTerminalShellIntegration ( ( event ) => {
60
+ if ( event . terminal === terminal ) {
61
+ listener . dispose ( ) ;
62
+ resolve ( true ) ;
63
+ }
64
+ } ) ;
65
+
66
+ setTimeout ( ( ) => {
67
+ listener . dispose ( ) ;
68
+ resolve ( false ) ;
69
+ } , timeout ) ;
70
+ } ) ;
71
+ }
72
+
42
73
export class LanguageToolsManager {
43
74
private _workspaceFolderLanguageStatuses = new WeakMap < vscode . WorkspaceFolder , ProjectInfo > ( ) ;
44
75
private _disposables : vscode . Disposable ;
@@ -237,20 +268,27 @@ export class LanguageToolsManager {
237
268
const config = vscode . workspace . getConfiguration ( CONFIG_SECTION , folder ) ;
238
269
const profiles = config . get < string [ ] > ( "profiles" , [ ] ) ;
239
270
240
- const { pythonCommand, final_args } = await this . pythonManager . buildRobotCodeCommand (
241
- folder ,
242
- [ "repl" ] ,
243
- profiles ,
244
- ) ;
245
- vscode . window
246
- . createTerminal ( {
247
- name : `Robot REPL${ vscode . workspace . workspaceFolders ?. length === 1 ? "" : ` (${ folder . name } )` } ` ,
248
- shellPath : pythonCommand ,
249
- shellArgs : final_args ,
250
- cwd : folder . uri ,
251
- iconPath : new vscode . ThemeIcon ( "robotcode-robot" ) ,
252
- } )
253
- . show ( ) ;
271
+ const terminal = vscode . window . createTerminal ( {
272
+ name : `Robot REPL${ vscode . workspace . workspaceFolders ?. length === 1 ? "" : ` (${ folder . name } )` } ` ,
273
+ cwd : folder . uri ,
274
+ iconPath : new vscode . ThemeIcon ( "robotcode-robot" ) ,
275
+ isTransient : false ,
276
+ } ) ;
277
+ terminal . show ( ) ;
278
+ const shellIntegrationActive = await waitForShellIntegration ( folder , terminal ) ;
279
+ if ( shellIntegrationActive ) {
280
+ terminal . shellIntegration ?. executeCommand ( "robotcode" , [
281
+ ...( profiles !== undefined ? profiles . flatMap ( ( v ) => [ "-p" , v ] ) : [ ] ) ,
282
+ "repl" ,
283
+ ] ) ;
284
+ } else {
285
+ const { pythonCommand, final_args } = await this . pythonManager . buildRobotCodeCommand (
286
+ folder ,
287
+ [ "repl" ] ,
288
+ profiles ,
289
+ ) ;
290
+ terminal . sendText ( `${ pythonCommand } ${ final_args . join ( " " ) } ` , true ) ;
291
+ }
254
292
} ,
255
293
) ,
256
294
vscode . commands . registerCommand ( "robotcode.disableRoboCop" , async ( ) => {
0 commit comments