@@ -22,42 +22,59 @@ 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
+ } else {
36
+ for ( const filename of iterSourceFiles ( path . join ( root , dir ) ) ) {
37
+ // We want the path relative to the root
38
+ yield path . join ( dir , filename ) ;
39
+ }
36
40
}
37
41
}
38
42
}
39
43
}
40
44
41
45
async function * iterFunctionInfo (
42
46
root : string ,
43
- filenames : IterableIterator < string > ,
47
+ filenames : AsyncGenerator < string > ,
44
48
) : AsyncIterableIterator < {
45
49
node_count : number ;
46
50
start_position : { row : number ; column : number } ;
47
51
funcdef : string ;
48
52
filename : string ;
49
53
} > {
50
- for ( const filename of filenames ) {
54
+ for await ( const filename of filenames ) {
51
55
const code = await Bun . file ( path . join ( root , filename ) ) . text ( ) ;
52
- const language = getLanguage ( filename ) ;
56
+ const language = ( ( ) => {
57
+ try {
58
+ return getLanguage ( filename ) ;
59
+ } catch {
60
+ return undefined ;
61
+ }
62
+ } ) ( ) ;
63
+ if ( ! language ) {
64
+ continue ;
65
+ }
53
66
for ( const func of iterFunctions ( code , language ) ) {
54
67
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
- } ;
68
+ try {
69
+ yield {
70
+ node_count : cfg . graph . order ,
71
+ start_position : func . startPosition ,
72
+ funcdef : getFuncDef ( code , func ) ,
73
+ filename : filename . replaceAll ( "\\" , "/" ) ,
74
+ } ;
75
+ } catch ( e ) {
76
+ console . error ( `Failed getting function definition for ${ func . text } ` , e ) ;
77
+ }
61
78
}
62
79
}
63
80
}
0 commit comments