@@ -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,28 @@ 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
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
28
+ object SnippetDriver extends Driver :
29
+ val currentCtx =
30
+ val rootCtx = initCtx.fresh.addMode(Mode .ReadPositions ).addMode(Mode .Interactive )
31
+ rootCtx.setSetting(rootCtx.settings.YretainTrees , true )
32
+ rootCtx.setSetting(rootCtx.settings.YcookComments , true )
33
+ rootCtx.setSetting(rootCtx.settings.YreadComments , true )
34
+ val defaultFlags =
35
+ List (" -color:never" , " -unchecked" , " -deprecation" , " -Ximport-suggestion-timeout" , " 0" )
36
+ val options = scalacOptions.split(" \\ s+" ).toList
37
+ val settings = options ::: defaultFlags ::: Nil
38
+ val ctx = setup(settings.toArray, rootCtx) match
39
+ case Some ((_, ctx)) => ctx
40
+ case None => rootCtx
41
+ ctx.initialize()(using ctx)
42
+ snippetCompilerSettings.foldLeft(ctx.fresh) { (ctx, setting) =>
43
+ ctx.setSetting(setting.setting, setting.value)
44
+ }
39
45
40
46
private val scala3Compiler = new Compiler
41
47
@@ -85,9 +91,9 @@ class SnippetCompiler(
85
91
wrappedSnippet : WrappedSnippet ,
86
92
arg : SnippetCompilerArg
87
93
): SnippetCompilationResult = {
88
- val context = driver .currentCtx.fresh
94
+ val context = SnippetDriver .currentCtx.fresh
89
95
.setSetting(
90
- driver .currentCtx.settings.outputDir,
96
+ SnippetDriver .currentCtx.settings.outputDir,
91
97
target
92
98
)
93
99
.setReporter(new StoreReporter )
0 commit comments