@@ -5,26 +5,23 @@ package semanticdb
55import core ._
66import Phases ._
77import ast .tpd ._
8+ import ast .untpd .given
89import ast .Trees .mods
910import Contexts ._
1011import Symbols ._
1112import Flags ._
1213import Names .Name
1314import StdNames .nme
15+ import NameOps ._
1416import util .Spans .Span
1517import util .{SourceFile , SourcePosition }
16- import scala .jdk .CollectionConverters ._
17- import collection .mutable
18- import java .nio .file .Paths
19-
20- import dotty .tools .dotc .transform .SymUtils ._
21-
22- import PartialFunction .condOpt
23-
24- import ast .untpd .given
25- import NameOps ._
18+ import transform .SymUtils ._
2619
20+ import scala .jdk .CollectionConverters ._
21+ import scala .collection .mutable
2722import scala .annotation .{ threadUnsafe => tu , tailrec }
23+ import scala .PartialFunction .condOpt
24+
2825
2926/** Extract symbol references and uses to semanticdb files.
3027 * See https://scalameta.org/docs/semanticdb/specification.html#symbol-1
@@ -590,37 +587,29 @@ object ExtractSemanticDB:
590587 import java .nio .file .Path
591588 import scala .collection .JavaConverters ._
592589 import java .nio .file .Files
590+ import java .nio .file .Paths
593591
594592 val name : String = " extractSemanticDB"
595593
596594 def write (source : SourceFile , occurrences : List [SymbolOccurrence ], symbolInfos : List [SymbolInformation ])(using Context ): Unit =
597595 def absolutePath (path : Path ): Path = path.toAbsolutePath.normalize
598- def commonPrefix [T ](z : T )(i1 : Iterable [T ], i2 : Iterable [T ])(app : (T , T ) => T ): T =
599- (i1 lazyZip i2).takeWhile(p => p(0 ) == p(1 )).map(_(0 )).foldLeft(z)(app)
600- val sourcePath = absolutePath(source.file.jpath)
601- val sourceRoot =
602- // Here if `sourceRoot` and `sourcePath` do not share a common prefix then `relPath` will not be normalised,
603- // containing ../.. etc, which is problematic when appending to `/META-INF/semanticdb/` and will not be accepted
604- // by Files.createDirectories on JDK 11.
605- val sourceRoot0 = absolutePath(Paths .get(ctx.settings.sourceroot.value))
606- commonPrefix(sourcePath.getRoot)(sourcePath.asScala, sourceRoot0.asScala)(_ resolve _)
607596 val semanticdbTarget =
608597 val semanticdbTargetSetting = ctx.settings.semanticdbTarget.value
609598 absolutePath(
610599 if semanticdbTargetSetting.isEmpty then ctx.settings.outputDir.value.jpath
611600 else Paths .get(semanticdbTargetSetting)
612601 )
613- val relPath = sourceRoot.relativize(sourcePath )
602+ val relPath = SourceFile .relativePath(source, ctx.settings.sourceroot.value )
614603 val outpath = semanticdbTarget
615604 .resolve(" META-INF" )
616605 .resolve(" semanticdb" )
617606 .resolve(relPath)
618- .resolveSibling(sourcePath.getFileName().toString() + " .semanticdb" )
607+ .resolveSibling(source.name + " .semanticdb" )
619608 Files .createDirectories(outpath.getParent())
620609 val doc : TextDocument = TextDocument (
621610 schema = Schema .SEMANTICDB4 ,
622611 language = Language .SCALA ,
623- uri = Tools .mkURIstring(relPath),
612+ uri = Tools .mkURIstring(Paths .get( relPath) ),
624613 text = " " ,
625614 md5 = internal.MD5 .compute(String (source.content)),
626615 symbols = symbolInfos,
0 commit comments