Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand button should not be shown when message not cropped in interactive editor #183564

Merged
merged 11 commits into from
Jun 5, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/c
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { ILogService } from 'vs/platform/log/common/log';
import { EditResponse, EmptyResponse, ErrorResponse, IInteractiveEditorSessionService, MarkdownResponse, Session, SessionExchange } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorSession';
import { EditResponse, EmptyResponse, ErrorResponse, ExpansionState, IInteractiveEditorSessionService, MarkdownResponse, Session, SessionExchange } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorSession';
import { EditModeStrategy, LivePreviewStrategy, LiveStrategy, PreviewStrategy } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorStrategies';
import { InteractiveEditorZoneWidget } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorWidget';
import { CTX_INTERACTIVE_EDITOR_HAS_ACTIVE_REQUEST, CTX_INTERACTIVE_EDITOR_LAST_FEEDBACK, IInteractiveEditorRequest, IInteractiveEditorResponse, INTERACTIVE_EDITOR_ID, EditMode, InteractiveEditorResponseFeedbackKind, CTX_INTERACTIVE_EDITOR_LAST_RESPONSE_TYPE, InteractiveEditorResponseType, CTX_INTERACTIVE_EDITOR_DID_EDIT, CTX_INTERACTIVE_EDITOR_HAS_STASHED_SESSION } from 'vs/workbench/contrib/interactiveEditor/common/interactiveEditor';
Expand Down Expand Up @@ -271,6 +271,7 @@ export class InteractiveEditorController implements IEditorContribution {
this._zone.value.widget.value = this._activeSession.lastInput ?? '';
this._zone.value.widget.updateInfo(this._activeSession.session.message ?? localize('welcome.1', "AI-generated code may be incorrect"));
this._zone.value.show(this._activeSession.wholeRange.getEndPosition());
this._zone.value.widget.preferredExpansionState = this._activeSession.lastExpansionState;

this._sessionStore.add(this._editor.onDidChangeModel((e) => {
const msg = this._activeSession?.lastExchange
Expand Down Expand Up @@ -556,7 +557,7 @@ export class InteractiveEditorController implements IEditorContribution {
this._zone.value.widget.updateStatus('');
this._zone.value.widget.updateMarkdownMessage(renderedMarkdown.element);
this._zone.value.widget.updateToolbar(true);
this._zone.value.widget.updateMarkdownMessageExpansionState(this._activeSession.lastExpansionState);
this._activeSession.lastExpansionState = this._zone.value.widget.expansionState;

} else if (response instanceof EditResponse) {
// edit response -> complex...
Expand Down Expand Up @@ -671,8 +672,9 @@ export class InteractiveEditorController implements IEditorContribution {

updateExpansionState(expand: boolean) {
if (this._activeSession) {
this._zone.value.widget.updateMarkdownMessageExpansionState(expand);
this._activeSession.lastExpansionState = expand;
const expansionState = expand ? ExpansionState.EXPANDED : ExpansionState.CROPPED;
this._zone.value.widget.updateMarkdownMessageExpansionState(expansionState);
this._activeSession.lastExpansionState = expansionState;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ type TelemetryDataClassification = {
editMode: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'What edit mode was choosen: live, livePreview, preview' };
};

export enum ExpansionState {
EXPANDED = 'expanded',
CROPPED = 'cropped',
NOT_CROPPED = 'not_cropped'
}

export class Session {

private _lastInput: string | undefined;
private _lastExpansionState: boolean | undefined;
private _lastExpansionState: ExpansionState | undefined;
private _lastTextModelChanges: LineRangeMapping[] | undefined;
private _isUnstashed: boolean = false;
private readonly _exchange: SessionExchange[] = [];
Expand Down Expand Up @@ -104,11 +110,11 @@ export class Session {
return this._lastInput;
}

get lastExpansionState() {
return this._lastExpansionState ?? false;
get lastExpansionState(): ExpansionState | undefined {
return this._lastExpansionState;
}

set lastExpansionState(state: boolean) {
set lastExpansionState(state: ExpansionState) {
this._lastExpansionState = state;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { AccessibilityVerbositySettingId } from 'vs/workbench/contrib/accessibility/browser/accessibilityContribution';
import { assertType } from 'vs/base/common/types';
import { renderLabelWithIcons } from 'vs/base/browser/ui/iconLabel/iconLabels';
import { ExpansionState } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorSession';
import { IdleValue } from 'vs/base/common/async';

const defaultAriaLabel = localize('aria-label', "Interactive Editor Input");
Expand Down Expand Up @@ -118,6 +119,9 @@ export interface InteractiveEditorWidgetViewState {
placeholder: string;
}

const MESSAGE_CROPPED_NUMBER_LINES = 3;
const MESSAGE_EXPANDED_NUMBER_LINES = 10;

export class InteractiveEditorWidget {

private static _modelPool: number = 1;
Expand Down Expand Up @@ -179,6 +183,8 @@ export class InteractiveEditorWidget {

private _lastDim: Dimension | undefined;
private _isLayouting: boolean = false;
private _preferredExpansionState: ExpansionState | undefined;
private _expansionState: ExpansionState = ExpansionState.NOT_CROPPED;

constructor(
parentEditor: ICodeEditor,
Expand Down Expand Up @@ -437,23 +443,49 @@ export class InteractiveEditorWidget {
this._onDidChangeHeight.fire();
}

get expansionState(): ExpansionState {
return this._expansionState;
}

set preferredExpansionState(expansionState: ExpansionState | undefined) {
this._preferredExpansionState = expansionState;
}

updateMarkdownMessage(message: Node | undefined) {
this._elements.markdownMessage.classList.toggle('hidden', !message);
let expansionState: ExpansionState;
if (!message) {
this._ctxMessageCropState.reset();
reset(this._elements.message);
this._ctxMessageCropState.reset();
expansionState = ExpansionState.NOT_CROPPED;

} else {
reset(this._elements.message, message);
if (this._elements.message.scrollHeight > this._elements.message.clientHeight) {
this._ctxMessageCropState.set('cropped');
if (this._preferredExpansionState) {
reset(this._elements.message, message);
expansionState = this._preferredExpansionState;
this._preferredExpansionState = undefined;
} else {
this._ctxMessageCropState.set('not_cropped');
this._elements.message.style.webkitLineClamp = MESSAGE_CROPPED_NUMBER_LINES.toString();
reset(this._elements.message, message);
expansionState = this._elements.message.scrollHeight > this._elements.message.clientHeight ? ExpansionState.CROPPED : ExpansionState.NOT_CROPPED;
}
this._ctxMessageCropState.set(expansionState);
this.updateLineClamp(expansionState);
}
this._expansionState = expansionState;
this._onDidChangeHeight.fire();
}

updateMarkdownMessageExpansionState(expansionState: ExpansionState) {
this._ctxMessageCropState.set(expansionState);
this.updateLineClamp(expansionState);
this._onDidChangeHeight.fire();
}

updateLineClamp(expansionState: ExpansionState) {
this._elements.message.style.webkitLineClamp = expansionState === ExpansionState.NOT_CROPPED ? 'none' : (expansionState === ExpansionState.EXPANDED ? MESSAGE_EXPANDED_NUMBER_LINES.toString() : MESSAGE_CROPPED_NUMBER_LINES.toString());
}

updateInfo(message: string): void {
this._elements.infoLabel.classList.toggle('hidden', !message);
this._elements.infoLabel.innerText = message;
Expand Down Expand Up @@ -502,12 +534,6 @@ export class InteractiveEditorWidget {
this._inputEditor.focus();
}

updateMarkdownMessageExpansionState(expand: boolean) {
this._ctxMessageCropState.set(expand ? 'expanded' : 'cropped');
this._elements.message.style.webkitLineClamp = expand ? '10' : '3';
this._onDidChangeHeight.fire();
}

// --- preview

showEditsPreview(textModelv0: ITextModel, edits: ISingleEditOperation[], changes: LineRangeMapping[]) {
Expand Down