@@ -22,42 +22,55 @@ export function iterSourceFiles(root: string): IterableIterator<string> {
22
22
) ;
23
23
return sourceGlob . scanSync ( root ) ;
24
24
}
25
- function * iterFilenames (
25
+ async function * iterFilenames (
26
26
root : string ,
27
27
dirsToInclude : string [ ] ,
28
- ) : IterableIterator < string > {
28
+ ) : AsyncGenerator < string > {
29
29
if ( dirsToInclude . length === 1 && dirsToInclude [ 0 ] === "*" ) {
30
30
yield * iterSourceFiles ( root ) ;
31
31
} else {
32
32
for ( const dir of dirsToInclude ) {
33
- for ( const filename of iterSourceFiles ( path . join ( root , dir ) ) ) {
34
- // We want the path relative to the root
35
- yield path . join ( dir , filename ) ;
33
+ if ( await Bun . file ( path . join ( root , dir ) ) . exists ( ) ) {
34
+ yield dir ;
35
+ }
36
+ else {
37
+ for ( const filename of iterSourceFiles ( path . join ( root , dir ) ) ) {
38
+ // We want the path relative to the root
39
+ yield path . join ( dir , filename ) ;
40
+ }
36
41
}
37
42
}
38
43
}
39
44
}
40
45
41
46
async function * iterFunctionInfo (
42
47
root : string ,
43
- filenames : IterableIterator < string > ,
48
+ filenames : AsyncGenerator < string > ,
44
49
) : AsyncIterableIterator < {
45
50
node_count : number ;
46
51
start_position : { row : number ; column : number } ;
47
52
funcdef : string ;
48
53
filename : string ;
49
54
} > {
50
- for ( const filename of filenames ) {
55
+ for await ( const filename of filenames ) {
51
56
const code = await Bun . file ( path . join ( root , filename ) ) . text ( ) ;
52
- const language = getLanguage ( filename ) ;
57
+ const language = ( ( ) => {
58
+ try { return getLanguage ( filename ) ; }
59
+ catch ( _e ) { return undefined ; }
60
+ } ) ( )
61
+ if ( ! language ) { continue ; }
53
62
for ( const func of iterFunctions ( code , language ) ) {
54
63
const cfg = buildCFG ( func , language ) ;
55
- yield {
56
- node_count : cfg . graph . order ,
57
- start_position : func . startPosition ,
58
- funcdef : getFuncDef ( code , func ) ,
59
- filename : filename . replaceAll ( "\\" , "/" ) ,
60
- } ;
64
+ try {
65
+ yield {
66
+ node_count : cfg . graph . order ,
67
+ start_position : func . startPosition ,
68
+ funcdef : getFuncDef ( code , func ) ,
69
+ filename : filename . replaceAll ( "\\" , "/" ) ,
70
+ } ;
71
+ } catch ( e ) {
72
+ console . error ( `Failed getting function definition for ${ func . text } ` , e ) ;
73
+ }
61
74
}
62
75
}
63
76
}
0 commit comments