Skip to content

fix dynamic variables not working in request edits #257304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/vs/workbench/contrib/chat/browser/chatVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { IChatVariablesService, IDynamicVariable } from '../common/chatVariables
import { IToolData, ToolSet } from '../common/languageModelToolsService.js';
import { IChatWidgetService } from './chat.js';
import { ChatDynamicVariableModel } from './contrib/chatDynamicVariables.js';
import { IRange, Range } from '../../../../editor/common/core/range.js';

export class ChatVariablesService implements IChatVariablesService {
declare _serviceBrand: undefined;
Expand All @@ -30,6 +31,28 @@ export class ChatVariablesService implements IChatVariablesService {
return [];
}

if (widget.input.attachmentModel.attachments.length > 0 && widget.viewModel.editing) {
const references: IDynamicVariable[] = [];
for (const attachment of widget.input.attachmentModel.attachments) {
// If the attachment has a range, it is a dynamic variable
if (attachment.range) {
const referenceObj: IDynamicVariable = {
id: attachment.id,
fullName: attachment.name,
modelDescription: attachment.modelDescription,
range: new Range(1, attachment.range.start + 1, 1, attachment.range.endExclusive + 1),
icon: attachment.icon,
isFile: attachment.kind === 'file',
isDirectory: attachment.kind === 'directory',
data: attachment.value
};
references.push(referenceObj);
}
}

return [...references];
}

return model.variables;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ import { MarkdownString } from '../../../../../base/common/htmlContent.js';
import { Disposable, MutableDisposable, toDisposable } from '../../../../../base/common/lifecycle.js';
import { autorun } from '../../../../../base/common/observable.js';
import { themeColorFromId } from '../../../../../base/common/themables.js';
import { URI } from '../../../../../base/common/uri.js';
import { ICodeEditorService } from '../../../../../editor/browser/services/codeEditorService.js';
import { Range } from '../../../../../editor/common/core/range.js';
import { IDecorationOptions } from '../../../../../editor/common/editorCommon.js';
import { TrackedRangeStickiness } from '../../../../../editor/common/model.js';
import { localize } from '../../../../../nls.js';
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js';
import { ILabelService } from '../../../../../platform/label/common/label.js';
import { inputPlaceholderForeground } from '../../../../../platform/theme/common/colorRegistry.js';
import { IThemeService } from '../../../../../platform/theme/common/themeService.js';
import { IChatAgentCommand, IChatAgentData, IChatAgentService } from '../../common/chatAgents.js';
import { chatSlashCommandBackground, chatSlashCommandForeground } from '../../common/chatColors.js';
import { ChatRequestAgentPart, ChatRequestAgentSubcommandPart, ChatRequestSlashCommandPart, ChatRequestSlashPromptPart, ChatRequestTextPart, ChatRequestToolPart, ChatRequestToolSetPart, IParsedChatRequestPart, chatAgentLeader, chatSubcommandLeader } from '../../common/chatParserTypes.js';
import { ChatRequestAgentPart, ChatRequestAgentSubcommandPart, ChatRequestDynamicVariablePart, ChatRequestSlashCommandPart, ChatRequestSlashPromptPart, ChatRequestTextPart, ChatRequestToolPart, ChatRequestToolSetPart, IParsedChatRequestPart, chatAgentLeader, chatSubcommandLeader } from '../../common/chatParserTypes.js';
import { ChatRequestParser } from '../../common/chatRequestParser.js';
import { ChatModeKind } from '../../common/constants.js';
import { IChatWidget } from '../chat.js';
Expand Down Expand Up @@ -47,7 +49,8 @@ class InputEditorDecorations extends Disposable {
@ICodeEditorService private readonly codeEditorService: ICodeEditorService,
@IThemeService private readonly themeService: IThemeService,
@IChatAgentService private readonly chatAgentService: IChatAgentService,
@IConfigurationService private readonly configurationService: IConfigurationService
@IConfigurationService private readonly configurationService: IConfigurationService,
@ILabelService private readonly labelService: ILabelService,
) {
super();

Expand Down Expand Up @@ -263,6 +266,11 @@ class InputEditorDecorations extends Disposable {
varDecorations.push({ range: tool.editorRange });
}

const dynamicVariableParts = parsedRequest.filter((p): p is ChatRequestDynamicVariablePart => p instanceof ChatRequestDynamicVariablePart);
for (const variable of dynamicVariableParts) {
varDecorations.push({ range: variable.editorRange, hoverMessage: URI.isUri(variable.data) ? new MarkdownString(this.labelService.getUriLabel(variable.data, { relative: true })) : undefined });
}

this.widget.inputEditor.setDecorationsByType(decorationDescription, variableTextDecorationType, varDecorations);
}
}
Expand Down
Loading