Merge pull request #216820 from microsoft/tyriar/210753

Serialize PromptInputModel
This commit is contained in:
Daniel Imms 2024-06-21 08:32:54 -07:00 committed by GitHub
commit f4f94df15e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 39 additions and 4 deletions

View File

@ -5,7 +5,7 @@
import { Event } from 'vs/base/common/event';
import { IDisposable } from 'vs/base/common/lifecycle';
import type { IPromptInputModel } from 'vs/platform/terminal/common/capabilities/commandDetection/promptInputModel';
import type { IPromptInputModel, ISerializedPromptInputModel } from 'vs/platform/terminal/common/capabilities/commandDetection/promptInputModel';
import { ICurrentPartialCommand } from 'vs/platform/terminal/common/capabilities/commandDetection/terminalCommand';
import { ITerminalOutputMatch, ITerminalOutputMatcher } from 'vs/platform/terminal/common/terminal';
import { ReplayEntry } from 'vs/platform/terminal/common/terminalProcess';
@ -301,6 +301,7 @@ export interface IMarkProperties {
export interface ISerializedCommandDetectionCapability {
isWindowsPty: boolean;
commands: ISerializedTerminalCommand[];
promptInputModel: ISerializedPromptInputModel | undefined;
}
export interface IPtyHostProcessReplayEvent {
events: ReplayEntry[];

View File

@ -49,6 +49,14 @@ export interface IPromptInputModelState {
readonly ghostTextIndex: number;
}
export interface ISerializedPromptInputModel {
readonly modelState: IPromptInputModelState;
readonly commandStartX: number;
readonly lastPromptLine: string | undefined;
readonly continuationPrompt: string | undefined;
readonly lastUserInput: string;
}
export class PromptInputModel extends Disposable implements IPromptInputModel {
private _state: PromptInputState = PromptInputState.Unknown;
@ -142,6 +150,26 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
return result;
}
serialize(): ISerializedPromptInputModel {
return {
modelState: this._createStateObject(),
commandStartX: this._commandStartX,
lastPromptLine: this._lastPromptLine,
continuationPrompt: this._continuationPrompt,
lastUserInput: this._lastUserInput
};
}
deserialize(serialized: ISerializedPromptInputModel): void {
this._value = serialized.modelState.value;
this._cursorIndex = serialized.modelState.cursorIndex;
this._ghostTextIndex = serialized.modelState.ghostTextIndex;
this._commandStartX = serialized.commandStartX;
this._lastPromptLine = serialized.lastPromptLine;
this._continuationPrompt = serialized.continuationPrompt;
this._lastUserInput = serialized.lastUserInput;
}
private _handleCommandStart(command: { marker: IMarker }) {
if (this._state === PromptInputState.Input) {
return;

View File

@ -408,7 +408,8 @@ export class CommandDetectionCapability extends Disposable implements ICommandDe
}
return {
isWindowsPty: this._ptyHeuristics.value instanceof WindowsPtyHeuristics,
commands
commands,
promptInputModel: this._promptInputModel.serialize(),
};
}
@ -443,6 +444,9 @@ export class CommandDetectionCapability extends Disposable implements ICommandDe
this._logService.debug('CommandDetectionCapability#onCommandFinished', newCommand);
this._onCommandFinished.fire(newCommand);
}
if (serialized.promptInputModel) {
this._promptInputModel.deserialize(serialized.promptInputModel);
}
}
}

View File

@ -91,7 +91,8 @@ export class TerminalRecorder {
// No command restoration is needed when relaunching terminals
commands: {
isWindowsPty: false,
commands: []
commands: [],
promptInputModel: undefined,
}
};
}

View File

@ -577,7 +577,8 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
if (!this._terminal || !this.capabilities.has(TerminalCapability.CommandDetection)) {
return {
isWindowsPty: false,
commands: []
commands: [],
promptInputModel: undefined,
};
}
const result = this._createOrGetCommandDetection(this._terminal).serialize();