Skip to content

Commit 6c8fd34

Browse files
authored
Joh/young-catshark (#198416)
* add save & discard-btns to inline new file experience, simplify response type because we don't really support workspace edit, fix size/height bug, fix positioning bug * fix preview mode, clean up events, fix workspace edit escape hatch * merge main, fix compile errors
1 parent 20cd4e4 commit 6c8fd34

9 files changed

Lines changed: 276 additions & 165 deletions

File tree

src/vs/base/browser/ui/button/button.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
border: 1px solid var(--vscode-button-border, transparent);
102102
border-left-width: 0 !important;
103103
border-radius: 0 2px 2px 0;
104+
display: flex;
105+
align-items: center;
104106
}
105107

106108
.monaco-button-dropdown > .monaco-button.monaco-text-button {

src/vs/editor/contrib/zoneWidget/browser/zoneWidget.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface IOptions {
2525
className?: string;
2626
isAccessible?: boolean;
2727
isResizeable?: boolean;
28-
frameColor?: Color;
28+
frameColor?: Color | string;
2929
arrowColor?: Color;
3030
keepEditorSelection?: boolean;
3131
allowUnlimitedHeight?: boolean;
@@ -34,7 +34,7 @@ export interface IOptions {
3434
}
3535

3636
export interface IStyles {
37-
frameColor?: Color | null;
37+
frameColor?: Color | string | null;
3838
arrowColor?: Color | null;
3939
}
4040

src/vs/workbench/contrib/inlineChat/browser/inlineChat.css

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,29 @@
318318
/* create zone */
319319

320320
.monaco-editor .inline-chat-newfile-widget {
321-
padding: 3px 0 6px 0;
322321
background-color: var(--vscode-inlineChat-regionHighlight);
323322
}
324323

325324
.monaco-editor .inline-chat-newfile-widget .title {
326325
display: flex;
327326
align-items: center;
328327
justify-content: space-between;
329-
padding: 3px 6px 3px 0;
328+
}
329+
330+
.monaco-editor .inline-chat-newfile-widget .title .detail {
331+
margin-left: 4px;
332+
}
333+
334+
.monaco-editor .inline-chat-newfile-widget .buttonbar-widget {
335+
display: flex;
336+
margin-left: auto;
337+
margin-right: 8px;
338+
}
339+
340+
.monaco-editor .inline-chat-newfile-widget .buttonbar-widget > .monaco-button {
341+
display: inline-flex;
342+
white-space: nowrap;
343+
margin-left: 4px;
330344
}
331345

332346
/* gutter decoration */
@@ -350,4 +364,3 @@
350364
.monaco-editor .glyph-margin-widgets .cgmr.codicon-inline-chat-transparent:hover {
351365
opacity: 1;
352366
}
353-

src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import { IModelDeltaDecoration } from 'vs/editor/common/model';
4444
import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
4545
import { chatAgentLeader, chatSubcommandLeader } from 'vs/workbench/contrib/chat/common/chatParserTypes';
4646
import { renderMarkdownAsPlaintext } from 'vs/base/browser/markdownRenderer';
47+
import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
4748

4849
export const enum State {
4950
CREATE_SESSION = 'CREATE_SESSION',
@@ -144,6 +145,7 @@ export class InlineChatController implements IEditorContribution {
144145
@IKeybindingService private readonly _keybindingService: IKeybindingService,
145146
@IChatAccessibilityService private readonly _chatAccessibilityService: IChatAccessibilityService,
146147
@IChatAgentService private readonly _chatAgentService: IChatAgentService,
148+
@IBulkEditService private readonly _bulkEditService: IBulkEditService,
147149
) {
148150
this._ctxHasActiveRequest = CTX_INLINE_CHAT_HAS_ACTIVE_REQUEST.bindTo(contextKeyService);
149151
this._ctxDidEdit = CTX_INLINE_CHAT_DID_EDIT.bindTo(contextKeyService);
@@ -270,7 +272,7 @@ export class InlineChatController implements IEditorContribution {
270272
this._zone.value.setContainerMargins();
271273
}
272274

273-
if (this._activeSession && this._activeSession.hasChangedText) {
275+
if (this._activeSession && (this._activeSession.hasChangedText || this._activeSession.lastExchange)) {
274276
widgetPosition = this._activeSession.wholeRange.value.getStartPosition().delta(-1);
275277
}
276278
if (this._activeSession) {
@@ -688,15 +690,15 @@ export class InlineChatController implements IEditorContribution {
688690
if (reply.message) {
689691
markdownContents.appendMarkdown(reply.message.value);
690692
}
691-
const replyResponse = response = new ReplyResponse(reply, markdownContents, this._activeSession.textModelN.uri, modelAltVersionIdNow, progressEdits);
693+
const replyResponse = response = this._instaService.createInstance(ReplyResponse, reply, markdownContents, this._activeSession.textModelN.uri, modelAltVersionIdNow, progressEdits);
692694

693695
for (let i = progressEdits.length; i < replyResponse.allLocalEdits.length; i++) {
694696
await this._makeChanges(replyResponse.allLocalEdits[i], undefined);
695697
}
696698

697699
const a11yMessageResponse = renderMarkdownAsPlaintext(replyResponse.mdContent);
698700

699-
a11yResponse = this._strategy.checkChanges(replyResponse) && a11yVerboseInlineChat
701+
a11yResponse = a11yVerboseInlineChat
700702
? a11yMessageResponse ? localize('editResponseMessage2', "{0}, also review proposed changes in the diff editor.", a11yMessageResponse) : localize('editResponseMessage', "Review proposed changes in the diff editor.")
701703
: a11yMessageResponse;
702704
}
@@ -741,14 +743,10 @@ export class InlineChatController implements IEditorContribution {
741743
assertType(this._strategy);
742744

743745
const { response } = this._activeSession.lastExchange!;
744-
if (response instanceof ReplyResponse) {
745-
// edit response -> complex...
746-
this._zone.value.widget.updateMarkdownMessage(undefined);
747-
748-
const canContinue = this._strategy.checkChanges(response);
749-
if (!canContinue) {
750-
return State.CANCEL;
751-
}
746+
if (response instanceof ReplyResponse && response.workspaceEdit) {
747+
// this reply cannot be applied in the normal inline chat UI and needs to be handled off to workspace edit
748+
this._bulkEditService.apply(response.workspaceEdit, { showPreview: true });
749+
return State.CANCEL;
752750
}
753751
return State.SHOW_RESPONSE;
754752
}
@@ -782,7 +780,7 @@ export class InlineChatController implements IEditorContribution {
782780
}
783781
}
784782

785-
private async [State.SHOW_RESPONSE](): Promise<State.WAIT_FOR_INPUT | State.CANCEL> {
783+
private async[State.SHOW_RESPONSE](): Promise<State.WAIT_FOR_INPUT | State.CANCEL> {
786784
assertType(this._activeSession);
787785
assertType(this._strategy);
788786

@@ -826,18 +824,14 @@ export class InlineChatController implements IEditorContribution {
826824
this._activeSession.lastExpansionState = this._zone.value.widget.expansionState;
827825
this._zone.value.widget.updateToolbar(true);
828826

829-
const canContinue = this._strategy.checkChanges(response);
830-
if (!canContinue) {
831-
return State.CANCEL;
832-
}
833827
await this._strategy.renderChanges(response);
834828
}
835829
this._showWidget(false);
836830

837831
return State.WAIT_FOR_INPUT;
838832
}
839833

840-
private async [State.PAUSE]() {
834+
private async[State.PAUSE]() {
841835

842836
this._ctxDidEdit.reset();
843837
this._ctxUserDidEdit.reset();
@@ -858,7 +852,7 @@ export class InlineChatController implements IEditorContribution {
858852
this._activeSession = undefined;
859853
}
860854

861-
private async [State.ACCEPT]() {
855+
private async[State.ACCEPT]() {
862856
assertType(this._activeSession);
863857
assertType(this._strategy);
864858
this._sessionStore.clear();
@@ -876,7 +870,7 @@ export class InlineChatController implements IEditorContribution {
876870
this[State.PAUSE]();
877871
}
878872

879-
private async [State.CANCEL]() {
873+
private async[State.CANCEL]() {
880874
assertType(this._activeSession);
881875
assertType(this._strategy);
882876
this._sessionStore.clear();

0 commit comments

Comments
 (0)