@@ -4,11 +4,20 @@ import org.jetbrains.dokka._
44import org .jetbrains .dokka .DokkaSourceSetImpl
55import org .jetbrains .dokka .plugability .DokkaContext
66import java .io .File
7+ import java .nio .file .Files
8+ import java .nio .file .Path
9+ import java .nio .file .Paths
10+
711import collection .JavaConverters ._
812import dotty .dokka .site .StaticSiteContext
913import dotty .tools .dotc .core .Contexts ._
14+ import dotty .tools .io .VirtualFile
15+ import dotty .tools .dotc .util .SourceFile
16+ import dotty .tools .dotc .util .SourcePosition
17+ import dotty .tools .dotc .util .Spans
1018import java .io .ByteArrayOutputStream
1119import java .io .PrintStream
20+ import scala .io .Codec
1221
1322type CompilerContext = dotty.tools.dotc.core.Contexts .Context
1423
@@ -20,12 +29,25 @@ given docContextFromDokka(using dokkaContext: DokkaContext) as DocContext =
2029
2130val report = dotty.tools.dotc.report
2231
32+ def relativePath (p : Path )(using Context ): Path =
33+ val root = Paths .get(" " ).toAbsolutePath()
34+ val absPath = p.toAbsolutePath
35+ println(Seq (p, absPath, absPath.startsWith(root), root.relativize(absPath)))
36+ if absPath.startsWith(root) then root.relativize(p.toAbsolutePath()) else p
37+
38+
2339def throwableToString (t : Throwable )(using CompilerContext ): String =
24- if ctx.settings.verbose.value then
25- val os = new ByteArrayOutputStream
26- t.printStackTrace(new PrintStream (os))
27- os.toString()
28- else s " ${t.getClass.getName}: ${t.getMessage}"
40+ val os = new ByteArrayOutputStream
41+ t.printStackTrace(new PrintStream (os))
42+ val stLinkes = os.toString().linesIterator
43+ if ctx.settings.verbose.value then stLinkes.mkString(" \n " )
44+ else stLinkes.take(5 ).mkString(" \n " )
45+
46+ private def sourcePostionFor (f : File )(using CompilerContext ) =
47+ val relPath = relativePath(f.toPath)
48+ val virtualFile = new VirtualFile (relPath.toString, relPath.toString)
49+ val sourceFile = new SourceFile (virtualFile, Codec .UTF8 )
50+ SourcePosition (sourceFile, Spans .NoSpan )
2951
3052// TODO (https://github.com/lampepfl/scala3doc/issues/238): provide proper error handling
3153private def createMessage (
@@ -38,13 +60,13 @@ private def createMessage(
3860
3961extension (r : report.type ):
4062 def error (m : String , f : File , e : Throwable | Null = null )(using CompilerContext ): Unit =
41- r.error(createMessage(m, f, e))
63+ r.error(createMessage(m, f, e), sourcePostionFor(f) )
4264
4365 def warn (m : String , f : File , e : Throwable )(using CompilerContext ): Unit =
44- r.warning(createMessage(m, f, e))
66+ r.warning(createMessage(m, f, e), sourcePostionFor(f) )
4567
4668 def warn (m : String , f : File )(using CompilerContext ): Unit =
47- r.warning(createMessage(m, f, null ))
69+ r.warning(createMessage(m, f, null ), sourcePostionFor(f) )
4870
4971
5072case class DocContext (args : Scala3doc .Args , compilerContext : CompilerContext )
0 commit comments