@@ -17,7 +17,6 @@ import { sanitizeFilename } from './textUtilities'
1717import { GitIgnoreAcceptor } from '@gerhobbelt/gitignore-parser'
1818import * as parser from '@gerhobbelt/gitignore-parser'
1919import fs from '../fs/fs'
20- import { telemetry } from '../telemetry'
2120
2221type GitIgnoreRelativeAcceptor = {
2322 folderPath : string
@@ -323,80 +322,70 @@ export async function collectFiles(
323322 zipFilePath : string
324323 } [ ]
325324> {
326- return telemetry . function_call . run (
327- async ( span ) => {
328- const storage : Awaited < ReturnType < typeof collectFiles > > = [ ]
329-
330- const workspaceFoldersMapping = getWorkspaceFoldersByPrefixes ( workspaceFolders )
331- const workspaceToPrefix = new Map < vscode . WorkspaceFolder , string > (
332- workspaceFoldersMapping === undefined
333- ? [ [ workspaceFolders [ 0 ] , '' ] ]
334- : Object . entries ( workspaceFoldersMapping ) . map ( ( value ) => [ value [ 1 ] , value [ 0 ] ] )
335- )
336- const prefixWithFolderPrefix = ( folder : vscode . WorkspaceFolder , path : string ) => {
337- const prefix = workspaceToPrefix . get ( folder )
338- /**
339- * collects all files that are marked as source
340- * @param sourcePaths the paths where collection starts
341- * @param workspaceFolders the current workspace folders opened
342- * @param respectGitIgnore whether to respect gitignore file
343- * @returns all matched files
344- */
345- if ( prefix === undefined ) {
346- throw new ToolkitError ( `Failed to find prefix for workspace folder ${ folder . name } ` )
347- }
348- return prefix === '' ? path : `${ prefix } /${ path } `
349- }
325+ const storage : Awaited < ReturnType < typeof collectFiles > > = [ ]
350326
351- let totalSizeBytes = 0
352- for ( const rootPath of sourcePaths ) {
353- const allFiles = await vscode . workspace . findFiles (
354- new vscode . RelativePattern ( rootPath , '**' ) ,
355- getExcludePattern ( )
356- )
327+ const workspaceFoldersMapping = getWorkspaceFoldersByPrefixes ( workspaceFolders )
328+ const workspaceToPrefix = new Map < vscode . WorkspaceFolder , string > (
329+ workspaceFoldersMapping === undefined
330+ ? [ [ workspaceFolders [ 0 ] , '' ] ]
331+ : Object . entries ( workspaceFoldersMapping ) . map ( ( value ) => [ value [ 1 ] , value [ 0 ] ] )
332+ )
333+ const prefixWithFolderPrefix = ( folder : vscode . WorkspaceFolder , path : string ) => {
334+ const prefix = workspaceToPrefix . get ( folder )
335+ /**
336+ * collects all files that are marked as source
337+ * @param sourcePaths the paths where collection starts
338+ * @param workspaceFolders the current workspace folders opened
339+ * @param respectGitIgnore whether to respect gitignore file
340+ * @returns all matched files
341+ */
342+ if ( prefix === undefined ) {
343+ throw new ToolkitError ( `Failed to find prefix for workspace folder ${ folder . name } ` )
344+ }
345+ return prefix === '' ? path : `${ prefix } /${ path } `
346+ }
357347
358- const files = respectGitIgnore ? await filterOutGitignoredFiles ( rootPath , allFiles ) : allFiles
348+ let totalSizeBytes = 0
349+ for ( const rootPath of sourcePaths ) {
350+ const allFiles = await vscode . workspace . findFiles (
351+ new vscode . RelativePattern ( rootPath , '**' ) ,
352+ getExcludePattern ( )
353+ )
359354
360- for ( const file of files ) {
361- const relativePath = getWorkspaceRelativePath ( file . fsPath , { workspaceFolders } )
362- if ( ! relativePath ) {
363- continue
364- }
355+ const files = respectGitIgnore ? await filterOutGitignoredFiles ( rootPath , allFiles ) : allFiles
365356
366- const fileStat = await fs . stat ( file )
367- if ( totalSizeBytes + fileStat . size > maxSize ) {
368- throw new ToolkitError (
369- 'The project you have selected for source code is too large to use as context. Please select a different folder to use' ,
370- { code : 'ContentLengthError' }
371- )
372- }
357+ for ( const file of files ) {
358+ const relativePath = getWorkspaceRelativePath ( file . fsPath , { workspaceFolders } )
359+ if ( ! relativePath ) {
360+ continue
361+ }
373362
374- const fileContent = await readFile ( file )
363+ const fileStat = await fs . stat ( file )
364+ if ( totalSizeBytes + fileStat . size > maxSize ) {
365+ throw new ToolkitError (
366+ 'The project you have selected for source code is too large to use as context. Please select a different folder to use' ,
367+ { code : 'ContentLengthError' }
368+ )
369+ }
375370
376- if ( fileContent === undefined ) {
377- continue
378- }
371+ const fileContent = await readFile ( file )
379372
380- // Now that we've read the file, increase our usage
381- totalSizeBytes += fileStat . size
382- storage . push ( {
383- workspaceFolder : relativePath . workspaceFolder ,
384- relativeFilePath : relativePath . relativePath ,
385- fileUri : file ,
386- fileContent : fileContent ,
387- zipFilePath : prefixWithFolderPrefix ( relativePath . workspaceFolder , relativePath . relativePath ) ,
388- } )
389- }
373+ if ( fileContent === undefined ) {
374+ continue
390375 }
391- return storage
392- } ,
393- {
394- emit : true ,
395- functionId : {
396- name : 'collectFiles' ,
397- } ,
376+
377+ // Now that we've read the file, increase our usage
378+ totalSizeBytes += fileStat . size
379+ storage . push ( {
380+ workspaceFolder : relativePath . workspaceFolder ,
381+ relativeFilePath : relativePath . relativePath ,
382+ fileUri : file ,
383+ fileContent : fileContent ,
384+ zipFilePath : prefixWithFolderPrefix ( relativePath . workspaceFolder , relativePath . relativePath ) ,
385+ } )
398386 }
399- )
387+ }
388+ return storage
400389}
401390
402391const readFile = async ( file : vscode . Uri ) => {
0 commit comments