5
5
6
6
import { Event } from 'vs/base/common/event' ;
7
7
import { Disposable } from 'vs/base/common/lifecycle' ;
8
- import { IProductService } from 'vs/platform/product/common/productService' ;
9
- import { TerminalCapability } from 'vs/platform/terminal/common/capabilities/capabilities' ;
8
+ import { TerminalCapability , type ITerminalCommand } from 'vs/platform/terminal/common/capabilities/capabilities' ;
10
9
import { ExtHostContext , MainContext , type ExtHostTerminalShellIntegrationShape , type MainThreadTerminalShellIntegrationShape } from 'vs/workbench/api/common/extHost.protocol' ;
11
10
import { ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal' ;
11
+ import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService' ;
12
12
import { extHostNamedCustomer , type IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers' ;
13
13
14
14
@extHostNamedCustomer ( MainContext . MainThreadTerminalShellIntegration )
@@ -18,7 +18,7 @@ export class MainThreadTerminalShellIntegration extends Disposable implements Ma
18
18
constructor (
19
19
extHostContext : IExtHostContext ,
20
20
@ITerminalService private readonly _terminalService : ITerminalService ,
21
- @IProductService productService : IProductService
21
+ @IWorkbenchEnvironmentService workbenchEnvironmentService : IWorkbenchEnvironmentService
22
22
) {
23
23
super ( ) ;
24
24
@@ -36,7 +36,16 @@ export class MainThreadTerminalShellIntegration extends Disposable implements Ma
36
36
37
37
// onDidStartTerminalShellExecution
38
38
const commandDetectionStartEvent = this . _store . add ( this . _terminalService . createOnInstanceCapabilityEvent ( TerminalCapability . CommandDetection , e => e . onCommandExecuted ) ) ;
39
- this . _store . add ( commandDetectionStartEvent . event ( e => this . _proxy . $shellExecutionStart ( e . instance . instanceId , e . data . command , e . data . cwd ) ) ) ;
39
+ let lastCommand : ITerminalCommand | undefined ;
40
+ this . _store . add ( commandDetectionStartEvent . event ( e => {
41
+ // Prevent duplicate events from being sent in case command detection double fires the
42
+ // event
43
+ if ( e . data === lastCommand ) {
44
+ return ;
45
+ }
46
+ lastCommand = e . data ;
47
+ this . _proxy . $shellExecutionStart ( e . instance . instanceId , e . data . command , e . data . cwd ) ;
48
+ } ) ) ;
40
49
41
50
// onDidEndTerminalShellExecution
42
51
const commandDetectionEndEvent = this . _store . add ( this . _terminalService . createOnInstanceCapabilityEvent ( TerminalCapability . CommandDetection , e => e . onCommandFinished ) ) ;
@@ -50,10 +59,8 @@ export class MainThreadTerminalShellIntegration extends Disposable implements Ma
50
59
this . _store . add ( this . _terminalService . onDidDisposeInstance ( e => this . _proxy . $closeTerminal ( e . instanceId ) ) ) ;
51
60
52
61
// TerminalShellExecution.createDataStream
53
- // HACK: While proposed, this will only work in Insiders so as to not hurt performance in
54
- // stable
55
- if ( productService . quality === 'insiders' ) {
56
- // TODO: This should to go via the server on remote
62
+ // TODO: Support this on remote; it should go via the server
63
+ if ( ! workbenchEnvironmentService . remoteAuthority ) {
57
64
this . _store . add ( this . _terminalService . onAnyInstanceData ( e => this . _proxy . $shellExecutionData ( e . instance . instanceId , e . data ) ) ) ;
58
65
}
59
66
}
0 commit comments