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

joh/boring lemming #185871

Merged
merged 2 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/vs/platform/actions/browser/buttonbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
export type IButtonConfigProvider = (action: IAction) => {
showIcon?: boolean;
showLabel?: boolean;
isSecondary?: boolean;
} | undefined;

export interface IMenuWorkbenchButtonBarOptions {
Expand Down Expand Up @@ -68,6 +69,7 @@ export class MenuWorkbenchButtonBar extends ButtonBar {
.flatMap(entry => entry[1]);

for (let i = 0; i < actions.length; i++) {

const secondary = i > 0;
const actionOrSubmenu = actions[i];
let action: MenuItemAction | SubmenuItemAction;
Expand All @@ -77,14 +79,16 @@ export class MenuWorkbenchButtonBar extends ButtonBar {
const [first, ...rest] = actionOrSubmenu.actions;
action = <MenuItemAction>first;
btn = this.addButtonWithDropdown({
secondary,
secondary: conifgProvider(action)?.isSecondary ?? secondary,
actionRunner,
actions: rest,
contextMenuProvider: contextMenuService,
});
} else {
action = actionOrSubmenu;
btn = this.addButton({ secondary });
btn = this.addButton({
secondary: conifgProvider(action)?.isSecondary ?? secondary,
});
}

btn.enabled = action.enabled;
Expand Down
10 changes: 3 additions & 7 deletions src/vs/workbench/contrib/inlineChat/browser/inlineChat.css
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
}

.monaco-editor .inline-chat .markdownMessage {
padding-top: 10px;
padding: 10px 5px;
}

.monaco-editor .inline-chat .markdownMessage.hidden {
Expand All @@ -155,7 +155,6 @@
}

.monaco-editor .inline-chat .markdownMessage .message {
margin-left: 5px;
-webkit-line-clamp: initial;
-webkit-box-orient: vertical;
overflow: hidden;
Expand All @@ -172,10 +171,6 @@
-webkit-line-clamp: var(--vscode-inline-chat-expanded, 10);
}

.monaco-editor .inline-chat .markdownMessage .messageActions {
direction: rtl;
}

.monaco-editor .inline-chat .status .label A {
color: var(--vscode-textLink-foreground);
cursor: pointer;
Expand Down Expand Up @@ -213,7 +208,8 @@
}

.monaco-editor .inline-chat .status .actions .monaco-text-button {
padding: 2px 4px
padding: 2px 4px;
white-space: nowrap;
}

.monaco-editor .inline-chat .status .monaco-toolbar .action-item {
Expand Down
23 changes: 12 additions & 11 deletions src/vs/workbench/contrib/inlineChat/browser/inlineChatActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { EditorAction2 } from 'vs/editor/browser/editorExtensions';
import { EmbeddedCodeEditorWidget, EmbeddedDiffEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { InlineChatController, InlineChatRunOptions } from 'vs/workbench/contrib/inlineChat/browser/inlineChatController';
import { CTX_INLINE_CHAT_FOCUSED, CTX_INLINE_CHAT_HAS_ACTIVE_REQUEST, CTX_INLINE_CHAT_HAS_PROVIDER, CTX_INLINE_CHAT_INNER_CURSOR_FIRST, CTX_INLINE_CHAT_INNER_CURSOR_LAST, CTX_INLINE_CHAT_EMPTY, CTX_INLINE_CHAT_OUTER_CURSOR_POSITION, CTX_INLINE_CHAT_VISIBLE, MENU_INLINE_CHAT_WIDGET, MENU_INLINE_CHAT_WIDGET_DISCARD, MENU_INLINE_CHAT_WIDGET_STATUS, CTX_INLINE_CHAT_LAST_FEEDBACK, CTX_INLINE_CHAT_SHOWING_DIFF, CTX_INLINE_CHAT_EDIT_MODE, EditMode, CTX_INLINE_CHAT_LAST_RESPONSE_TYPE, MENU_INLINE_CHAT_WIDGET_MARKDOWN_MESSAGE, CTX_INLINE_CHAT_MESSAGE_CROP_STATE, CTX_INLINE_CHAT_DOCUMENT_CHANGED, CTX_INLINE_CHAT_DID_EDIT, CTX_INLINE_CHAT_HAS_STASHED_SESSION, MENU_INLINE_CHAT_WIDGET_FEEDBACK, ACTION_ACCEPT_CHANGES, ACTION_REGENERATE_RESPONSE } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
import { CTX_INLINE_CHAT_FOCUSED, CTX_INLINE_CHAT_HAS_ACTIVE_REQUEST, CTX_INLINE_CHAT_HAS_PROVIDER, CTX_INLINE_CHAT_INNER_CURSOR_FIRST, CTX_INLINE_CHAT_INNER_CURSOR_LAST, CTX_INLINE_CHAT_EMPTY, CTX_INLINE_CHAT_OUTER_CURSOR_POSITION, CTX_INLINE_CHAT_VISIBLE, MENU_INLINE_CHAT_WIDGET, MENU_INLINE_CHAT_WIDGET_DISCARD, MENU_INLINE_CHAT_WIDGET_STATUS, CTX_INLINE_CHAT_LAST_FEEDBACK, CTX_INLINE_CHAT_SHOWING_DIFF, CTX_INLINE_CHAT_EDIT_MODE, EditMode, CTX_INLINE_CHAT_LAST_RESPONSE_TYPE, MENU_INLINE_CHAT_WIDGET_MARKDOWN_MESSAGE, CTX_INLINE_CHAT_MESSAGE_CROP_STATE, CTX_INLINE_CHAT_DOCUMENT_CHANGED, CTX_INLINE_CHAT_DID_EDIT, CTX_INLINE_CHAT_HAS_STASHED_SESSION, MENU_INLINE_CHAT_WIDGET_FEEDBACK, ACTION_ACCEPT_CHANGES, ACTION_REGENERATE_RESPONSE, InlineChatResponseType, CTX_INLINE_CHAT_RESPONSE_TYPES, InlineChateResponseTypes, ACTION_VIEW_IN_CHAT } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
import { localize } from 'vs/nls';
import { IAction2Options, MenuRegistry } from 'vs/platform/actions/common/actions';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
Expand Down Expand Up @@ -314,7 +314,7 @@ MenuRegistry.appendMenuItem(MENU_INLINE_CHAT_WIDGET_STATUS, {
icon: Codicon.discard,
group: '0_main',
order: 2,
when: CTX_INLINE_CHAT_EDIT_MODE.notEqualsTo(EditMode.Preview),
when: ContextKeyExpr.and(CTX_INLINE_CHAT_EDIT_MODE.notEqualsTo(EditMode.Preview), CTX_INLINE_CHAT_RESPONSE_TYPES.notEqualsTo(InlineChateResponseTypes.OnlyMessages)),
rememberDefaultAction: true
});

Expand Down Expand Up @@ -479,6 +479,7 @@ export class ApplyPreviewEdits extends AbstractInlineChatAction {
primary: KeyMod.CtrlCmd | KeyCode.Enter,
}],
menu: {
when: CTX_INLINE_CHAT_RESPONSE_TYPES.notEqualsTo(InlineChateResponseTypes.OnlyMessages),
id: MENU_INLINE_CHAT_WIDGET_STATUS,
group: '0_main',
order: 0
Expand All @@ -498,16 +499,16 @@ export class CancelSessionAction extends AbstractInlineChatAction {
id: 'inlineChat.cancel',
title: localize('cancel', 'Cancel'),
icon: Codicon.clearAll,
precondition: ContextKeyExpr.and(CTX_INLINE_CHAT_VISIBLE, CTX_INLINE_CHAT_EDIT_MODE.isEqualTo(EditMode.Preview)),
precondition: CTX_INLINE_CHAT_VISIBLE,
keybinding: {
weight: KeybindingWeight.EditorContrib - 1,
primary: KeyCode.Escape
},
menu: {
id: MENU_INLINE_CHAT_WIDGET_STATUS,
when: CTX_INLINE_CHAT_EDIT_MODE.isEqualTo(EditMode.Preview),
when: ContextKeyExpr.or(CTX_INLINE_CHAT_EDIT_MODE.isEqualTo(EditMode.Preview), CTX_INLINE_CHAT_RESPONSE_TYPES.isEqualTo(InlineChateResponseTypes.OnlyMessages)),
group: '0_main',
order: 1
order: 3
}
});
}
Expand Down Expand Up @@ -559,14 +560,14 @@ export class CopyRecordings extends AbstractInlineChatAction {
export class ViewInChatAction extends AbstractInlineChatAction {
constructor() {
super({
id: 'inlineChat.viewInChat',
id: ACTION_VIEW_IN_CHAT,
title: localize('viewInChat', 'View in Chat'),
icon: Codicon.commentDiscussion,
precondition: CTX_INLINE_CHAT_VISIBLE,
menu: {
id: MENU_INLINE_CHAT_WIDGET_MARKDOWN_MESSAGE,
when: CTX_INLINE_CHAT_LAST_RESPONSE_TYPE.isEqualTo('message'),
group: '1_viewInChat',
id: MENU_INLINE_CHAT_WIDGET_STATUS,
when: CTX_INLINE_CHAT_LAST_RESPONSE_TYPE.isEqualTo(InlineChatResponseType.Message),
group: '0_main',
order: 1
}
});
Expand All @@ -580,7 +581,7 @@ export class ExpandMessageAction extends AbstractInlineChatAction {
constructor() {
super({
id: 'inlineChat.expandMessageAction',
title: localize('expandMessage', 'Expand Message'),
title: localize('expandMessage', 'Show More'),
icon: Codicon.chevronDown,
precondition: CTX_INLINE_CHAT_VISIBLE,
menu: {
Expand All @@ -600,7 +601,7 @@ export class ContractMessageAction extends AbstractInlineChatAction {
constructor() {
super({
id: 'inlineChat.contractMessageAction',
title: localize('contractMessage', 'Contract Message'),
title: localize('contractMessage', 'Show Less'),
icon: Codicon.chevronUp,
precondition: CTX_INLINE_CHAT_VISIBLE,
menu: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { ILogService } from 'vs/platform/log/common/log';
import { EditResponse, EmptyResponse, ErrorResponse, ExpansionState, IInlineChatSessionService, MarkdownResponse, Session, SessionExchange, SessionPrompt } from 'vs/workbench/contrib/inlineChat/browser/inlineChatSession';
import { EditModeStrategy, LivePreviewStrategy, LiveStrategy, PreviewStrategy } from 'vs/workbench/contrib/inlineChat/browser/inlineChatStrategies';
import { InlineChatZoneWidget } from 'vs/workbench/contrib/inlineChat/browser/inlineChatWidget';
import { CTX_INLINE_CHAT_HAS_ACTIVE_REQUEST, CTX_INLINE_CHAT_LAST_FEEDBACK, IInlineChatRequest, IInlineChatResponse, INLINE_CHAT_ID, EditMode, InlineChatResponseFeedbackKind, CTX_INLINE_CHAT_LAST_RESPONSE_TYPE, InlineChatResponseType, CTX_INLINE_CHAT_DID_EDIT, CTX_INLINE_CHAT_HAS_STASHED_SESSION } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
import { CTX_INLINE_CHAT_HAS_ACTIVE_REQUEST, CTX_INLINE_CHAT_LAST_FEEDBACK, IInlineChatRequest, IInlineChatResponse, INLINE_CHAT_ID, EditMode, InlineChatResponseFeedbackKind, CTX_INLINE_CHAT_LAST_RESPONSE_TYPE, InlineChatResponseType, CTX_INLINE_CHAT_DID_EDIT, CTX_INLINE_CHAT_HAS_STASHED_SESSION, InlineChateResponseTypes, CTX_INLINE_CHAT_RESPONSE_TYPES } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
import { IChatWidgetService } from 'vs/workbench/contrib/chat/browser/chat';
import { IChatService } from 'vs/workbench/contrib/chat/common/chatService';
import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/services/notebookEditorService';
Expand Down Expand Up @@ -90,6 +90,7 @@ export class InlineChatController implements IEditorContribution {
private readonly _zone: Lazy<InlineChatZoneWidget>;
private readonly _ctxHasActiveRequest: IContextKey<boolean>;
private readonly _ctxLastResponseType: IContextKey<undefined | InlineChatResponseType>;
private readonly _ctxResponseTypes: IContextKey<undefined | InlineChateResponseTypes>;
private readonly _ctxDidEdit: IContextKey<boolean>;
private readonly _ctxLastFeedbackKind: IContextKey<'helpful' | 'unhelpful' | ''>;

Expand Down Expand Up @@ -117,6 +118,7 @@ export class InlineChatController implements IEditorContribution {
) {
this._ctxHasActiveRequest = CTX_INLINE_CHAT_HAS_ACTIVE_REQUEST.bindTo(contextKeyService);
this._ctxDidEdit = CTX_INLINE_CHAT_DID_EDIT.bindTo(contextKeyService);
this._ctxResponseTypes = CTX_INLINE_CHAT_RESPONSE_TYPES.bindTo(contextKeyService);
this._ctxLastResponseType = CTX_INLINE_CHAT_LAST_RESPONSE_TYPE.bindTo(contextKeyService);
this._ctxLastFeedbackKind = CTX_INLINE_CHAT_LAST_FEEDBACK.bindTo(contextKeyService);
this._zone = new Lazy(() => this._store.add(_instaService.createInstance(InlineChatZoneWidget, this._editor)));
Expand Down Expand Up @@ -598,6 +600,22 @@ export class InlineChatController implements IEditorContribution {
? response.raw.type
: undefined);

let responseTypes: InlineChateResponseTypes | undefined;
for (const { response } of this._activeSession.exchanges) {

const thisType = response instanceof MarkdownResponse
? InlineChateResponseTypes.OnlyMessages : response instanceof EditResponse
? InlineChateResponseTypes.OnlyEdits : undefined;

if (responseTypes === undefined) {
responseTypes = thisType;
} else if (responseTypes !== thisType) {
responseTypes = InlineChateResponseTypes.Mixed;
break;
}
}
this._ctxResponseTypes.set(responseTypes);

if (response instanceof EmptyResponse) {
// show status message
this._zone.value.widget.updateStatus(localize('empty', "No results, please refine your input and try again"), { classes: ['warn'] });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ export class Session {
this._teldata.rounds += `${newLen}|`;
}

get exchanges(): Iterable<SessionExchange> {
return this._exchange;
}

get lastExchange(): SessionExchange | undefined {
return this._exchange[this._exchange.length - 1];
}
Expand Down
12 changes: 7 additions & 5 deletions src/vs/workbench/contrib/inlineChat/browser/inlineChatWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { localize } from 'vs/nls';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ZoneWidget } from 'vs/editor/contrib/zoneWidget/browser/zoneWidget';
import { CTX_INLINE_CHAT_FOCUSED, CTX_INLINE_CHAT_INNER_CURSOR_FIRST, CTX_INLINE_CHAT_INNER_CURSOR_LAST, CTX_INLINE_CHAT_EMPTY, CTX_INLINE_CHAT_OUTER_CURSOR_POSITION, CTX_INLINE_CHAT_VISIBLE, MENU_INLINE_CHAT_WIDGET, MENU_INLINE_CHAT_WIDGET_STATUS, MENU_INLINE_CHAT_WIDGET_MARKDOWN_MESSAGE, CTX_INLINE_CHAT_MESSAGE_CROP_STATE, IInlineChatSlashCommand, MENU_INLINE_CHAT_WIDGET_FEEDBACK, ACTION_REGENERATE_RESPONSE } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
import { CTX_INLINE_CHAT_FOCUSED, CTX_INLINE_CHAT_INNER_CURSOR_FIRST, CTX_INLINE_CHAT_INNER_CURSOR_LAST, CTX_INLINE_CHAT_EMPTY, CTX_INLINE_CHAT_OUTER_CURSOR_POSITION, CTX_INLINE_CHAT_VISIBLE, MENU_INLINE_CHAT_WIDGET, MENU_INLINE_CHAT_WIDGET_STATUS, MENU_INLINE_CHAT_WIDGET_MARKDOWN_MESSAGE, CTX_INLINE_CHAT_MESSAGE_CROP_STATE, IInlineChatSlashCommand, MENU_INLINE_CHAT_WIDGET_FEEDBACK, ACTION_REGENERATE_RESPONSE, ACTION_VIEW_IN_CHAT } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
import { IModelDeltaDecoration, ITextModel } from 'vs/editor/common/model';
import { Dimension, addDisposableListener, getActiveElement, getTotalHeight, getTotalWidth, h, reset } from 'vs/base/browser/dom';
import { Emitter, Event, MicrotaskEmitter } from 'vs/base/common/event';
Expand Down Expand Up @@ -136,16 +136,16 @@ export class InlineChatWidget {
h('div.previewDiff.hidden@previewDiff'),
h('div.previewCreateTitle.show-file-icons@previewCreateTitle'),
h('div.previewCreate.hidden@previewCreate'),
h('div.markdownMessage.hidden@markdownMessage', [
h('div.message@message'),
h('div.messageActions@messageActions')
]),
h('div.status@status', [
h('div.label.info.hidden@infoLabel'),
h('div.actions.hidden@statusToolbar'),
h('div.label.status.hidden@statusLabel'),
h('div.actions.hidden@feedbackToolbar'),
]),
h('div.markdownMessage.hidden@markdownMessage', [
h('div.message@message'),
h('div.messageActions@messageActions')
]),
]
);

Expand Down Expand Up @@ -294,6 +294,8 @@ export class InlineChatWidget {
buttonConfigProvider: action => {
if (action.id === ACTION_REGENERATE_RESPONSE) {
return { showIcon: true, showLabel: false };
} else if (action.id === ACTION_VIEW_IN_CHAT) {
return { isSecondary: false };
}
return undefined;
}
Expand Down
8 changes: 8 additions & 0 deletions src/vs/workbench/contrib/inlineChat/common/inlineChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export const enum InlineChatResponseType {
Message = 'message'
}

export const enum InlineChateResponseTypes {
OnlyMessages = 'onlyMessages',
OnlyEdits = 'onlyEdits',
Mixed = 'mixed'
}

export interface IInlineChatEditResponse {
id: number;
type: InlineChatResponseType.EditorEdit;
Expand Down Expand Up @@ -114,6 +120,7 @@ export const CTX_INLINE_CHAT_HAS_ACTIVE_REQUEST = new RawContextKey<boolean>('in
export const CTX_INLINE_CHAT_HAS_STASHED_SESSION = new RawContextKey<boolean>('inlineChatHasStashedSession', false, localize('inlineChatHasStashedSession', "Whether interactive editor has kept a session for quick restore"));
export const CTX_INLINE_CHAT_SHOWING_DIFF = new RawContextKey<boolean>('inlineChatDiff', false, localize('inlineChatDiff', "Whether interactive editor show diffs for changes"));
export const CTX_INLINE_CHAT_LAST_RESPONSE_TYPE = new RawContextKey<InlineChatResponseType | undefined>('inlineChatLastResponseType', undefined, localize('inlineChatResponseType', "What type was the last response of the current interactive editor session"));
export const CTX_INLINE_CHAT_RESPONSE_TYPES = new RawContextKey<InlineChateResponseTypes | undefined>('inlineChatResponseTypes', undefined, localize('inlineChatResponseTypes', "What type was the responses have been receieved"));
export const CTX_INLINE_CHAT_DID_EDIT = new RawContextKey<boolean>('inlineChatDidEdit', false, localize('inlineChatDidEdit', "Whether interactive editor did change any code"));
export const CTX_INLINE_CHAT_LAST_FEEDBACK = new RawContextKey<'unhelpful' | 'helpful' | ''>('inlineChatLastFeedbackKind', '', localize('inlineChatLastFeedbackKind', "The last kind of feedback that was provided"));
export const CTX_INLINE_CHAT_DOCUMENT_CHANGED = new RawContextKey<boolean>('inlineChatDocumentChanged', false, localize('inlineChatDocumentChanged', "Whether the document has changed concurrently"));
Expand All @@ -123,6 +130,7 @@ export const CTX_INLINE_CHAT_EDIT_MODE = new RawContextKey<EditMode>('config.inl

export const ACTION_ACCEPT_CHANGES = 'interactive.acceptChanges';
export const ACTION_REGENERATE_RESPONSE = 'inlineChat.regenerate';
export const ACTION_VIEW_IN_CHAT = 'inlineChat.viewInChat';

// --- menus

Expand Down