4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
import { Event } from 'vs/base/common/event' ;
7
- import { Disposable } from 'vs/base/common/lifecycle' ;
7
+ import { Disposable , toDisposable , type IDisposable } from 'vs/base/common/lifecycle' ;
8
8
import { URI } from 'vs/base/common/uri' ;
9
9
import { TerminalCapability , type ITerminalCommand } from 'vs/platform/terminal/common/capabilities/capabilities' ;
10
10
import { ExtHostContext , MainContext , type ExtHostTerminalShellIntegrationShape , type MainThreadTerminalShellIntegrationShape } from 'vs/workbench/api/common/extHost.protocol' ;
@@ -26,6 +26,13 @@ export class MainThreadTerminalShellIntegration extends Disposable implements Ma
26
26
27
27
this . _proxy = extHostContext . getProxy ( ExtHostContext . ExtHostTerminalShellIntegration ) ;
28
28
29
+ const instanceDataListeners : Map < number , IDisposable > = new Map ( ) ;
30
+ this . _register ( toDisposable ( ( ) => {
31
+ for ( const listener of instanceDataListeners . values ( ) ) {
32
+ listener . dispose ( ) ;
33
+ }
34
+ } ) ) ;
35
+
29
36
// onDidChangeTerminalShellIntegration
30
37
const onDidAddCommandDetection = this . _store . add ( this . _terminalService . createOnInstanceEvent ( instance => {
31
38
return Event . map (
@@ -47,14 +54,22 @@ export class MainThreadTerminalShellIntegration extends Disposable implements Ma
47
54
}
48
55
// String paths are not exposed in the extension API
49
56
currentCommand = e . data ;
50
- this . _proxy . $shellExecutionStart ( e . instance . instanceId , e . data . command , convertToExtHostCommandLineConfidence ( e . data ) , e . data . isTrusted , this . _convertCwdToUri ( e . data . cwd ) ) ;
57
+ const instanceId = e . instance . instanceId ;
58
+ this . _proxy . $shellExecutionStart ( instanceId , e . data . command , convertToExtHostCommandLineConfidence ( e . data ) , e . data . isTrusted , this . _convertCwdToUri ( e . data . cwd ) ) ;
59
+
60
+ // TerminalShellExecution.createDataStream
61
+ // Debounce events to reduce the message count - when this listener is disposed the events will be flushed
62
+ instanceDataListeners . get ( instanceId ) ?. dispose ( ) ;
63
+ instanceDataListeners . set ( instanceId , Event . accumulate ( e . instance . onData , 50 , this . _store ) ( events => this . _proxy . $shellExecutionData ( instanceId , events . join ( ) ) ) ) ;
51
64
} ) ) ;
52
65
53
66
// onDidEndTerminalShellExecution
54
67
const commandDetectionEndEvent = this . _store . add ( this . _terminalService . createOnInstanceCapabilityEvent ( TerminalCapability . CommandDetection , e => e . onCommandFinished ) ) ;
55
68
this . _store . add ( commandDetectionEndEvent . event ( e => {
56
69
currentCommand = undefined ;
57
- this . _proxy . $shellExecutionEnd ( e . instance . instanceId , e . data . command , convertToExtHostCommandLineConfidence ( e . data ) , e . data . isTrusted , e . data . exitCode ) ;
70
+ const instanceId = e . instance . instanceId ;
71
+ instanceDataListeners . get ( instanceId ) ?. dispose ( ) ;
72
+ this . _proxy . $shellExecutionEnd ( instanceId , e . data . command , convertToExtHostCommandLineConfidence ( e . data ) , e . data . isTrusted , e . data . exitCode ) ;
58
73
} ) ) ;
59
74
60
75
// onDidChangeTerminalShellIntegration via cwd
@@ -65,12 +80,6 @@ export class MainThreadTerminalShellIntegration extends Disposable implements Ma
65
80
66
81
// Clean up after dispose
67
82
this . _store . add ( this . _terminalService . onDidDisposeInstance ( e => this . _proxy . $closeTerminal ( e . instanceId ) ) ) ;
68
-
69
- // TerminalShellExecution.createDataStream
70
- // TODO: Support this on remote; it should go via the server
71
- if ( ! workbenchEnvironmentService . remoteAuthority ) {
72
- this . _store . add ( this . _terminalService . onAnyInstanceData ( e => this . _proxy . $shellExecutionData ( e . instance . instanceId , e . data ) ) ) ;
73
- }
74
83
}
75
84
76
85
$executeCommand ( terminalId : number , commandLine : string ) : void {
0 commit comments