1
1
package dotty .tools .languageserver .util .server
2
2
3
3
import java .io .PrintWriter
4
+ import java .io .File .{separator => sep }
4
5
import java .net .URI
5
- import java .nio .file .Path
6
+ import java .nio .file .{ Files , Path }
6
7
import java .util
7
8
8
9
import dotty .tools .languageserver .DottyLanguageServer
10
+ import dotty .tools .languageserver .util .Code .Workspace
9
11
import org .eclipse .lsp4j .{ DidOpenTextDocumentParams , InitializeParams , InitializeResult , TextDocumentItem }
10
12
11
- class TestServer (testFolder : Path ) {
13
+ class TestServer (testFolder : Path , workspaces : List [ Workspace ] ) {
12
14
13
15
val server = new DottyLanguageServer
14
16
var client : TestClient = _
15
17
16
18
init()
17
19
18
20
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}",
27
54
| "compilerVersion" : " ${BuildInfo .ideTestsCompilerVersion}",
28
55
| "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('\\ ' ,'/' )}"
32
59
|}
33
- |] """ .stripMargin
60
+ | """ .stripMargin
61
+ }
62
+
63
+ Files .createDirectories(testFolder)
34
64
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(" [" , " ," , " ]" )
38
66
39
67
new PrintWriter (configFile.toString) {
40
- write(dottyIdeJson )
68
+ write(configuration )
41
69
close()
42
70
}
43
71
@@ -54,8 +82,8 @@ class TestServer(testFolder: Path) {
54
82
* @param fileName file path in the source directory
55
83
* @return the file opened
56
84
*/
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)
59
87
val dotdp = new DidOpenTextDocumentParams ()
60
88
val tdi = new TextDocumentItem ()
61
89
tdi.setUri(testFile.uri)
0 commit comments