chat: fix createModelReference leak in ResolveSymbolsContextAction (#306068)

Improve error handling in ResolveSymbolsContextAction by ensuring model reference disposal
This commit is contained in:
Rob Lourens
2026-03-28 22:15:27 -07:00
committed by GitHub
parent 1ae3819053
commit 83700a8c46

View File

@@ -807,27 +807,31 @@ registerAction2(class ResolveSymbolsContextAction extends EditingSessionAction {
const symbol = args[0] as Location;
const modelReference = await textModelService.createModelReference(symbol.uri);
const textModel = modelReference.object.textEditorModel;
if (!textModel) {
return;
try {
const textModel = modelReference.object.textEditorModel;
if (!textModel) {
return;
}
const position = new Position(symbol.range.startLineNumber, symbol.range.startColumn);
const [references, definitions, implementations] = await Promise.all([
this.getReferences(position, textModel, languageFeaturesService),
this.getDefinitions(position, textModel, languageFeaturesService),
this.getImplementations(position, textModel, languageFeaturesService)
]);
// Sort the references, definitions and implementations by
// how important it is that they make it into the working set as it has limited size
const attachments = [];
for (const reference of [...definitions, ...implementations, ...references]) {
attachments.push(chatWidget.attachmentModel.asFileVariableEntry(reference.uri));
}
chatWidget.attachmentModel.addContext(...attachments);
} finally {
modelReference.dispose();
}
const position = new Position(symbol.range.startLineNumber, symbol.range.startColumn);
const [references, definitions, implementations] = await Promise.all([
this.getReferences(position, textModel, languageFeaturesService),
this.getDefinitions(position, textModel, languageFeaturesService),
this.getImplementations(position, textModel, languageFeaturesService)
]);
// Sort the references, definitions and implementations by
// how important it is that they make it into the working set as it has limited size
const attachments = [];
for (const reference of [...definitions, ...implementations, ...references]) {
attachments.push(chatWidget.attachmentModel.asFileVariableEntry(reference.uri));
}
chatWidget.attachmentModel.addContext(...attachments);
}
private async getReferences(position: Position, textModel: ITextModel, languageFeaturesService: ILanguageFeaturesService): Promise<Location[]> {