Skip to content

Commit 89ba12c

Browse files
authored
simplify dynamic variables, no more unused chat file reference fyi @aeschli (microsoft#251273)
1 parent e680d23 commit 89ba12c

File tree

1 file changed

+9
-33
lines changed

1 file changed

+9
-33
lines changed

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

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,23 @@ import { IDecorationOptions } from '../../../../../editor/common/editorCommon.js
1212
import { Command, isLocation } from '../../../../../editor/common/languages.js';
1313
import { Action2, registerAction2 } from '../../../../../platform/actions/common/actions.js';
1414
import { ICommandService } from '../../../../../platform/commands/common/commands.js';
15-
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
16-
import { IInstantiationService, ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js';
15+
import { ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js';
1716
import { ILabelService } from '../../../../../platform/label/common/label.js';
1817
import { IChatRequestVariableValue, IDynamicVariable } from '../../common/chatVariables.js';
19-
import { PromptsConfig } from '../../common/promptSyntax/config/config.js';
2018
import { IChatWidget } from '../chat.js';
2119
import { IChatWidgetContrib } from '../chatWidget.js';
2220
import { ChatFileReference } from './chatDynamicVariables/chatFileReference.js';
2321

2422
export const dynamicVariableDecorationType = 'chat-dynamic-variable';
2523

26-
/**
27-
* Type of dynamic variables. Can be either a file reference or
28-
* another dynamic variable (e.g., a `#sym`, `#kb`, etc.).
29-
*/
30-
type TDynamicVariable = IDynamicVariable | ChatFileReference;
24+
3125

3226
export class ChatDynamicVariableModel extends Disposable implements IChatWidgetContrib {
3327
public static readonly ID = 'chatDynamicVariableModel';
3428

35-
private _variables: TDynamicVariable[] = [];
36-
get variables(): ReadonlyArray<TDynamicVariable> {
29+
private _variables: IDynamicVariable[] = [];
30+
31+
get variables(): ReadonlyArray<IDynamicVariable> {
3732
return [...this._variables];
3833
}
3934

@@ -46,18 +41,16 @@ export class ChatDynamicVariableModel extends Disposable implements IChatWidgetC
4641
constructor(
4742
private readonly widget: IChatWidget,
4843
@ILabelService private readonly labelService: ILabelService,
49-
@IConfigurationService private readonly configService: IConfigurationService,
50-
@IInstantiationService private readonly instantiationService: IInstantiationService,
5144
) {
5245
super();
5346

5447
this._register(widget.inputEditor.onDidChangeModelContent(e => {
5548

56-
const removed: TDynamicVariable[] = [];
49+
const removed: IDynamicVariable[] = [];
5750
let didChange = false;
5851

5952
// Don't mutate entries in _variables, since they will be returned from the getter
60-
this._variables = coalesce(this._variables.map((ref, idx): TDynamicVariable | null => {
53+
this._variables = coalesce(this._variables.map((ref, idx): IDynamicVariable | null => {
6154
const model = widget.inputEditor.getModel();
6255

6356
if (!model) {
@@ -115,7 +108,7 @@ export class ChatDynamicVariableModel extends Disposable implements IChatWidgetC
115108

116109
getInputState(): any {
117110
return this.variables
118-
.map((variable: TDynamicVariable) => {
111+
.map((variable: IDynamicVariable) => {
119112
// return underlying `IDynamicVariable` object for file references
120113
if (variable instanceof ChatFileReference) {
121114
return variable.reference;
@@ -143,26 +136,9 @@ export class ChatDynamicVariableModel extends Disposable implements IChatWidgetC
143136
}
144137

145138
addReference(ref: IDynamicVariable): void {
146-
// use `ChatFileReference` for file references and `IDynamicVariable` for other variables
147-
const promptSnippetsEnabled = PromptsConfig.enabled(this.configService);
148-
const variable = (ref.id === 'vscode.file' && promptSnippetsEnabled)
149-
? this.instantiationService.createInstance(ChatFileReference, ref)
150-
: ref;
151-
152-
this._variables.push(variable);
139+
this._variables.push(ref);
153140
this.updateDecorations();
154141
this.widget.refreshParsedInput();
155-
156-
// if the `prompt snippets` feature is enabled, and file is a `prompt snippet`,
157-
// start resolving nested file references immediately and subscribe to updates
158-
if (variable instanceof ChatFileReference && variable.isPromptFile) {
159-
// subscribe to variable changes
160-
variable.onUpdate(() => {
161-
this.updateDecorations();
162-
});
163-
// start resolving the file references
164-
variable.start();
165-
}
166142
}
167143

168144
private updateDecorations(): void {

0 commit comments

Comments
 (0)