Skip to content

Commit a0055ca

Browse files
authored
feat: allow to configure implicit context enablement in chat and edits (#241752)
1 parent 434ebfb commit a0055ca

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,25 @@ configurationRegistry.registerConfiguration({
137137
markdownDescription: nls.localize('chat.commandCenter.enabled', "Controls whether the command center shows a menu for actions to control Copilot (requires {0}).", '`#window.commandCenter#`'),
138138
default: true
139139
},
140+
'chat.implicitContext.enabled': {
141+
type: 'object',
142+
tags: ['experimental'],
143+
description: nls.localize('chat.implicitContext.enabled', "Enables the implicit context widget for specified chat locations."),
144+
additionalProperties: {
145+
type: 'string',
146+
enum: ['never', 'first', 'always'],
147+
description: nls.localize('chat.implicitContext.value', "The value for the implicit context."),
148+
enumDescriptions: [
149+
nls.localize('chat.implicitContext.value.never', "Implicit context is never enabled."),
150+
nls.localize('chat.implicitContext.value.first', "Implicit context is enabled for the first interaction."),
151+
nls.localize('chat.implicitContext.value.always', "Implicit context is always enabled.")
152+
]
153+
},
154+
default: {
155+
'panel': 'always',
156+
'editing-session': 'first'
157+
}
158+
},
140159
'chat.editing.autoAcceptDelay': {
141160
type: 'number',
142161
markdownDescription: nls.localize('chat.editing.autoAcceptDelay', "Delay after which changes made by chat are automatically accepted. Values are in seconds, `0` means disabled and `100` seconds is the maximum."),

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { URI } from '../../../../../base/common/uri.js';
1212
import { ICodeEditor, isCodeEditor, isDiffEditor } from '../../../../../editor/browser/editorBrowser.js';
1313
import { ICodeEditorService } from '../../../../../editor/browser/services/codeEditorService.js';
1414
import { Location } from '../../../../../editor/common/languages.js';
15+
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
1516
import { IWorkbenchContribution } from '../../../../common/contributions.js';
1617
import { EditorsOrder } from '../../../../common/editor.js';
1718
import { IEditorService } from '../../../../services/editor/common/editorService.js';
@@ -27,17 +28,21 @@ export class ChatImplicitContextContribution extends Disposable implements IWork
2728

2829
private readonly _currentCancelTokenSource = this._register(new MutableDisposable<CancellationTokenSource>());
2930

31+
private _implicitContextEnablement = this.configurationService.getValue<{ [mode: string]: string }>('chat.implicitContext.enabled');
32+
3033
constructor(
3134
@ICodeEditorService private readonly codeEditorService: ICodeEditorService,
3235
@IEditorService private readonly editorService: IEditorService,
3336
@IChatWidgetService private readonly chatWidgetService: IChatWidgetService,
3437
@IChatService private readonly chatService: IChatService,
3538
@IChatEditingService private readonly chatEditingService: IChatEditingService,
39+
@IConfigurationService private readonly configurationService: IConfigurationService,
3640
@ILanguageModelIgnoredFilesService private readonly ignoredFilesService: ILanguageModelIgnoredFilesService,
3741
) {
3842
super();
3943

4044
const activeEditorDisposables = this._register(new DisposableStore());
45+
4146
this._register(Event.runAndSubscribe(
4247
editorService.onDidVisibleEditorsChange,
4348
(() => {
@@ -59,9 +64,18 @@ export class ChatImplicitContextContribution extends Disposable implements IWork
5964
this.chatEditingService.editingSessionsObs.read(reader);
6065
this.updateImplicitContext();
6166
}));
67+
this._register(this.configurationService.onDidChangeConfiguration(e => {
68+
if (e.affectsConfiguration('chat.implicitContext.enabled')) {
69+
this._implicitContextEnablement = this.configurationService.getValue<{ [mode: string]: string }>('chat.implicitContext.enabled');
70+
this.updateImplicitContext();
71+
}
72+
}));
6273
this._register(this.chatService.onDidSubmitRequest(({ chatSessionId }) => {
6374
const widget = this.chatWidgetService.getWidgetBySessionId(chatSessionId);
64-
if (widget?.input.implicitContext && widget.location === ChatAgentLocation.EditingSession && widget.viewModel?.getItems().length !== 0) {
75+
if (!widget?.input.implicitContext) {
76+
return;
77+
}
78+
if (this._implicitContextEnablement[widget.location] === 'first' && widget.viewModel?.getItems().length !== 0) {
6579
widget.input.implicitContext.setValue(undefined, false);
6680
}
6781
}));
@@ -131,10 +145,17 @@ export class ChatImplicitContextContribution extends Disposable implements IWork
131145

132146
const widgets = updateWidget ? [updateWidget] : [...this.chatWidgetService.getWidgetsByLocations(ChatAgentLocation.Panel), ...this.chatWidgetService.getWidgetsByLocations(ChatAgentLocation.EditingSession), ...this.chatWidgetService.getWidgetsByLocations(ChatAgentLocation.Editor)];
133147
for (const widget of widgets) {
134-
if (widget.input.implicitContext && widget.location === ChatAgentLocation.EditingSession && widget.viewModel?.getItems().length !== 0) {
148+
if (!widget.input.implicitContext) {
149+
continue;
150+
}
151+
const setting = this._implicitContextEnablement[widget.location];
152+
const isFirstInteraction = widget.viewModel?.getItems().length === 0;
153+
if (setting === 'first' && !isFirstInteraction) {
135154
widget.input.implicitContext.setValue(undefined, false);
136-
} else if (widget.input.implicitContext) {
155+
} else if (setting === 'always' || setting === 'first' && isFirstInteraction) {
137156
widget.input.implicitContext.setValue(newValue, isSelection);
157+
} else if (setting === 'never') {
158+
widget.input.implicitContext.setValue(undefined, false);
138159
}
139160
}
140161
}

0 commit comments

Comments
 (0)