Skip to content

Commit 2c044d6

Browse files
committed
Relativize path in SourceFile annotation
1 parent 0ad43b7 commit 2c044d6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,19 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
335335
&& ctx.compilationUnit.source.exists
336336
&& sym != defn.SourceFileAnnot
337337
then
338-
sym.addAnnotation(Annotation.makeSourceFile(ctx.compilationUnit.source.file.path))
338+
def sourcerootPath =
339+
java.nio.file.Paths.get(ctx.settings.sourceroot.value)
340+
.toAbsolutePath
341+
.normalize
342+
val file = ctx.compilationUnit.source.file
343+
val relativePath =
344+
if file.path.startsWith(str.REPL_SESSION_LINE) then
345+
file.path
346+
else
347+
val jpath = file.jpath
348+
if jpath.isAbsolute then sourcerootPath.relativize(jpath.normalize).toString
349+
else jpath.normalize.toString
350+
sym.addAnnotation(Annotation.makeSourceFile(relativePath))
339351
else (tree.rhs, sym.info) match
340352
case (rhs: LambdaTypeTree, bounds: TypeBounds) =>
341353
VarianceChecker.checkLambda(rhs, bounds)

0 commit comments

Comments
 (0)