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

# Allow to use inline Chat for single edit application #190258

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/vs/workbench/api/common/extHostInlineChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type * as vscode from 'vscode';
import { ApiCommand, ApiCommandArgument, ApiCommandResult, ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
import { IRange } from 'vs/editor/common/core/range';
import { IPosition } from 'vs/editor/common/core/position';
import { TextEdit } from 'vs/editor/common/languages';

class ProviderWrapper {

Expand Down Expand Up @@ -62,6 +63,7 @@ export class ExtHostInteractiveEditor implements ExtHostInlineChatShape {
message?: string;
autoSend?: boolean;
position?: vscode.Position;
edits?: extHostTypes.TextEdit[];
};

type InteractiveEditorRunOptions = {
Expand All @@ -70,6 +72,7 @@ export class ExtHostInteractiveEditor implements ExtHostInlineChatShape {
message?: string;
autoSend?: boolean;
position?: IPosition;
edits?: TextEdit[];
};

extHostCommands.registerApiCommand(new ApiCommand(
Expand All @@ -86,6 +89,7 @@ export class ExtHostInteractiveEditor implements ExtHostInlineChatShape {
message: v.message,
autoSend: v.autoSend,
position: v.position ? typeConvert.Position.from(v.position) : undefined,
edits: v.edits ? v.edits.map(edit => typeConvert.TextEdit.from(edit)) : undefined,
};
})],
ApiCommandResult.Void
Expand Down Expand Up @@ -222,8 +226,10 @@ export class ExtHostInteractiveEditor implements ExtHostInlineChatShape {
$handleFeedback(handle: number, sessionId: number, responseId: number, kind: InlineChatResponseFeedbackKind): void {
const entry = this._inputProvider.get(handle);
const sessionData = this._inputSessions.get(sessionId);
const response = sessionData?.responses[responseId];
if (entry && response) {

// Allows to handle feedback on Edit Only triggers
const response = responseId === Number.MAX_VALUE ? { edits: [] } : sessionData?.responses[responseId];
if (entry && sessionData?.session && response) {
const apiKind = typeConvert.InteractiveEditorResponseFeedbackKind.to(kind);
entry.provider.handleInteractiveEditorResponseFeedback?.(sessionData.session, response, apiKind);
}
Expand Down
9 changes: 1 addition & 8 deletions src/vs/workbench/contrib/inlineChat/browser/inlineChat.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@

/* body */

.monaco-editor .inline-chat .body {
display: flex;
}

.monaco-editor .inline-chat .body .content {
display: flex;
box-sizing: border-box;
Expand Down Expand Up @@ -105,10 +101,6 @@
align-items: center;
}

.monaco-editor .inline-chat .status.actions {
margin-top: 6px;
}

.monaco-editor .inline-chat .status .actions.hidden {
display: none;
}
Expand Down Expand Up @@ -299,6 +291,7 @@

/* create zone */


.monaco-editor .inline-chat-newfile-widget {
padding: 3px 0 6px 0;
background-color: var(--vscode-inlineChat-regionHighlight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface InlineChatRunOptions {
existingSession?: Session;
isUnstashed?: boolean;
position?: IPosition;
edits?: TextEdit[];
}

export class InlineChatController implements IEditorContribution {
Expand Down Expand Up @@ -189,6 +190,8 @@ export class InlineChatController implements IEditorContribution {
private _currentRun?: Promise<void>;

async run(options: InlineChatRunOptions | undefined = {}): Promise<void> {
// Modifies the styling of inlineChat based on the mode of usage.
this._zone.value.widget.showEditOnlyActions(options.edits && options.edits.length > 0);
this.finishExistingSession();
if (this._currentRun) {
await this._currentRun;
Expand Down Expand Up @@ -367,6 +370,22 @@ export class InlineChatController implements IEditorContribution {
}
}));

if (options.edits && options.edits.length > 0) {
this._activeSession.addExchange(new SessionExchange(
new SessionPrompt('edit'),
new EditResponse(
this._activeSession.textModelN.uri,
this._activeSession.textModelN.getAlternativeVersionId(),
{
id: Number.MAX_VALUE,
type: InlineChatResponseType.EditorEdit,
edits: options.edits
},
[]
)));
return State.APPLY_RESPONSE;
}

if (!this._activeSession.lastExchange) {
return State.WAIT_FOR_INPUT;
} else if (options.isUnstashed) {
Expand Down
18 changes: 17 additions & 1 deletion src/vs/workbench/contrib/inlineChat/browser/inlineChatWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,21 @@ export class InlineChatWidget {
this._inputEditor.updateOptions({ ariaLabel: label });
}

// Changes styling of properties (e.g. Hides the input field), when toolbar is used only for Edit application.
showEditOnlyActions(isEditOnly?: boolean) {
if (isEditOnly) {
this._elements.content.style.display = 'none';
this._elements.status.style.marginTop = '0px';
this._elements.previewCreateTitle.classList.add('hidden');
this._elements.previewCreate.classList.add('hidden');
} else {
this._elements.content.style.display = 'flex';
this._elements.status.style.marginTop = '2px';
this._elements.previewCreateTitle.classList.remove('hidden');
this._elements.previewCreate.classList.remove('hidden');
}
}

dispose(): void {
this._store.dispose();
this._ctxInputEmpty.reset();
Expand Down Expand Up @@ -446,7 +461,8 @@ export class InlineChatWidget {

getHeight(): number {
const base = getTotalHeight(this._elements.progress) + getTotalHeight(this._elements.status);
const editorHeight = this._inputEditor.getContentHeight() + 12 /* padding and border */;
// If the input area is not shown, then don't extend the viewZone with its height.
const editorHeight = this._elements.content.style.display === 'none' ? 0 : this._inputEditor.getContentHeight() + 12 /* padding and border */;
const markdownMessageHeight = getTotalHeight(this._elements.markdownMessage);
const previewDiffHeight = this._previewDiffEditor.value.getModel() ? 12 + Math.min(300, Math.max(0, this._previewDiffEditor.value.getContentHeight())) : 0;
const previewCreateTitleHeight = getTotalHeight(this._elements.previewCreateTitle);
Expand Down