Skip to content

Commit

Permalink
feat: allow to configure implicit context enablement in chat and edits (
Browse files Browse the repository at this point in the history
  • Loading branch information
joyceerhl authored Feb 24, 2025
1 parent 434ebfb commit a0055ca
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/vs/workbench/contrib/chat/browser/chat.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,25 @@ configurationRegistry.registerConfiguration({
markdownDescription: nls.localize('chat.commandCenter.enabled', "Controls whether the command center shows a menu for actions to control Copilot (requires {0}).", '`#window.commandCenter#`'),
default: true
},
'chat.implicitContext.enabled': {
type: 'object',
tags: ['experimental'],
description: nls.localize('chat.implicitContext.enabled', "Enables the implicit context widget for specified chat locations."),
additionalProperties: {
type: 'string',
enum: ['never', 'first', 'always'],
description: nls.localize('chat.implicitContext.value', "The value for the implicit context."),
enumDescriptions: [
nls.localize('chat.implicitContext.value.never', "Implicit context is never enabled."),
nls.localize('chat.implicitContext.value.first', "Implicit context is enabled for the first interaction."),
nls.localize('chat.implicitContext.value.always', "Implicit context is always enabled.")
]
},
default: {
'panel': 'always',
'editing-session': 'first'
}
},
'chat.editing.autoAcceptDelay': {
type: 'number',
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."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { URI } from '../../../../../base/common/uri.js';
import { ICodeEditor, isCodeEditor, isDiffEditor } from '../../../../../editor/browser/editorBrowser.js';
import { ICodeEditorService } from '../../../../../editor/browser/services/codeEditorService.js';
import { Location } from '../../../../../editor/common/languages.js';
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
import { IWorkbenchContribution } from '../../../../common/contributions.js';
import { EditorsOrder } from '../../../../common/editor.js';
import { IEditorService } from '../../../../services/editor/common/editorService.js';
Expand All @@ -27,17 +28,21 @@ export class ChatImplicitContextContribution extends Disposable implements IWork

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

private _implicitContextEnablement = this.configurationService.getValue<{ [mode: string]: string }>('chat.implicitContext.enabled');

constructor(
@ICodeEditorService private readonly codeEditorService: ICodeEditorService,
@IEditorService private readonly editorService: IEditorService,
@IChatWidgetService private readonly chatWidgetService: IChatWidgetService,
@IChatService private readonly chatService: IChatService,
@IChatEditingService private readonly chatEditingService: IChatEditingService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@ILanguageModelIgnoredFilesService private readonly ignoredFilesService: ILanguageModelIgnoredFilesService,
) {
super();

const activeEditorDisposables = this._register(new DisposableStore());

this._register(Event.runAndSubscribe(
editorService.onDidVisibleEditorsChange,
(() => {
Expand All @@ -59,9 +64,18 @@ export class ChatImplicitContextContribution extends Disposable implements IWork
this.chatEditingService.editingSessionsObs.read(reader);
this.updateImplicitContext();
}));
this._register(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('chat.implicitContext.enabled')) {
this._implicitContextEnablement = this.configurationService.getValue<{ [mode: string]: string }>('chat.implicitContext.enabled');
this.updateImplicitContext();
}
}));
this._register(this.chatService.onDidSubmitRequest(({ chatSessionId }) => {
const widget = this.chatWidgetService.getWidgetBySessionId(chatSessionId);
if (widget?.input.implicitContext && widget.location === ChatAgentLocation.EditingSession && widget.viewModel?.getItems().length !== 0) {
if (!widget?.input.implicitContext) {
return;
}
if (this._implicitContextEnablement[widget.location] === 'first' && widget.viewModel?.getItems().length !== 0) {
widget.input.implicitContext.setValue(undefined, false);
}
}));
Expand Down Expand Up @@ -131,10 +145,17 @@ export class ChatImplicitContextContribution extends Disposable implements IWork

const widgets = updateWidget ? [updateWidget] : [...this.chatWidgetService.getWidgetsByLocations(ChatAgentLocation.Panel), ...this.chatWidgetService.getWidgetsByLocations(ChatAgentLocation.EditingSession), ...this.chatWidgetService.getWidgetsByLocations(ChatAgentLocation.Editor)];
for (const widget of widgets) {
if (widget.input.implicitContext && widget.location === ChatAgentLocation.EditingSession && widget.viewModel?.getItems().length !== 0) {
if (!widget.input.implicitContext) {
continue;
}
const setting = this._implicitContextEnablement[widget.location];
const isFirstInteraction = widget.viewModel?.getItems().length === 0;
if (setting === 'first' && !isFirstInteraction) {
widget.input.implicitContext.setValue(undefined, false);
} else if (widget.input.implicitContext) {
} else if (setting === 'always' || setting === 'first' && isFirstInteraction) {
widget.input.implicitContext.setValue(newValue, isSelection);
} else if (setting === 'never') {
widget.input.implicitContext.setValue(undefined, false);
}
}
}
Expand Down

0 comments on commit a0055ca

Please sign in to comment.