@@ -17,7 +17,6 @@ import { sanitizeFilename } from './textUtilities'
17
17
import { GitIgnoreAcceptor } from '@gerhobbelt/gitignore-parser'
18
18
import * as parser from '@gerhobbelt/gitignore-parser'
19
19
import fs from '../fs/fs'
20
- import { telemetry } from '../telemetry'
21
20
22
21
type GitIgnoreRelativeAcceptor = {
23
22
folderPath : string
@@ -323,80 +322,70 @@ export async function collectFiles(
323
322
zipFilePath : string
324
323
} [ ]
325
324
> {
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 > > = [ ]
350
326
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
+ }
357
347
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
+ )
359
354
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
365
356
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
+ }
373
362
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
+ }
375
370
376
- if ( fileContent === undefined ) {
377
- continue
378
- }
371
+ const fileContent = await readFile ( file )
379
372
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
390
375
}
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
+ } )
398
386
}
399
- )
387
+ }
388
+ return storage
400
389
}
401
390
402
391
const readFile = async ( file : vscode . Uri ) => {
0 commit comments