Skip to content

Commit b5218eb

Browse files
authored
fix dynamic variables not working in request edits (microsoft#257304)
* dynamic variables on start * fix new # files not working
1 parent 29cf86e commit b5218eb

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { IChatVariablesService, IDynamicVariable } from '../common/chatVariables
77
import { IToolData, ToolSet } from '../common/languageModelToolsService.js';
88
import { IChatWidgetService } from './chat.js';
99
import { ChatDynamicVariableModel } from './contrib/chatDynamicVariables.js';
10+
import { Range } from '../../../../editor/common/core/range.js';
1011

1112
export class ChatVariablesService implements IChatVariablesService {
1213
declare _serviceBrand: undefined;
@@ -30,6 +31,28 @@ export class ChatVariablesService implements IChatVariablesService {
3031
return [];
3132
}
3233

34+
if (widget.input.attachmentModel.attachments.length > 0 && widget.viewModel.editing) {
35+
const references: IDynamicVariable[] = [];
36+
for (const attachment of widget.input.attachmentModel.attachments) {
37+
// If the attachment has a range, it is a dynamic variable
38+
if (attachment.range) {
39+
const referenceObj: IDynamicVariable = {
40+
id: attachment.id,
41+
fullName: attachment.name,
42+
modelDescription: attachment.modelDescription,
43+
range: new Range(1, attachment.range.start + 1, 1, attachment.range.endExclusive + 1),
44+
icon: attachment.icon,
45+
isFile: attachment.kind === 'file',
46+
isDirectory: attachment.kind === 'directory',
47+
data: attachment.value
48+
};
49+
references.push(referenceObj);
50+
}
51+
}
52+
53+
return [...model.variables, ...references];
54+
}
55+
3356
return model.variables;
3457
}
3558

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ import { MarkdownString } from '../../../../../base/common/htmlContent.js';
77
import { Disposable, MutableDisposable, toDisposable } from '../../../../../base/common/lifecycle.js';
88
import { autorun } from '../../../../../base/common/observable.js';
99
import { themeColorFromId } from '../../../../../base/common/themables.js';
10+
import { URI } from '../../../../../base/common/uri.js';
1011
import { ICodeEditorService } from '../../../../../editor/browser/services/codeEditorService.js';
1112
import { Range } from '../../../../../editor/common/core/range.js';
1213
import { IDecorationOptions } from '../../../../../editor/common/editorCommon.js';
1314
import { TrackedRangeStickiness } from '../../../../../editor/common/model.js';
1415
import { localize } from '../../../../../nls.js';
1516
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
1617
import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js';
18+
import { ILabelService } from '../../../../../platform/label/common/label.js';
1719
import { inputPlaceholderForeground } from '../../../../../platform/theme/common/colorRegistry.js';
1820
import { IThemeService } from '../../../../../platform/theme/common/themeService.js';
1921
import { IChatAgentCommand, IChatAgentData, IChatAgentService } from '../../common/chatAgents.js';
2022
import { chatSlashCommandBackground, chatSlashCommandForeground } from '../../common/chatColors.js';
21-
import { ChatRequestAgentPart, ChatRequestAgentSubcommandPart, ChatRequestSlashCommandPart, ChatRequestSlashPromptPart, ChatRequestTextPart, ChatRequestToolPart, ChatRequestToolSetPart, IParsedChatRequestPart, chatAgentLeader, chatSubcommandLeader } from '../../common/chatParserTypes.js';
23+
import { ChatRequestAgentPart, ChatRequestAgentSubcommandPart, ChatRequestDynamicVariablePart, ChatRequestSlashCommandPart, ChatRequestSlashPromptPart, ChatRequestTextPart, ChatRequestToolPart, ChatRequestToolSetPart, IParsedChatRequestPart, chatAgentLeader, chatSubcommandLeader } from '../../common/chatParserTypes.js';
2224
import { ChatRequestParser } from '../../common/chatRequestParser.js';
2325
import { IChatWidget } from '../chat.js';
2426
import { ChatWidget } from '../chatWidget.js';
@@ -46,7 +48,8 @@ class InputEditorDecorations extends Disposable {
4648
@ICodeEditorService private readonly codeEditorService: ICodeEditorService,
4749
@IThemeService private readonly themeService: IThemeService,
4850
@IChatAgentService private readonly chatAgentService: IChatAgentService,
49-
@IConfigurationService private readonly configurationService: IConfigurationService
51+
@IConfigurationService private readonly configurationService: IConfigurationService,
52+
@ILabelService private readonly labelService: ILabelService,
5053
) {
5154
super();
5255

@@ -258,6 +261,11 @@ class InputEditorDecorations extends Disposable {
258261
varDecorations.push({ range: tool.editorRange });
259262
}
260263

264+
const dynamicVariableParts = parsedRequest.filter((p): p is ChatRequestDynamicVariablePart => p instanceof ChatRequestDynamicVariablePart);
265+
for (const variable of dynamicVariableParts) {
266+
varDecorations.push({ range: variable.editorRange, hoverMessage: URI.isUri(variable.data) ? new MarkdownString(this.labelService.getUriLabel(variable.data, { relative: true })) : undefined });
267+
}
268+
261269
this.widget.inputEditor.setDecorationsByType(decorationDescription, variableTextDecorationType, varDecorations);
262270
}
263271
}

0 commit comments

Comments
 (0)