Code change:
return null; } <ins> const result: CompletionList = { suggestions: [] }; </ins> const afterRange = new Range(position.lineNumber, range.replace.startColumn, position.lineNumber, range.replace.startColumn + '#file:'.length); <del> return { suggestions: [ { label: `${chatVariableLeader}file`, insertText: `${chatVariableLeader}file:`, detail: localize('pickFileLabel', "Pick a file"), range, kind: CompletionItemKind.Text, command: { id: SelectAndInsertFileAction.ID, title: SelectAndInsertFileAction.ID, arguments: [{ widget, range: afterRange }] }, sortText: 'z' } satisfies CompletionItem ] }; </del> <ins> result.suggestions.push({ label: `${chatVariableLeader}file`, insertText: `${chatVariableLeader}file:`, detail: localize('pickFileLabel', "Pick a file"), range, kind: CompletionItemKind.Text, command: { id: SelectAndInsertFileAction.ID, title: SelectAndInsertFileAction.ID, arguments: [{ widget, range: afterRange }] }, sortText: 'z' }); await this.addFileEntries(widget, result, range, token); return result; </ins> } })); <ins> this._register(CommandsRegistry.registerCommand(BuiltinDynamicCompletions.addReferenceCommand, (_services, arg) => this.cmdAddReference(arg))); this.queryBuilder = this.instantiationService.createInstance(QueryBuilder); } private async addFileEntries(widget: IChatWidget, result: CompletionList, info: { insert: Range; replace: Range; varWord: IWordAtPosition | null }, token: CancellationToken) { const makeFileCompletionItem = (resource: URI): CompletionItem => { const basename = this.labelService.getUriBasenameLabel(resource); const insertText = `${chatVariableLeader}file:${basename} `; return { label: { label: `${chatVariableLeader}file:${basename}`, description: this.labelService.getUriLabel(resource) }, insertText, range: info, kind: CompletionItemKind.File, sortText: 'zz', command: { id: BuiltinDynamicCompletions.addReferenceCommand, title: '', arguments: [new ReferenceArgument(widget, { id: 'vscode.file', range: { startLineNumber: info.replace.startLineNumber, startColumn: info.replace.startColumn, endLineNumber: info.replace.endLineNumber, endColumn: info.replace.startColumn + insertText.length }, data: resource })] } }; }; let pattern: string | undefined; if (info.varWord?.word && info.varWord.word.startsWith(chatVariableLeader)) { pattern = info.varWord.word.toLowerCase().slice(1); // remove leading # } const seen = new ResourceSet(); const len = result.suggestions.length; // HISTORY // always take the last N items for (const item of this.historyService.getHistory()) { if (!item.resource || !this.workspaceContextService.getWorkspaceFolder(item.resource)) { // ignore "forgein" editors continue; } if (pattern) { // use pattern if available const basename = this.labelService.getUriBasenameLabel(item.resource).toLowerCase(); if (!isPatternInWord(pattern, 0, pattern.length, basename, 0, basename.length)) { continue; } } seen.add(item.resource); const newLen = result.suggestions.push(makeFileCompletionItem(item.resource)); if (newLen - len >= 5) { break; } } // SEARCH // use file search when having a pattern if (pattern) { const query = this.queryBuilder.file(this.workspaceContextService.getWorkspace().folders, { filePattern: pattern, maxResults: 25 }); const data = await this.searchService.fileSearch(query, token); for (const match of data.results) { if (seen.has(match.resource)) { // already included via history continue; } result.suggestions.push(makeFileCompletionItem(match.resource)); } if (!data.limitHit) { result.incomplete = true; } } } private cmdAddReference(arg: ReferenceArgument) { // invoked via the completion command arg.widget.getContrib<ChatDynamicVariableModel>(ChatDynamicVariableModel.ID)?.addReference(arg.variable); </ins> } }

Related discussion:
text: Today which have which triggers quick pick to select a file. This issue is about also allowing to type a file name and have dynamic suggestions, like inserts