@@ -2,10 +2,9 @@ package dotty.tools.scaladoc
2
2
package snippets
3
3
4
4
import dotty .tools .io .{AbstractFile , VirtualDirectory }
5
- import dotty .tools .dotc .interactive .InteractiveDriver
6
- import dotty .tools .dotc .interactive .Interactive
7
- import dotty .tools .dotc .interactive .InteractiveCompiler
5
+ import dotty .tools .dotc .Driver
8
6
import dotty .tools .dotc .core .Contexts .Context
7
+ import dotty .tools .dotc .core .Mode
9
8
import dotty .tools .dotc .config .Settings .Setting ._
10
9
import dotty .tools .dotc .interfaces .SourcePosition
11
10
import dotty .tools .dotc .ast .Trees .Tree
@@ -21,21 +20,29 @@ import dotty.tools.dotc.interfaces.Diagnostic._
21
20
import scala .util .{ Try , Success , Failure }
22
21
23
22
class SnippetCompiler (
24
- val scalacOptions : String ,
23
+ val snippetCompilerSettings : Seq [SnippetCompilerSetting [_]],
24
+ val scalacOptions : String = " " ,
25
25
target : AbstractFile = new VirtualDirectory (" (memory)" )
26
26
):
27
-
28
- private def newDriver : InteractiveDriver = {
29
- val defaultFlags =
30
- List (" -color:never" , " -unchecked" , " -deprecation" , " -Ximport-suggestion-timeout" , " 0" )
31
- val options = scalacOptions.split(" \\ s+" ).toList
32
- val settings =
33
- options ::: defaultFlags ::: Nil
34
-
35
- new InteractiveDriver (settings)
36
- }
37
-
38
- private val driver = newDriver
27
+ object SnippetDriver extends Driver :
28
+ val currentCtx =
29
+ val rootCtx = initCtx.fresh.addMode(Mode .ReadPositions ).addMode(Mode .Interactive )
30
+ rootCtx.setSetting(rootCtx.settings.YretainTrees , true )
31
+ rootCtx.setSetting(rootCtx.settings.YcookComments , true )
32
+ rootCtx.setSetting(rootCtx.settings.YreadComments , true )
33
+ val defaultFlags =
34
+ List (" -color:never" , " -unchecked" , " -deprecation" , " -Ximport-suggestion-timeout" , " 0" )
35
+ val options = scalacOptions.split(" \\ s+" ).toList
36
+ val settings = options ::: defaultFlags ::: Nil
37
+ val ctx = setup(settings.toArray, rootCtx) match
38
+ case Some ((_, ctx)) =>
39
+ ctx
40
+ case None => rootCtx
41
+ val res = snippetCompilerSettings.foldLeft(ctx.fresh) { (ctx, setting) =>
42
+ ctx.setSetting(setting.setting, setting.value)
43
+ }
44
+ res.initialize()(using res)
45
+ res
39
46
40
47
private val scala3Compiler = new Compiler
41
48
@@ -85,9 +92,9 @@ class SnippetCompiler(
85
92
wrappedSnippet : WrappedSnippet ,
86
93
arg : SnippetCompilerArg
87
94
): SnippetCompilationResult = {
88
- val context = driver .currentCtx.fresh
95
+ val context = SnippetDriver .currentCtx.fresh
89
96
.setSetting(
90
- driver .currentCtx.settings.outputDir,
97
+ SnippetDriver .currentCtx.settings.outputDir,
91
98
target
92
99
)
93
100
.setReporter(new StoreReporter )
0 commit comments