4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
import type * as vscode from 'vscode' ;
7
+ import { TerminalShellExecutionCommandLineConfidence } from './extHostTypes' ;
7
8
import { Disposable , DisposableStore , toDisposable } from 'vs/base/common/lifecycle' ;
8
9
import { createDecorator } from 'vs/platform/instantiation/common/instantiation' ;
9
10
import { MainContext , type ExtHostTerminalShellIntegrationShape , type MainThreadTerminalShellIntegrationShape } from 'vs/workbench/api/common/extHost.protocol' ;
@@ -17,7 +18,7 @@ export interface IExtHostTerminalShellIntegration extends ExtHostTerminalShellIn
17
18
readonly _serviceBrand : undefined ;
18
19
19
20
readonly onDidChangeTerminalShellIntegration : Event < vscode . TerminalShellIntegrationChangeEvent > ;
20
- readonly onDidStartTerminalShellExecution : Event < vscode . TerminalShellExecution > ;
21
+ readonly onDidStartTerminalShellExecution : Event < vscode . TerminalShellExecutionStartEvent > ;
21
22
readonly onDidEndTerminalShellExecution : Event < vscode . TerminalShellExecutionEndEvent > ;
22
23
}
23
24
export const IExtHostTerminalShellIntegration = createDecorator < IExtHostTerminalShellIntegration > ( 'IExtHostTerminalShellIntegration' ) ;
@@ -32,7 +33,7 @@ export class ExtHostTerminalShellIntegration extends Disposable implements IExtH
32
33
33
34
protected readonly _onDidChangeTerminalShellIntegration = new Emitter < vscode . TerminalShellIntegrationChangeEvent > ( ) ;
34
35
readonly onDidChangeTerminalShellIntegration = this . _onDidChangeTerminalShellIntegration . event ;
35
- protected readonly _onDidStartTerminalShellExecution = new Emitter < vscode . TerminalShellExecution > ( ) ;
36
+ protected readonly _onDidStartTerminalShellExecution = new Emitter < vscode . TerminalShellExecutionStartEvent > ( ) ;
36
37
readonly onDidStartTerminalShellExecution = this . _onDidStartTerminalShellExecution . event ;
37
38
protected readonly _onDidEndTerminalShellExecution = new Emitter < vscode . TerminalShellExecutionEndEvent > ( ) ;
38
39
readonly onDidEndTerminalShellExecution = this . _onDidEndTerminalShellExecution . event ;
@@ -103,16 +104,26 @@ export class ExtHostTerminalShellIntegration extends Disposable implements IExtH
103
104
} ) ;
104
105
}
105
106
106
- public $shellExecutionStart ( instanceId : number , commandLine : string , cwd : URI | undefined ) : void {
107
+ public $shellExecutionStart ( instanceId : number , commandLineValue : string , commandLineConfidence : TerminalShellExecutionCommandLineConfidence , isTrusted : boolean , cwd : URI | undefined ) : void {
107
108
// Force shellIntegration creation if it hasn't been created yet, this could when events
108
109
// don't come through on startup
109
110
if ( ! this . _activeShellIntegrations . has ( instanceId ) ) {
110
111
this . $shellIntegrationChange ( instanceId ) ;
111
112
}
113
+ const commandLine : vscode . TerminalShellExecutionCommandLine = {
114
+ value : commandLineValue ,
115
+ confidence : commandLineConfidence ,
116
+ isTrusted
117
+ } ;
112
118
this . _activeShellIntegrations . get ( instanceId ) ?. startShellExecution ( commandLine , cwd ) ;
113
119
}
114
120
115
- public $shellExecutionEnd ( instanceId : number , commandLine : string | undefined , exitCode : number | undefined ) : void {
121
+ public $shellExecutionEnd ( instanceId : number , commandLineValue : string , commandLineConfidence : TerminalShellExecutionCommandLineConfidence , isTrusted : boolean , exitCode : number | undefined ) : void {
122
+ const commandLine : vscode . TerminalShellExecutionCommandLine = {
123
+ value : commandLineValue ,
124
+ confidence : commandLineConfidence ,
125
+ isTrusted
126
+ } ;
116
127
this . _activeShellIntegrations . get ( instanceId ) ?. endShellExecution ( commandLine , exitCode ) ;
117
128
}
118
129
@@ -151,7 +162,7 @@ class InternalTerminalShellIntegration extends Disposable {
151
162
152
163
constructor (
153
164
private readonly _terminal : vscode . Terminal ,
154
- private readonly _onDidStartTerminalShellExecution : Emitter < vscode . TerminalShellExecution >
165
+ private readonly _onDidStartTerminalShellExecution : Emitter < vscode . TerminalShellExecutionStartEvent >
155
166
) {
156
167
super ( ) ;
157
168
@@ -160,30 +171,42 @@ class InternalTerminalShellIntegration extends Disposable {
160
171
get cwd ( ) : URI | undefined {
161
172
return that . _cwd ;
162
173
} ,
163
- executeCommand ( commandLine ) : vscode . TerminalShellExecution {
164
- that . _onDidRequestShellExecution . fire ( commandLine ) ;
174
+ // executeCommand(commandLine: string): vscode.TerminalShellExecution;
175
+ // executeCommand(executable: string, args: string[]): vscode.TerminalShellExecution;
176
+ executeCommand ( commandLineOrExecutable : string , args ?: string [ ] ) : vscode . TerminalShellExecution {
177
+ let commandLineValue : string = commandLineOrExecutable ;
178
+ if ( args ) {
179
+ commandLineValue += ` "${ args . map ( e => `${ e . replaceAll ( '"' , '\\"' ) } ` ) . join ( '" "' ) } "` ;
180
+ }
181
+
182
+ that . _onDidRequestShellExecution . fire ( commandLineValue ) ;
165
183
// Fire the event in a microtask to allow the extension to use the execution before
166
184
// the start event fires
185
+ const commandLine : vscode . TerminalShellExecutionCommandLine = {
186
+ value : commandLineValue ,
187
+ confidence : TerminalShellExecutionCommandLineConfidence . High ,
188
+ isTrusted : true
189
+ } ;
167
190
const execution = that . startShellExecution ( commandLine , that . _cwd , true ) . value ;
168
191
that . _ignoreNextExecution = true ;
169
192
return execution ;
170
193
}
171
194
} ;
172
195
}
173
196
174
- startShellExecution ( commandLine : string , cwd : URI | undefined , fireEventInMicrotask ?: boolean ) : InternalTerminalShellExecution {
197
+ startShellExecution ( commandLine : vscode . TerminalShellExecutionCommandLine , cwd : URI | undefined , fireEventInMicrotask ?: boolean ) : InternalTerminalShellExecution {
175
198
if ( this . _ignoreNextExecution && this . _currentExecution ) {
176
199
this . _ignoreNextExecution = false ;
177
200
} else {
178
201
if ( this . _currentExecution ) {
179
- this . _currentExecution . endExecution ( undefined , undefined ) ;
180
- this . _onDidRequestEndExecution . fire ( { execution : this . _currentExecution . value , exitCode : undefined } ) ;
202
+ this . _currentExecution . endExecution ( undefined ) ;
203
+ this . _onDidRequestEndExecution . fire ( { terminal : this . _terminal , shellIntegration : this . value , execution : this . _currentExecution . value , exitCode : undefined } ) ;
181
204
}
182
- const currentExecution = this . _currentExecution = new InternalTerminalShellExecution ( this . _terminal , commandLine , cwd ) ;
205
+ const currentExecution = this . _currentExecution = new InternalTerminalShellExecution ( commandLine , cwd ) ;
183
206
if ( fireEventInMicrotask ) {
184
- queueMicrotask ( ( ) => this . _onDidStartTerminalShellExecution . fire ( currentExecution . value ) ) ;
207
+ queueMicrotask ( ( ) => this . _onDidStartTerminalShellExecution . fire ( { terminal : this . _terminal , shellIntegration : this . value , execution : currentExecution . value } ) ) ;
185
208
} else {
186
- this . _onDidStartTerminalShellExecution . fire ( this . _currentExecution . value ) ;
209
+ this . _onDidStartTerminalShellExecution . fire ( { terminal : this . _terminal , shellIntegration : this . value , execution : this . _currentExecution . value } ) ;
187
210
}
188
211
}
189
212
return this . _currentExecution ;
@@ -193,10 +216,10 @@ class InternalTerminalShellIntegration extends Disposable {
193
216
this . currentExecution ?. emitData ( data ) ;
194
217
}
195
218
196
- endShellExecution ( commandLine : string | undefined , exitCode : number | undefined ) : void {
219
+ endShellExecution ( commandLine : vscode . TerminalShellExecutionCommandLine | undefined , exitCode : number | undefined ) : void {
197
220
if ( this . _currentExecution ) {
198
- this . _currentExecution . endExecution ( commandLine , exitCode ) ;
199
- this . _onDidRequestEndExecution . fire ( { execution : this . _currentExecution . value , exitCode } ) ;
221
+ this . _currentExecution . endExecution ( commandLine ) ;
222
+ this . _onDidRequestEndExecution . fire ( { terminal : this . _terminal , shellIntegration : this . value , execution : this . _currentExecution . value , exitCode } ) ;
200
223
this . _currentExecution = undefined ;
201
224
}
202
225
}
@@ -223,16 +246,12 @@ class InternalTerminalShellExecution {
223
246
readonly value : vscode . TerminalShellExecution ;
224
247
225
248
constructor (
226
- readonly terminal : vscode . Terminal ,
227
- private _commandLine : string | undefined ,
249
+ private _commandLine : vscode . TerminalShellExecutionCommandLine ,
228
250
readonly cwd : URI | undefined ,
229
251
) {
230
252
const that = this ;
231
253
this . value = {
232
- get terminal ( ) : vscode . Terminal {
233
- return that . terminal ;
234
- } ,
235
- get commandLine ( ) : string | undefined {
254
+ get commandLine ( ) : vscode . TerminalShellExecutionCommandLine {
236
255
return that . _commandLine ;
237
256
} ,
238
257
get cwd ( ) : URI | undefined {
@@ -258,7 +277,7 @@ class InternalTerminalShellExecution {
258
277
this . _dataStream ?. emitData ( data ) ;
259
278
}
260
279
261
- endExecution ( commandLine : string | undefined , exitCode : number | undefined ) : void {
280
+ endExecution ( commandLine : vscode . TerminalShellExecutionCommandLine | undefined ) : void {
262
281
if ( commandLine ) {
263
282
this . _commandLine = commandLine ;
264
283
}
0 commit comments