Skip to content

Commit e5dc1e8

Browse files
authored
cleanup dynamic prompt variables (#251444)
1 parent d4cda5f commit e5dc1e8

File tree

3 files changed

+6
-117
lines changed

3 files changed

+6
-117
lines changed

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

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ import { IChatAgentService } from '../common/chatAgents.js';
7777
import { ChatContextKeys } from '../common/chatContextKeys.js';
7878
import { IChatEditingSession } from '../common/chatEditingService.js';
7979
import { ChatEntitlement, IChatEntitlementService } from '../common/chatEntitlementService.js';
80-
import { IChatRequestVariableEntry, ChatRequestVariableSet, isPromptFileVariableEntry, isElementVariableEntry, isImageVariableEntry, isNotebookOutputVariableEntry, isPasteVariableEntry, isSCMHistoryItemVariableEntry, toPromptFileVariableEntry } from '../common/chatVariableEntries.js';
80+
import { IChatRequestVariableEntry, ChatRequestVariableSet, isPromptFileVariableEntry, isElementVariableEntry, isImageVariableEntry, isNotebookOutputVariableEntry, isPasteVariableEntry, isSCMHistoryItemVariableEntry } from '../common/chatVariableEntries.js';
8181
import { ChatMode2, IChatMode, IChatModeService, isBuiltinChatMode, validateChatMode2 } from '../common/chatModes.js';
8282
import { IChatFollowup } from '../common/chatService.js';
83-
import { IChatVariablesService } from '../common/chatVariables.js';
8483
import { IChatResponseViewModel } from '../common/chatViewModel.js';
8584
import { ChatInputHistoryMaxEntries, IChatHistoryEntry, IChatInputState, IChatWidgetHistoryService } from '../common/chatWidgetHistoryService.js';
8685
import { ChatAgentLocation, ChatConfiguration, ChatMode, isChatMode, validateChatMode } from '../common/constants.js';
@@ -97,7 +96,6 @@ import { ChatEditingShowChangesAction, ViewPreviousEditsAction } from './chatEdi
9796
import { ChatFollowups } from './chatFollowups.js';
9897
import { ChatSelectedTools } from './chatSelectedTools.js';
9998
import { IChatViewState } from './chatWidget.js';
100-
import { ChatFileReference } from './contrib/chatDynamicVariables/chatFileReference.js';
10199
import { ChatImplicitContext } from './contrib/chatImplicitContext.js';
102100
import { ChatRelatedFiles } from './contrib/chatInputRelatedFilesContrib.js';
103101
import { resizeImage } from './imageUtils.js';
@@ -167,35 +165,18 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
167165

168166
public async getAttachedAndImplicitContext(sessionId: string): Promise<ChatRequestVariableSet> {
169167

170-
// prompt files may have nested child references to other prompt
171-
// files that are resolved asynchronously, hence we need to wait
172-
// for the entire prompt instruction tree to be processed
173-
174168
const contextArr = new ChatRequestVariableSet();
175169

170+
// get prompt file variables (instructions) and all rereferenced contents first
176171
contextArr.add(... await this.attachmentModel.getPromptFileVariables());
172+
173+
// then add all other attachments (includes prompt file variables, but they will be ignored if already added)
177174
contextArr.add(...this.attachmentModel.attachments);
178175

179176
if (this.implicitContext?.enabled && this.implicitContext.value) {
180177
const implicitChatVariables = await this.implicitContext.toBaseEntries();
181178
contextArr.add(...implicitChatVariables);
182179
}
183-
184-
// factor in nested file links of a prompt into the implicit context
185-
const variables = this.variableService.getDynamicVariables(sessionId);
186-
for (const variable of variables) {
187-
if (!(variable instanceof ChatFileReference)) {
188-
continue;
189-
}
190-
191-
// the usual URIs list of prompt instructions is `bottom-up`, therefore
192-
// we do the same here - first add all child references to the list
193-
contextArr.add(
194-
...variable.allValidReferences.map((link) => {
195-
return toPromptFileVariableEntry(link.uri, false);
196-
}),
197-
);
198-
}
199180
return contextArr;
200181
}
201182

@@ -375,7 +356,6 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
375356
@ITextModelService private readonly textModelResolverService: ITextModelService,
376357
@IStorageService private readonly storageService: IStorageService,
377358
@ILabelService private readonly labelService: ILabelService,
378-
@IChatVariablesService private readonly variableService: IChatVariablesService,
379359
@IChatAgentService private readonly agentService: IChatAgentService,
380360
@ISharedWebContentExtractorService private readonly sharedWebExtracterService: ISharedWebContentExtractorService,
381361
@IWorkbenchAssignmentService private readonly experimentService: IWorkbenchAssignmentService,

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { ILabelService } from '../../../../../platform/label/common/label.js';
1717
import { IChatRequestVariableValue, IDynamicVariable } from '../../common/chatVariables.js';
1818
import { IChatWidget } from '../chat.js';
1919
import { IChatWidgetContrib } from '../chatWidget.js';
20-
import { ChatFileReference } from './chatDynamicVariables/chatFileReference.js';
2120

2221
export const dynamicVariableDecorationType = 'chat-dynamic-variable';
2322

@@ -87,12 +86,7 @@ export class ChatDynamicVariableModel extends Disposable implements IChatWidgetC
8786

8887
didChange = true;
8988

90-
if (ref instanceof ChatFileReference) {
91-
ref.range = newRange;
92-
return ref;
93-
} else {
94-
return { ...ref, range: newRange };
95-
}
89+
return { ...ref, range: newRange };
9690
}));
9791

9892
// cleanup disposable variables
@@ -107,15 +101,7 @@ export class ChatDynamicVariableModel extends Disposable implements IChatWidgetC
107101
}
108102

109103
getInputState(): any {
110-
return this.variables
111-
.map((variable: IDynamicVariable) => {
112-
// return underlying `IDynamicVariable` object for file references
113-
if (variable instanceof ChatFileReference) {
114-
return variable.reference;
115-
}
116-
117-
return variable;
118-
});
104+
return this.variables;
119105
}
120106

121107
setInputState(s: any): void {

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

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)