11package dotty .tools .languageserver .util .server
22
33import java .io .PrintWriter
4+ import java .io .File .{separator => sep }
45import java .net .URI
5- import java .nio .file .Path
6+ import java .nio .file .{ Files , Path }
67import java .util
78
89import dotty .tools .languageserver .DottyLanguageServer
10+ import dotty .tools .languageserver .util .Code .Workspace
911import org .eclipse .lsp4j .{ DidOpenTextDocumentParams , InitializeParams , InitializeResult , TextDocumentItem }
1012
11- class TestServer (testFolder : Path ) {
13+ class TestServer (testFolder : Path , workspaces : List [ Workspace ] ) {
1214
1315 val server = new DottyLanguageServer
1416 var client : TestClient = _
1517
1618 init()
1719
1820 private [this ] def init (): InitializeResult = {
19- // Fill the configuration with values populated by sbt
20- def showSeq [T ](lst : Seq [T ]): String =
21- lst
22- .map(elem => '"' + elem.toString.replace('\\ ' , '/' ) + '"' )
23- .mkString(" [ " , " , " , " ]" )
24- val dottyIdeJson : String =
25- s """ [ {
26- | "id" : "dotty-ide-test",
21+ /**
22+ * Set up given workspace, return JSON config.
23+ *
24+ * This creates the necessary directories to hold the classes and sources. Some values
25+ * are passed via sbt-buildinfo, such as the classpath containing the scala and dotty libaries.
26+ *
27+ * @param workspace The workspace to configure.
28+ * @return A JSON object representing the configuration for this workspace.
29+ */
30+ def workspaceSetup (workspace : Workspace ): String = {
31+ def showSeq [T ](lst : Seq [T ]): String =
32+ lst
33+ .map(elem => '"' + elem.toString.replace('\\ ' , '/' ) + '"' )
34+ .mkString(" [ " , " , " , " ]" )
35+
36+ def classDirectory (workspace : Workspace ): Path = {
37+ val path = testFolder.resolve(workspace.name).resolve(" out" )
38+ Files .createDirectories(path)
39+ path.toAbsolutePath
40+ }
41+
42+ val dependencyClasspath =
43+ BuildInfo .ideTestsDependencyClasspath.map(_.getAbsolutePath) ++
44+ workspace.dependsOn.map(w => classDirectory(w).toString)
45+
46+ val sourceDirectory : Path = {
47+ val path = TestFile .sourceDir.resolve(workspace.name).toAbsolutePath
48+ Files .createDirectories(path)
49+ path
50+ }
51+
52+ s """ {
53+ | "id" : " ${workspace.name}",
2754 | "compilerVersion" : " ${BuildInfo .ideTestsCompilerVersion}",
2855 | "compilerArguments" : ${showSeq(BuildInfo .ideTestsCompilerArguments)},
29- | "sourceDirectories" : ${showSeq(BuildInfo .ideTestsSourceDirectories )},
30- | "dependencyClasspath" : ${showSeq(BuildInfo .ideTestsDependencyClasspath )},
31- | "classDirectory" : " ${BuildInfo .ideTestsClassDirectory .toString.replace('\\ ' ,'/' )}"
56+ | "sourceDirectories" : ${showSeq(sourceDirectory :: Nil )},
57+ | "dependencyClasspath" : ${showSeq(dependencyClasspath )},
58+ | "classDirectory" : " ${classDirectory(workspace) .toString.replace('\\ ' ,'/' )}"
3259 |}
33- |] """ .stripMargin
60+ | """ .stripMargin
61+ }
62+
63+ Files .createDirectories(testFolder)
3464 val configFile = testFolder.resolve(DottyLanguageServer .IDE_CONFIG_FILE )
35- testFolder.toFile.mkdirs()
36- testFolder.resolve(" src" ).toFile.mkdirs()
37- testFolder.resolve(" out" ).toFile.mkdirs()
65+ val configuration = workspaces.map(workspaceSetup).mkString(" [" , " ," , " ]" )
3866
3967 new PrintWriter (configFile.toString) {
40- write(dottyIdeJson )
68+ write(configuration )
4169 close()
4270 }
4371
@@ -54,8 +82,8 @@ class TestServer(testFolder: Path) {
5482 * @param fileName file path in the source directory
5583 * @return the file opened
5684 */
57- def openCode (code : String , fileName : String ): TestFile = {
58- val testFile = new TestFile (fileName)
85+ def openCode (code : String , workspace : Workspace , fileName : String ): TestFile = {
86+ val testFile = new TestFile (workspace.name + sep + fileName)
5987 val dotdp = new DidOpenTextDocumentParams ()
6088 val tdi = new TextDocumentItem ()
6189 tdi.setUri(testFile.uri)
0 commit comments