Fix start and end events

This commit is contained in:
Daniel Imms
2024-03-20 18:39:42 -07:00
parent b7a128cc3f
commit dd06e98376
4 changed files with 22 additions and 14 deletions
@@ -175,7 +175,7 @@ export interface ICommandDetectionCapability {
readonly currentCommand: ICurrentPartialCommand | undefined;
readonly onCommandStarted: Event<ITerminalCommand>;
readonly onCommandFinished: Event<ITerminalCommand>;
readonly onCommandExecuted: Event<void>;
readonly onCommandExecuted: Event<ITerminalCommand>;
readonly onCommandInvalidated: Event<ITerminalCommand[]>;
readonly onCurrentCommandInvalidated: Event<ICommandInvalidationRequest>;
setCwd(value: string): void;
@@ -74,7 +74,7 @@ export class CommandDetectionCapability extends Disposable implements ICommandDe
readonly onBeforeCommandFinished = this._onBeforeCommandFinished.event;
private readonly _onCommandFinished = this._register(new Emitter<ITerminalCommand>());
readonly onCommandFinished = this._onCommandFinished.event;
private readonly _onCommandExecuted = this._register(new Emitter<void>());
private readonly _onCommandExecuted = this._register(new Emitter<ITerminalCommand>());
readonly onCommandExecuted = this._onCommandExecuted.event;
private readonly _onCommandInvalidated = this._register(new Emitter<ITerminalCommand[]>());
readonly onCommandInvalidated = this._onCommandInvalidated.event;
@@ -408,7 +408,7 @@ export class CommandDetectionCapability extends Disposable implements ICommandDe
interface ICommandDetectionHeuristicsHooks {
readonly onCurrentCommandInvalidatedEmitter: Emitter<ICommandInvalidationRequest>;
readonly onCommandStartedEmitter: Emitter<ITerminalCommand>;
readonly onCommandExecutedEmitter: Emitter<void>;
readonly onCommandExecutedEmitter: Emitter<ITerminalCommand>;
readonly dimensions: ITerminalDimensions;
readonly isCommandStorageDisabled: boolean;
@@ -495,7 +495,7 @@ class UnixPtyHeuristics extends Disposable {
if (y === commandExecutedLine) {
currentCommand.command += this._terminal.buffer.active.getLine(commandExecutedLine)?.translateToString(true, undefined, currentCommand.commandExecutedX) || '';
}
this._hooks.onCommandExecutedEmitter.fire();
this._hooks.onCommandExecutedEmitter.fire(currentCommand as ITerminalCommand);
}
}
@@ -733,7 +733,7 @@ class WindowsPtyHeuristics extends Disposable {
this._onCursorMoveListener.clear();
this._evaluateCommandMarkers();
this._capability.currentCommand.commandExecutedX = this._terminal.buffer.active.cursorX;
this._hooks.onCommandExecutedEmitter.fire();
this._hooks.onCommandExecutedEmitter.fire(this._capability.currentCommand as ITerminalCommand);
this._logService.debug('CommandDetectionCapability#handleCommandExecuted', this._capability.currentCommand.commandExecutedX, this._capability.currentCommand.commandExecutedMarker?.line);
}
@@ -827,7 +827,7 @@ class WindowsPtyHeuristics extends Disposable {
}
this._capability.currentCommand.commandExecutedMarker = this._hooks.commandMarkers[this._hooks.commandMarkers.length - 1];
// Fire this now to prevent issues like #197409
this._hooks.onCommandExecutedEmitter.fire();
this._hooks.onCommandExecutedEmitter.fire(this._capability.currentCommand as ITerminalCommand);
}
private _cursorOnNextLine(): boolean {
@@ -34,7 +34,7 @@ export class MainThreadTerminalShellIntegration extends Disposable implements Ma
// onDidStartTerminalShellExecution
const commandDetectionStartEvent = this._store.add(
this._terminalService.createOnInstanceCapabilityEvent(TerminalCapability.CommandDetection, e => e.onCommandStarted)
this._terminalService.createOnInstanceCapabilityEvent(TerminalCapability.CommandDetection, e => e.onCommandExecuted)
);
this._store.add(commandDetectionStartEvent.event(e => {
const command = e.data;
@@ -46,6 +46,7 @@ export class MainThreadTerminalShellIntegration extends Disposable implements Ma
this._terminalService.createOnInstanceCapabilityEvent(TerminalCapability.CommandDetection, e => e.onCommandFinished)
);
this._store.add(commandDetectionEndEvent.event(e => {
console.log('$acceptTerminalShellExecutionEnd');
this._proxy.$acceptTerminalShellExecutionEnd(e.instance.instanceId, e.data.exitCode);
}));
@@ -45,6 +45,8 @@ export class ExtHostTerminalShellIntegration extends Disposable implements IExtH
this._proxy = extHostRpc.getProxy(MainContext.MainThreadTerminalShellIntegration);
// TODO: Dispose shell integration when terminal is disposed
// TODO: Remove test code
this.onDidChangeTerminalShellIntegration(e => {
console.log('*** onDidChangeTerminalShellIntegration', e);
@@ -65,6 +67,7 @@ export class ExtHostTerminalShellIntegration extends Disposable implements IExtH
this.onDidEndTerminalShellExecution(e => {
console.log('*** onDidEndTerminalShellExecution', e);
});
setTimeout(() => {
Array.from(this._activeShellIntegrations.values())[0].value.executeCommand('echo hello');
}, 4000);
@@ -98,7 +101,7 @@ export class ExtHostTerminalShellIntegration extends Disposable implements IExtH
}
public $acceptTerminalShellExecutionEnd(id: number, exitCode: number | undefined): void {
this._activeShellIntegrations.get(id)?.currentExecution?.endExecution(exitCode);
this._activeShellIntegrations.get(id)?.endShellExecution(exitCode);
}
public $acceptTerminalShellExecutionData(id: number, data: string): void {
@@ -106,7 +109,7 @@ export class ExtHostTerminalShellIntegration extends Disposable implements IExtH
}
}
class InternalTerminalShellIntegration {
class InternalTerminalShellIntegration extends Disposable {
private _currentExecution: InternalTerminalShellExecution | undefined;
get currentExecution(): InternalTerminalShellExecution | undefined { return this._currentExecution; }
@@ -114,16 +117,17 @@ class InternalTerminalShellIntegration {
readonly value: vscode.TerminalShellIntegration;
protected readonly _onDidRequestShellExecution = new Emitter<string>();
protected readonly _onDidRequestShellExecution = this._register(new Emitter<string>());
readonly onDidRequestShellExecution = this._onDidRequestShellExecution.event;
protected readonly _onDidRequestEndExecution = new Emitter<InternalTerminalShellExecution>();
protected readonly _onDidRequestEndExecution = this._register(new Emitter<InternalTerminalShellExecution>());
readonly onDidRequestEndExecution = this._onDidRequestEndExecution.event;
constructor(
private readonly _terminal: vscode.Terminal,
private readonly _onDidStartTerminalShellExecution: Emitter<vscode.TerminalShellExecution>
) {
// TODO: impl
super();
const that = this;
this.value = {
// TODO: Fill in cwd
@@ -158,8 +162,11 @@ class InternalTerminalShellIntegration {
}
endShellExecution(exitCode: number | undefined): void {
this._currentExecution?.endExecution(exitCode);
this._currentExecution = undefined;
if (this._currentExecution) {
this._currentExecution.endExecution(exitCode);
this._onDidRequestEndExecution.fire(this._currentExecution);
this._currentExecution = undefined;
}
}
}