Skip to content

Commit

Permalink
Safer fix for 239274 (#239511)
Browse files Browse the repository at this point in the history
* Revert "fix config-context-key handling when config isn't known yet (#239294)"

This reverts commit d231e6c.

* Ensure agentModeDisallowed key always changes when setting is registered
  • Loading branch information
roblourens authored Feb 3, 2025
1 parent a4815c3 commit 14270fe
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 18 deletions.
11 changes: 1 addition & 10 deletions src/vs/platform/contextkey/browser/contextKeyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class ConfigAwareContextValuesContainer extends Context {
private static readonly _keyPrefix = 'config.';

private readonly _values = TernarySearchTree.forConfigKeys<any>();
private readonly _missed = TernarySearchTree.forConfigKeys<boolean>();
private readonly _listener: IDisposable;

constructor(
Expand All @@ -118,10 +117,7 @@ class ConfigAwareContextValuesContainer extends Context {
// new setting, reset everything
const allKeys = Array.from(this._values, ([k]) => k);
this._values.clear();
emitter.fire(new CompositeContextKeyChangeEvent([
new ArrayContextKeyChangeEvent(allKeys),
new ArrayContextKeyChangeEvent(Array.from(this._missed, ([k]) => k))
]));
emitter.fire(new ArrayContextKeyChangeEvent(allKeys));
} else {
const changedKeys: string[] = [];
for (const configKey of event.affectedKeys) {
Expand Down Expand Up @@ -176,11 +172,6 @@ class ConfigAwareContextValuesContainer extends Context {
}

this._values.set(key, value);
if (value === undefined) {
this._missed.set(key, true);
} else {
this._missed.delete(key);
}
return value;
}

Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/chat/browser/chat.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ class ChatAgentSettingContribution implements IWorkbenchContribution {
this.registerSetting();
} else if (value === false) {
this.deregisterSetting();
expDisabledKey.set(true);
}
expDisabledKey.set(!value);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ export class LanguageModelToolsService extends Disposable implements ILanguageMo
this._tools.set(toolData.id, { data: toolData });
this._onDidChangeToolsScheduler.schedule();

if (toolData.when) {
this._contextKeyService.contextMatchesRules(toolData.when);
toolData.when.keys().forEach(key => this._toolContextKeys.add(key));
}
toolData.when?.keys().forEach(key => this._toolContextKeys.add(key));

return toDisposable(() => {
this._tools.delete(toolData.id);
Expand Down
2 changes: 0 additions & 2 deletions src/vs/workbench/contrib/chat/common/chatAgents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,6 @@ export class ChatAgentService extends Disposable implements IChatAgentService {
this._agents.set(id, entry);
this._updateAgentsContextKeys();
this._updateContextKeys();
this._agentIsEnabled(entry);

this._onDidChangeAgents.fire(undefined);

return toDisposable(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/chat/common/chatContextKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ export namespace ChatContextKeys {
export const Editing = {
hasToolsAgent: new RawContextKey<boolean>('chatHasToolsAgent', false, { type: 'boolean', description: localize('chatEditingHasToolsAgent', "True when a tools agent is registered.") }),
agentMode: new RawContextKey<boolean>('chatAgentMode', false, { type: 'boolean', description: localize('chatEditingAgentMode', "True when edits is in agent mode.") }),
agentModeDisallowed: new RawContextKey<boolean>('chatAgentModeDisallowed', false, { type: 'boolean', description: localize('chatAgentModeDisallowed', "True when agent mode is not allowed.") }), // experiment-driven disablement
agentModeDisallowed: new RawContextKey<boolean>('chatAgentModeDisallowed', undefined, { type: 'boolean', description: localize('chatAgentModeDisallowed', "True when agent mode is not allowed.") }), // experiment-driven disablement
};
}

0 comments on commit 14270fe

Please sign in to comment.