@@ -24,6 +24,7 @@ import scala.annotation.{ threadUnsafe => tu, tailrec }
24
24
import scala .PartialFunction .condOpt
25
25
26
26
import dotty .tools .dotc .{semanticdb => s }
27
+ import dotty .tools .io .JarArchive
27
28
28
29
/** Extract symbol references and uses to semanticdb files.
29
30
* See https://scalameta.org/docs/semanticdb/specification.html#symbol-1
@@ -38,7 +39,10 @@ class ExtractSemanticDB extends Phase:
38
39
override val description : String = ExtractSemanticDB .description
39
40
40
41
override def isRunnable (using Context ) =
41
- super .isRunnable && ctx.settings.Xsemanticdb .value
42
+ def writesToOutputJar =
43
+ ExtractSemanticDB .semanticdbTarget.isEmpty &&
44
+ ExtractSemanticDB .outputDirectory.isInstanceOf [JarArchive ]
45
+ super .isRunnable && ctx.settings.Xsemanticdb .value && ! writesToOutputJar
42
46
43
47
// Check not needed since it does not transform trees
44
48
override def isCheckable : Boolean = false
@@ -473,21 +477,22 @@ object ExtractSemanticDB:
473
477
val name : String = " extractSemanticDB"
474
478
val description : String = " extract info into .semanticdb files"
475
479
480
+ private def semanticdbTarget (using Context ): Option [Path ] =
481
+ Option (ctx.settings.semanticdbTarget.value)
482
+ .filterNot(_.isEmpty)
483
+ .map(Paths .get(_))
484
+
485
+ private def outputDirectory (using Context ) = ctx.settings.outputDir.value
486
+
476
487
def write (
477
488
source : SourceFile ,
478
489
occurrences : List [SymbolOccurrence ],
479
490
symbolInfos : List [SymbolInformation ],
480
491
synthetics : List [Synthetic ],
481
492
)(using Context ): Unit =
482
493
def absolutePath (path : Path ): Path = path.toAbsolutePath.normalize
483
- val semanticdbTarget =
484
- val semanticdbTargetSetting = ctx.settings.semanticdbTarget.value
485
- absolutePath(
486
- if semanticdbTargetSetting.isEmpty then ctx.settings.outputDir.value.jpath
487
- else Paths .get(semanticdbTargetSetting)
488
- )
489
494
val relPath = SourceFile .relativePath(source, ctx.settings.sourceroot.value)
490
- val outpath = semanticdbTarget
495
+ val outpath = absolutePath( semanticdbTarget.getOrElse(outputDirectory.jpath))
491
496
.resolve(" META-INF" )
492
497
.resolve(" semanticdb" )
493
498
.resolve(relPath)
0 commit comments