Skip to content

Commit f8b1d52

Browse files
committed
Prevent double fire of start shell execution
1 parent d8b76b5 commit f8b1d52

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/vs/workbench/api/browser/mainThreadTerminalShellIntegration.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
import { Event } from 'vs/base/common/event';
77
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';
109
import { ExtHostContext, MainContext, type ExtHostTerminalShellIntegrationShape, type MainThreadTerminalShellIntegrationShape } from 'vs/workbench/api/common/extHost.protocol';
1110
import { ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal';
11+
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
1212
import { extHostNamedCustomer, type IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers';
1313

1414
@extHostNamedCustomer(MainContext.MainThreadTerminalShellIntegration)
@@ -18,7 +18,7 @@ export class MainThreadTerminalShellIntegration extends Disposable implements Ma
1818
constructor(
1919
extHostContext: IExtHostContext,
2020
@ITerminalService private readonly _terminalService: ITerminalService,
21-
@IProductService productService: IProductService
21+
@IWorkbenchEnvironmentService workbenchEnvironmentService: IWorkbenchEnvironmentService
2222
) {
2323
super();
2424

@@ -36,7 +36,16 @@ export class MainThreadTerminalShellIntegration extends Disposable implements Ma
3636

3737
// onDidStartTerminalShellExecution
3838
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+
}));
4049

4150
// onDidEndTerminalShellExecution
4251
const commandDetectionEndEvent = this._store.add(this._terminalService.createOnInstanceCapabilityEvent(TerminalCapability.CommandDetection, e => e.onCommandFinished));
@@ -50,10 +59,8 @@ export class MainThreadTerminalShellIntegration extends Disposable implements Ma
5059
this._store.add(this._terminalService.onDidDisposeInstance(e => this._proxy.$closeTerminal(e.instanceId)));
5160

5261
// 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) {
5764
this._store.add(this._terminalService.onAnyInstanceData(e => this._proxy.$shellExecutionData(e.instance.instanceId, e.data)));
5865
}
5966
}

0 commit comments

Comments
 (0)