@@ -4,11 +4,20 @@ import org.jetbrains.dokka._
4
4
import org .jetbrains .dokka .DokkaSourceSetImpl
5
5
import org .jetbrains .dokka .plugability .DokkaContext
6
6
import java .io .File
7
+ import java .nio .file .Files
8
+ import java .nio .file .Path
9
+ import java .nio .file .Paths
10
+
7
11
import collection .JavaConverters ._
8
12
import dotty .dokka .site .StaticSiteContext
9
13
import 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
10
18
import java .io .ByteArrayOutputStream
11
19
import java .io .PrintStream
20
+ import scala .io .Codec
12
21
13
22
type CompilerContext = dotty.tools.dotc.core.Contexts .Context
14
23
@@ -20,12 +29,25 @@ given docContextFromDokka(using dokkaContext: DokkaContext) as DocContext =
20
29
21
30
val report = dotty.tools.dotc.report
22
31
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
+
23
39
def 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 )
29
51
30
52
// TODO (https://github.com/lampepfl/scala3doc/issues/238): provide proper error handling
31
53
private def createMessage (
@@ -38,13 +60,13 @@ private def createMessage(
38
60
39
61
extension (r : report.type ):
40
62
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) )
42
64
43
65
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) )
45
67
46
68
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) )
48
70
49
71
50
72
case class DocContext (args : Scala3doc .Args , compilerContext : CompilerContext )
0 commit comments