@@ -405,7 +405,7 @@ type InteractiveChecker internal (compilerStateCache) =
405
405
return ( parseFileResults, checkFileResults, projectResults)
406
406
}
407
407
408
- /// Find the dependent files of the current file based on the untyped syntax tree
408
+ /// Find the transitive dependent files of the current file based on the untyped syntax tree.
409
409
member _.GetDependentFiles ( currentFileName : string , fileNames : string [], sourceReader : string -> int * Lazy < string >) = async {
410
410
// parse files
411
411
let! ct = Async.CancellationToken
@@ -431,23 +431,27 @@ type InteractiveChecker internal (compilerStateCache) =
431
431
let currentFileIdx = Array.IndexOf( fileNames, currentFileName)
432
432
433
433
let filePairs = FilePairMap( sourceFiles)
434
- let graph , _trie = DependencyResolution.mkGraph filePairs sourceFiles
435
-
436
- let dependentFiles =
437
- graph.Keys
438
- |> Seq.choose ( fun fileIndex ->
439
- let isDependency =
440
- // Only files that came after the current file are relevant
441
- fileIndex > currentFileIdx
442
- &&
443
- // The current file is listed as a dependency
444
- Array.contains currentFileIdx graph.[ fileIndex]
445
- if not isDependency then
446
- None
434
+ let graph , _trie = DependencyResolution.mkGraph filePairs sourceFiles
435
+ let findTransitiveDependencies ( startNode : FileIndex ) : FileIndex array =
436
+ let rec dfs ( node : FileIndex ) ( visited : Set < FileIndex >) ( acc : FileIndex array ) : FileIndex array =
437
+ if ( Set.contains node visited) then
438
+ acc
447
439
else
448
- Some( Array.item fileIndex fileNames)
449
- )
450
- |> Seq.toArray
440
+ let neighbors = graph.[ node]
441
+ let visited ' = Set.add node visited
442
+
443
+ let acc ' =
444
+ Array.fold ( fun innerAcc neighbor -> dfs neighbor visited' innerAcc) acc neighbors
445
+
446
+ [| yield ! acc' ; yield node |]
447
+
448
+ dfs startNode Set.empty Array.empty
449
+ |> Array.sort
450
+
451
+ let dependentFiles =
452
+ findTransitiveDependencies currentFileIdx
453
+ |> Array.sort
454
+ |> Array.map ( fun idx -> Array.item idx fileNames)
451
455
452
456
return dependentFiles
453
- }
457
+ }
0 commit comments