Serialize PromptInputModel

Fixes #210753
This commit is contained in:
Daniel Imms 2024-06-21 08:14:57 -07:00
parent ce7105088c
commit 6ddf63fd33
No known key found for this signature in database
GPG key ID: E5CF412B63651C69
5 changed files with 39 additions and 4 deletions

View file

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

View file

@ -49,6 +49,14 @@ export interface IPromptInputModelState {
readonly ghostTextIndex: number; 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 { export class PromptInputModel extends Disposable implements IPromptInputModel {
private _state: PromptInputState = PromptInputState.Unknown; private _state: PromptInputState = PromptInputState.Unknown;
@ -142,6 +150,26 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
return result; 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 }) { private _handleCommandStart(command: { marker: IMarker }) {
if (this._state === PromptInputState.Input) { if (this._state === PromptInputState.Input) {
return; return;

View file

@ -408,7 +408,8 @@ export class CommandDetectionCapability extends Disposable implements ICommandDe
} }
return { return {
isWindowsPty: this._ptyHeuristics.value instanceof WindowsPtyHeuristics, 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._logService.debug('CommandDetectionCapability#onCommandFinished', newCommand);
this._onCommandFinished.fire(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 // No command restoration is needed when relaunching terminals
commands: { commands: {
isWindowsPty: false, 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)) { if (!this._terminal || !this.capabilities.has(TerminalCapability.CommandDetection)) {
return { return {
isWindowsPty: false, isWindowsPty: false,
commands: [] commands: [],
promptInputModel: undefined,
}; };
} }
const result = this._createOrGetCommandDetection(this._terminal).serialize(); const result = this._createOrGetCommandDetection(this._terminal).serialize();