Skip to content

Commit

Permalink
fix config-context-key handling when config isn't known yet (#239294)
Browse files Browse the repository at this point in the history
* make sure to "read" when-clause of tools and agents as soon as registered
* make sure to record config-context-keys that don't exist yet
  • Loading branch information
jrieken authored Jan 31, 2025
1 parent 5bd0584 commit d231e6c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/vs/platform/contextkey/browser/contextKeyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ 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 @@ -117,7 +118,10 @@ class ConfigAwareContextValuesContainer extends Context {
// new setting, reset everything
const allKeys = Array.from(this._values, ([k]) => k);
this._values.clear();
emitter.fire(new ArrayContextKeyChangeEvent(allKeys));
emitter.fire(new CompositeContextKeyChangeEvent([
new ArrayContextKeyChangeEvent(allKeys),
new ArrayContextKeyChangeEvent(Array.from(this._missed, ([k]) => k))
]));
} else {
const changedKeys: string[] = [];
for (const configKey of event.affectedKeys) {
Expand Down Expand Up @@ -172,6 +176,11 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ export class LanguageModelToolsService extends Disposable implements ILanguageMo
this._tools.set(toolData.id, { data: toolData });
this._onDidChangeToolsScheduler.schedule();

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

return toDisposable(() => {
this._tools.delete(toolData.id);
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/contrib/chat/common/chatAgents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ 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

0 comments on commit d231e6c

Please sign in to comment.