Skip to content

Commit 7a3a29f

Browse files
authored
Assorted inline chat fixes (microsoft#208769)
* fix/workaround microsoft#208549 * fixes microsoft#208656 * add minHeight to inline chat widget fixes microsoft/vscode-copilot#4770 * fixes microsoft#208606 * only honor `refer` flag when its command is the first and only fixes microsoft#208574
1 parent 4a6ebe0 commit 7a3a29f

File tree

6 files changed

+41
-14
lines changed

6 files changed

+41
-14
lines changed

src/vs/workbench/contrib/chat/browser/chatInputPart.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
326326
// Only allow history navigation when the input is empty.
327327
// (If this model change happened as a result of a history navigation, this is canceled out by a call in this.navigateHistory)
328328
const model = this._inputEditor.getModel();
329-
const inputHasText = !!model && model.getValueLength() > 0;
329+
const inputHasText = !!model && model.getValue().trim().length > 0;
330330
this.inputEditorHasText.set(inputHasText);
331331

332332
// If the user is typing on a history entry, then reset the onHistoryEntry flag so that history navigation can be disabled

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { ChatAgentLocation } from 'vs/workbench/contrib/chat/common/chatAgents';
2020
import { editorBackground, editorForeground, inputBackground } from 'vs/platform/theme/common/colorRegistry';
2121
import { ChatModel } from 'vs/workbench/contrib/chat/common/chatModel';
2222
import { Range } from 'vs/editor/common/core/range';
23+
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
24+
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
2325

2426
export class InlineChatContentWidget implements IContentWidget {
2527

@@ -45,11 +47,19 @@ export class InlineChatContentWidget implements IContentWidget {
4547
constructor(
4648
private readonly _editor: ICodeEditor,
4749
@IInstantiationService instaService: IInstantiationService,
50+
@IContextKeyService contextKeyService: IContextKeyService,
4851
) {
4952

5053
this._defaultChatModel = this._store.add(instaService.createInstance(ChatModel, `inlineChatDefaultModel/editorContentWidgetPlaceholder`, undefined));
5154

52-
this._widget = instaService.createInstance(
55+
const scopedInstaService = instaService.createChild(
56+
new ServiceCollection([
57+
IContextKeyService,
58+
this._store.add(contextKeyService.createScoped(this._domNode))
59+
])
60+
);
61+
62+
this._widget = scopedInstaService.createInstance(
5363
ChatWidget,
5464
ChatAgentLocation.Editor,
5565
{ resource: true },

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ export class InlineChatController implements IEditorContribution {
606606
}
607607
return false;
608608
});
609-
if (refer && slashCommandLike) {
609+
if (refer && slashCommandLike && !this._session.lastExchange) {
610610
this._log('[IE] seeing refer command, continuing outside editor', this._session.provider.extensionId);
611611

612612
// cancel this request
@@ -627,11 +627,7 @@ export class InlineChatController implements IEditorContribution {
627627
// if agent has a refer command, massage the input to include the agent name
628628
await this._instaService.invokeFunction(sendRequest, massagedInput);
629629

630-
if (!this._session.lastExchange) {
631-
// DONE when there wasn't any exchange yet. We used the inline chat only as trampoline
632-
return State.ACCEPT;
633-
}
634-
return State.WAIT_FOR_INPUT;
630+
return State.ACCEPT;
635631
}
636632

637633
this._session.addInput(new SessionPrompt(input, this._nextAttempt, this._nextWithIntentDetection));

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { SuggestController } from 'vs/editor/contrib/suggest/browser/suggestCont
5454
import { IChatService } from 'vs/workbench/contrib/chat/common/chatService';
5555
import { setupCustomHover } from 'vs/base/browser/ui/hover/updatableHoverWidget';
5656
import { getDefaultHoverDelegate } from 'vs/base/browser/ui/hover/hoverDelegateFactory';
57+
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
5758

5859

5960
export interface InlineChatWidgetViewState {
@@ -174,7 +175,16 @@ export class InlineChatWidget {
174175
this._store.add(this._progressBar);
175176

176177
let allowRequests = false;
177-
this._chatWidget = _instantiationService.createInstance(
178+
179+
180+
const scopedInstaService = _instantiationService.createChild(
181+
new ServiceCollection([
182+
IContextKeyService,
183+
this._store.add(_contextKeyService.createScoped(this._elements.chatWidget))
184+
])
185+
);
186+
187+
this._chatWidget = scopedInstaService.createInstance(
178188
ChatWidget,
179189
location,
180190
{ resource: true },
@@ -365,16 +375,24 @@ export class InlineChatWidget {
365375
get contentHeight(): number {
366376
const data = {
367377
followUpsHeight: getTotalHeight(this._elements.followUps),
368-
chatWidgetHeight: this._chatWidget.contentHeight,
378+
chatWidgetContentHeight: this._chatWidget.contentHeight,
369379
progressHeight: getTotalHeight(this._elements.progress),
370380
statusHeight: getTotalHeight(this._elements.status),
371381
extraHeight: this._getExtraHeight()
372382
};
373-
const result = data.progressHeight + data.chatWidgetHeight + data.followUpsHeight + data.statusHeight + data.extraHeight;
374-
// console.log(`InlineChat#contentHeight ${result}`, data);
383+
const result = data.progressHeight + data.chatWidgetContentHeight + data.followUpsHeight + data.statusHeight + data.extraHeight;
375384
return result;
376385
}
377386

387+
get minHeight(): number {
388+
// The chat widget is variable height and supports scrolling. It
389+
// should be at least 100px high and at most the content height.
390+
let value = this.contentHeight;
391+
value -= this._chatWidget.contentHeight;
392+
value += Math.min(100, this._chatWidget.contentHeight);
393+
return value;
394+
}
395+
378396
protected _getExtraHeight(): number {
379397
return 12 /* padding */ + 2 /*border*/ + 12 /*shadow*/;
380398
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,8 @@ export class InlineChatZoneWidget extends ZoneWidget {
114114
const chatContentHeight = this.widget.contentHeight;
115115
const editorHeight = this.editor.getLayoutInfo().height;
116116

117-
const contentHeight = Math.min(chatContentHeight, editorHeight * 0.42);
117+
const contentHeight = Math.min(chatContentHeight, Math.max(this.widget.minHeight, editorHeight * 0.42));
118118
const heightInLines = contentHeight / this.editor.getOption(EditorOption.lineHeight);
119-
// console.log('ZONE#_computeHeightInLines', { chatContentHeight, editorHeight, contentHeight, heightInLines });
120119
return heightInLines;
121120
}
122121

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
z-index: 3;
88
}
99

10+
.monaco-workbench .zone-widget.inline-chat-widget .interactive-session {
11+
max-width: unset;
12+
}
13+
1014
.monaco-workbench .zone-widget-container.inside-selection {
1115
background-color: var(--vscode-inlineChat-regionHighlight);
1216
}

0 commit comments

Comments
 (0)