Skip to content

Commit 2fce05e

Browse files
committed
initial code
1 parent d568855 commit 2fce05e

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { EditorAction2 } from 'vs/editor/browser/editorExtensions';
1010
import { EmbeddedCodeEditorWidget, EmbeddedDiffEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget';
1111
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
1212
import { InlineChatController, InlineChatRunOptions } from 'vs/workbench/contrib/inlineChat/browser/inlineChatController';
13-
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, CTX_INLINE_CHAT_USER_DID_EDIT } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
13+
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, CTX_INLINE_CHAT_USER_DID_EDIT, MENU_INLINE_CHAT_WIDGET_TOGGLE } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
1414
import { localize } from 'vs/nls';
1515
import { IAction2Options, MenuRegistry } from 'vs/platform/actions/common/actions';
1616
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
@@ -452,10 +452,10 @@ export class ToggleInlineDiff extends AbstractInlineChatAction {
452452
id: 'inlineChat.toggleDiff',
453453
title: localize('toggleDiff', 'Toggle Diff'),
454454
icon: Codicon.diff,
455-
precondition: ContextKeyExpr.and(CTX_INLINE_CHAT_VISIBLE, CTX_INLINE_CHAT_DID_EDIT),
455+
precondition: ContextKeyExpr.and(CTX_INLINE_CHAT_VISIBLE),
456456
toggled: { condition: CTX_INLINE_CHAT_SHOWING_DIFF, title: localize('toggleDiff2', "Show Inline Diff") },
457457
menu: {
458-
id: MENU_INLINE_CHAT_WIDGET_DISCARD,
458+
id: MENU_INLINE_CHAT_WIDGET_TOGGLE,
459459
when: CTX_INLINE_CHAT_EDIT_MODE.notEqualsTo(EditMode.Preview),
460460
group: '1_config',
461461
order: 9

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { Event } from 'vs/base/common/event';
77
import { Lazy } from 'vs/base/common/lazy';
8-
import { IDisposable } from 'vs/base/common/lifecycle';
8+
import { DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
99
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
1010
import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
1111
import { StableEditorScrollState } from 'vs/editor/browser/stableEditorScroll';
@@ -17,9 +17,10 @@ import { IEditorDecorationsCollection } from 'vs/editor/common/editorCommon';
1717
import { ICursorStateComputer, IModelDecorationOptions, IModelDeltaDecoration, ITextModel, IValidEditOperation } from 'vs/editor/common/model';
1818
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorker';
1919
import { localize } from 'vs/nls';
20+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2021
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
2122
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
22-
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
23+
import { IStorageService } from 'vs/platform/storage/common/storage';
2324
import { InlineChatFileCreatePreviewWidget, InlineChatLivePreviewWidget } from 'vs/workbench/contrib/inlineChat/browser/inlineChatLivePreviewWidget';
2425
import { EditResponse, Session } from 'vs/workbench/contrib/inlineChat/browser/inlineChatSession';
2526
import { InlineChatWidget } from 'vs/workbench/contrib/inlineChat/browser/inlineChatWidget';
@@ -222,11 +223,12 @@ class InlineDiffDecorations {
222223

223224
export class LiveStrategy extends EditModeStrategy {
224225

225-
private static _inlineDiffStorageKey: string = 'interactiveEditor.storage.inlineDiff';
226226
protected _diffEnabled: boolean = false;
227227

228228
private readonly _inlineDiffDecorations: InlineDiffDecorations;
229229
private readonly _ctxShowingDiff: IContextKey<boolean>;
230+
private readonly _store: DisposableStore = new DisposableStore();
231+
230232
private _lastResponse?: EditResponse;
231233
private _editCount: number = 0;
232234

@@ -235,29 +237,36 @@ export class LiveStrategy extends EditModeStrategy {
235237
protected readonly _editor: ICodeEditor,
236238
protected readonly _widget: InlineChatWidget,
237239
@IContextKeyService contextKeyService: IContextKeyService,
240+
@IConfigurationService configService: IConfigurationService,
238241
@IStorageService protected _storageService: IStorageService,
239242
@IBulkEditService protected readonly _bulkEditService: IBulkEditService,
240243
@IEditorWorkerService protected readonly _editorWorkerService: IEditorWorkerService,
241244
@IInstantiationService private readonly _instaService: IInstantiationService,
242245
) {
243246
super();
244-
this._diffEnabled = _storageService.getBoolean(LiveStrategy._inlineDiffStorageKey, StorageScope.PROFILE, true);
247+
this._diffEnabled = configService.getValue<boolean>('inlineChat.showDiff');
245248

246249
this._inlineDiffDecorations = new InlineDiffDecorations(this._editor, this._diffEnabled);
247250
this._ctxShowingDiff = CTX_INLINE_CHAT_SHOWING_DIFF.bindTo(contextKeyService);
248251
this._ctxShowingDiff.set(this._diffEnabled);
249252
this._inlineDiffDecorations.visible = this._diffEnabled;
253+
254+
this._store.add(configService.onDidChangeConfiguration(e => {
255+
if (e.affectsConfiguration('inlineChat.showDiff')) {
256+
this.toggleDiff();
257+
}
258+
}));
250259
}
251260

252261
override dispose(): void {
253262
this._inlineDiffDecorations.clear();
254263
this._ctxShowingDiff.reset();
264+
this._store.dispose();
255265
}
256266

257267
toggleDiff(): void {
258268
this._diffEnabled = !this._diffEnabled;
259269
this._ctxShowingDiff.set(this._diffEnabled);
260-
this._storageService.store(LiveStrategy._inlineDiffStorageKey, this._diffEnabled, StorageScope.PROFILE, StorageTarget.USER);
261270
this._doToggleDiff();
262271
}
263272

@@ -384,12 +393,13 @@ export class LivePreviewStrategy extends LiveStrategy {
384393
editor: ICodeEditor,
385394
widget: InlineChatWidget,
386395
@IContextKeyService contextKeyService: IContextKeyService,
396+
@IConfigurationService configService: IConfigurationService,
387397
@IStorageService storageService: IStorageService,
388398
@IBulkEditService bulkEditService: IBulkEditService,
389399
@IEditorWorkerService editorWorkerService: IEditorWorkerService,
390400
@IInstantiationService instaService: IInstantiationService,
391401
) {
392-
super(session, editor, widget, contextKeyService, storageService, bulkEditService, editorWorkerService, instaService);
402+
super(session, editor, widget, contextKeyService, configService, storageService, bulkEditService, editorWorkerService, instaService);
393403

394404
this._diffZone = new Lazy(() => instaService.createInstance(InlineChatLivePreviewWidget, editor, session));
395405
this._previewZone = new Lazy(() => instaService.createInstance(InlineChatFileCreatePreviewWidget, editor));

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import { localize } from 'vs/nls';
1212
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1313
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1414
import { ZoneWidget } from 'vs/editor/contrib/zoneWidget/browser/zoneWidget';
15-
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';
15+
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, MENU_INLINE_CHAT_WIDGET_TOGGLE } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
1616
import { IModelDeltaDecoration, ITextModel } from 'vs/editor/common/model';
17-
import { Dimension, addDisposableListener, getActiveElement, getTotalHeight, getTotalWidth, h, reset } from 'vs/base/browser/dom';
17+
import { EventType, Dimension, addDisposableListener, getActiveElement, getTotalHeight, getTotalWidth, h, reset } from 'vs/base/browser/dom';
1818
import { Emitter, Event, MicrotaskEmitter } from 'vs/base/common/event';
1919
import { IEditorConstructionOptions } from 'vs/editor/browser/config/editorConfiguration';
2020
import { ICodeEditorWidgetOptions } from 'vs/editor/browser/widget/codeEditorWidget';
@@ -49,6 +49,7 @@ import { ExpansionState } from 'vs/workbench/contrib/inlineChat/browser/inlineCh
4949
import { IdleValue } from 'vs/base/common/async';
5050
import * as aria from 'vs/base/browser/ui/aria/aria';
5151
import { IMenuWorkbenchButtonBarOptions, MenuWorkbenchButtonBar } from 'vs/platform/actions/browser/buttonbar';
52+
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
5253

5354
const defaultAriaLabel = localize('aria-label', "Inline Chat Input");
5455

@@ -189,7 +190,8 @@ export class InlineChatWidget {
189190
@IKeybindingService private readonly _keybindingService: IKeybindingService,
190191
@IInstantiationService private readonly _instantiationService: IInstantiationService,
191192
@IAccessibilityService private readonly _accessibilityService: IAccessibilityService,
192-
@IConfigurationService private readonly _configurationService: IConfigurationService
193+
@IConfigurationService private readonly _configurationService: IConfigurationService,
194+
@IContextMenuService private readonly _contextMenuService: IContextMenuService,
193195
) {
194196

195197
// input editor logic
@@ -328,6 +330,17 @@ export class InlineChatWidget {
328330
const markdownMessageToolbar = this._instantiationService.createInstance(MenuWorkbenchToolBar, this._elements.messageActions, MENU_INLINE_CHAT_WIDGET_MARKDOWN_MESSAGE, workbenchToolbarOptions);
329331
this._store.add(markdownMessageToolbar.onDidChangeMenuItems(() => this._onDidChangeHeight.fire()));
330332
this._store.add(markdownMessageToolbar);
333+
334+
this._store.add(addDisposableListener(this._elements.root, EventType.CONTEXT_MENU, async (event: MouseEvent) => {
335+
this.onContextMenu(event);
336+
}));
337+
}
338+
339+
private onContextMenu(event: MouseEvent) {
340+
this._contextMenuService.showContextMenu({
341+
menuId: MENU_INLINE_CHAT_WIDGET_TOGGLE,
342+
getAnchor: () => event,
343+
});
331344
}
332345

333346
private _updateAriaLabel(): void {

src/vs/workbench/contrib/inlineChat/common/inlineChat.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export const MENU_INLINE_CHAT_WIDGET_MARKDOWN_MESSAGE = MenuId.for('inlineChatWi
140140
export const MENU_INLINE_CHAT_WIDGET_STATUS = MenuId.for('inlineChatWidget.status');
141141
export const MENU_INLINE_CHAT_WIDGET_FEEDBACK = MenuId.for('inlineChatWidget.feedback');
142142
export const MENU_INLINE_CHAT_WIDGET_DISCARD = MenuId.for('inlineChatWidget.undo');
143+
export const MENU_INLINE_CHAT_WIDGET_TOGGLE = MenuId.for('inlineChatWidget.toggle');
143144

144145
// --- colors
145146

@@ -188,3 +189,14 @@ Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfigurat
188189
}
189190
}
190191
});
192+
193+
Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfiguration({
194+
id: 'editor',
195+
properties: {
196+
'inlineChat.showDiff': {
197+
description: localize('showDiff', "Enable/disable showing the diff when edits are generated."),
198+
default: true,
199+
type: 'boolean'
200+
}
201+
}
202+
});

0 commit comments

Comments
 (0)