@@ -29,6 +29,7 @@ import dotty.tools.dotc.{semanticdb => s}
29
29
import dotty .tools .io .{AbstractFile , JarArchive }
30
30
import dotty .tools .dotc .semanticdb .DiagnosticOps .*
31
31
import scala .util .{Using , Failure , Success }
32
+ import java .nio .file .Path
32
33
33
34
34
35
/** Extract symbol references and uses to semanticdb files.
@@ -65,41 +66,49 @@ class ExtractSemanticDB private (phaseMode: ExtractSemanticDB.PhaseMode) extends
65
66
val appendDiagnostics = phaseMode == ExtractSemanticDB .PhaseMode .AppendDiagnostics
66
67
if (appendDiagnostics)
67
68
val warnings = ctx.reporter.allWarnings.groupBy(w => w.pos.source)
68
- units.flatMap { unit =>
69
- warnings.get(unit.source).map { ws =>
70
- val unitCtx = ctx.fresh.setCompilationUnit(unit).withRootImports
71
- val outputDir =
72
- ExtractSemanticDB .semanticdbPath(
73
- unit.source,
74
- ExtractSemanticDB .semanticdbOutDir(using unitCtx),
75
- sourceRoot
76
- )
77
- (outputDir, ws.map(_.toSemanticDiagnostic))
69
+ val buf = mutable.ListBuffer .empty[(Path , Seq [Diagnostic ])]
70
+ units.foreach { unit =>
71
+ val unitCtx = ctx.fresh.setCompilationUnit(unit).withRootImports
72
+ monitor(phaseName) {
73
+ warnings.get(unit.source).foreach { ws =>
74
+ val outputDir =
75
+ ExtractSemanticDB .semanticdbPath(
76
+ unit.source,
77
+ ExtractSemanticDB .semanticdbOutDir(using unitCtx),
78
+ sourceRoot
79
+ )
80
+ buf += ((outputDir, ws.map(_.toSemanticDiagnostic)))
81
+ }
82
+ }(using unitCtx)
83
+ }
84
+ cancellable {
85
+ buf.toList.asJava.parallelStream().forEach { case (out, warnings) =>
86
+ ExtractSemanticDB .appendDiagnostics(warnings, out)
78
87
}
79
- }.asJava.parallelStream().forEach { case (out, warnings) =>
80
- ExtractSemanticDB .appendDiagnostics(warnings, out)
81
88
}
82
89
else
83
90
val writeSemanticdbText = ctx.settings.semanticdbText.value
84
91
units.foreach { unit =>
85
92
val unitCtx = ctx.fresh.setCompilationUnit(unit).withRootImports
86
- val outputDir =
87
- ExtractSemanticDB .semanticdbPath(
93
+ monitor(phaseName) {
94
+ val outputDir =
95
+ ExtractSemanticDB .semanticdbPath(
96
+ unit.source,
97
+ ExtractSemanticDB .semanticdbOutDir(using unitCtx),
98
+ sourceRoot
99
+ )
100
+ val extractor = ExtractSemanticDB .Extractor ()
101
+ extractor.extract(unit.tpdTree)(using unitCtx)
102
+ ExtractSemanticDB .write(
88
103
unit.source,
89
- ExtractSemanticDB .semanticdbOutDir(using unitCtx),
90
- sourceRoot
104
+ extractor.occurrences.toList,
105
+ extractor.symbolInfos.toList,
106
+ extractor.synthetics.toList,
107
+ outputDir,
108
+ sourceRoot,
109
+ writeSemanticdbText
91
110
)
92
- val extractor = ExtractSemanticDB .Extractor ()
93
- extractor.extract(unit.tpdTree)(using unitCtx)
94
- ExtractSemanticDB .write(
95
- unit.source,
96
- extractor.occurrences.toList,
97
- extractor.symbolInfos.toList,
98
- extractor.synthetics.toList,
99
- outputDir,
100
- sourceRoot,
101
- writeSemanticdbText
102
- )
111
+ }(using unitCtx)
103
112
}
104
113
units
105
114
}
@@ -611,4 +620,4 @@ object ExtractSemanticDB:
611
620
traverse(vparam.tpt)
612
621
tparams.foreach(tp => traverse(tp.rhs))
613
622
end Extractor
614
- end ExtractSemanticDB
623
+ end ExtractSemanticDB
0 commit comments