@@ -10,63 +10,63 @@ import dotty.tools.dotc.Main
10
10
import dotty .tools .dotc .reporting .{Reporter , ThrowingReporter }
11
11
import dotty .tools .io .Directory
12
12
import dotty .tools .languageserver .DottyLanguageServer
13
- import dotty .tools .languageserver .util .Code .{TastyWithPositions , Workspace }
13
+ import dotty .tools .languageserver .util .Code .{TastyWithPositions , Project }
14
14
import org .eclipse .lsp4j .{ DidOpenTextDocumentParams , InitializeParams , InitializeResult , TextDocumentItem }
15
15
16
- class TestServer (testFolder : Path , workspaces : List [Workspace ]) {
16
+ class TestServer (testFolder : Path , projects : List [Project ]) {
17
17
18
18
val server = new DottyLanguageServer
19
19
var client : TestClient = _
20
20
21
21
init()
22
22
23
23
private [this ] def init (): InitializeResult = {
24
- var compiledWorkspaces : Set [Workspace ] = Set .empty
25
-
26
- /** Compile the dependencies of the given workspace , and then the workspace . */
27
- def compileWorkspaceAndDependencies ( workspace : Workspace ): Unit =
28
- if (! compiledWorkspaces .contains(workspace )) {
29
- workspace .dependsOn.foreach(compileWorkspaceAndDependencies )
30
- compileWorkspace(workspace )
31
- compiledWorkspaces += workspace
24
+ var compiledProjects : Set [Project ] = Set .empty
25
+
26
+ /** Compile the dependencies of the given project , and then the project . */
27
+ def compileProjectAndDependencies ( project : Project ): Unit =
28
+ if (! compiledProjects .contains(project )) {
29
+ project .dependsOn.foreach(compileProjectAndDependencies )
30
+ compileProject(project )
31
+ compiledProjects += project
32
32
}
33
33
34
34
/**
35
- * Set up given workspace , return JSON config.
35
+ * Set up given project , return JSON config.
36
36
*
37
- * If the workspace has dependencies, these dependencies are compiled. The classfiles of the
38
- * dependent workspaces are put on the classpath of this workspace .
37
+ * If the project has dependencies, these dependencies are compiled. The classfiles of the
38
+ * dependent projects are put on the classpath of this project .
39
39
*
40
- * @param workspace The workspace to configure.
41
- * @return A JSON object representing the configuration for this workspace .
40
+ * @param project The project to configure.
41
+ * @return A JSON object representing the configuration for this project .
42
42
*/
43
- def workspaceSetup ( workspace : Workspace ): String = {
43
+ def projectSetup ( project : Project ): String = {
44
44
def showSeq [T ](lst : Seq [T ]): String =
45
45
lst
46
46
.map(elem => '"' + elem.toString.replace('\\ ' , '/' ) + '"' )
47
47
.mkString(" [ " , " , " , " ]" )
48
48
49
- if (workspace .sources.exists(_.isInstanceOf [TastyWithPositions ])) {
50
- compileWorkspaceAndDependencies(workspace )
49
+ if (project .sources.exists(_.isInstanceOf [TastyWithPositions ])) {
50
+ compileProjectAndDependencies(project )
51
51
} else {
52
- // Compile all the dependencies of this workspace
53
- workspace .dependsOn.foreach(compileWorkspaceAndDependencies )
52
+ // Compile all the dependencies of this project
53
+ project .dependsOn.foreach(compileProjectAndDependencies )
54
54
}
55
55
56
56
s """ {
57
- | "id" : " ${workspace .name}",
57
+ | "id" : " ${project .name}",
58
58
| "compilerVersion" : " ${BuildInfo .ideTestsCompilerVersion}",
59
59
| "compilerArguments" : ${showSeq(BuildInfo .ideTestsCompilerArguments)},
60
- | "sourceDirectories" : ${showSeq(sourceDirectory(workspace , wipe = false ) :: Nil )},
61
- | "dependencyClasspath" : ${showSeq(dependencyClasspath(workspace ))},
62
- | "classDirectory" : " ${classDirectory(workspace , wipe = false ).toString.replace('\\ ' ,'/' )}"
60
+ | "sourceDirectories" : ${showSeq(sourceDirectory(project , wipe = false ) :: Nil )},
61
+ | "dependencyClasspath" : ${showSeq(dependencyClasspath(project ))},
62
+ | "classDirectory" : " ${classDirectory(project , wipe = false ).toString.replace('\\ ' ,'/' )}"
63
63
|}
64
64
| """ .stripMargin
65
65
}
66
66
67
67
Files .createDirectories(testFolder)
68
68
val configFile = testFolder.resolve(DottyLanguageServer .IDE_CONFIG_FILE )
69
- val configuration = workspaces .map(workspaceSetup ).mkString(" [" , " ," , " ]" )
69
+ val configuration = projects .map(projectSetup ).mkString(" [" , " ," , " ]" )
70
70
71
71
new PrintWriter (configFile.toString) {
72
72
write(configuration)
@@ -87,8 +87,8 @@ class TestServer(testFolder: Path, workspaces: List[Workspace]) {
87
87
* @param openInIDE If true, send `textDocument/didOpen` to the server.
88
88
* @return the file opened
89
89
*/
90
- def openCode (code : String , workspace : Workspace , fileName : String , openInIDE : Boolean ): TestFile = {
91
- val testFile = new TestFile (workspace .name + separator + fileName)
90
+ def openCode (code : String , project : Project , fileName : String , openInIDE : Boolean ): TestFile = {
91
+ val testFile = new TestFile (project .name + separator + fileName)
92
92
val tdi = new TextDocumentItem ()
93
93
tdi.setUri(testFile.uri)
94
94
tdi.setText(code)
@@ -102,24 +102,24 @@ class TestServer(testFolder: Path, workspaces: List[Workspace]) {
102
102
testFile
103
103
}
104
104
105
- private def classDirectory (workspace : Workspace , wipe : Boolean ): Path = {
106
- val path = testFolder.resolve(workspace .name).resolve(" out" )
105
+ private def classDirectory (project : Project , wipe : Boolean ): Path = {
106
+ val path = testFolder.resolve(project .name).resolve(" out" )
107
107
if (wipe) {
108
108
Directory (path).deleteRecursively()
109
109
Files .createDirectories(path)
110
110
}
111
111
path.toAbsolutePath
112
112
}
113
113
114
- private def dependencyClasspath (workspace : Workspace ): Seq [String ] = {
114
+ private def dependencyClasspath (project : Project ): Seq [String ] = {
115
115
BuildInfo .ideTestsDependencyClasspath.map(_.getAbsolutePath) ++
116
- workspace .dependsOn.flatMap { dep =>
116
+ project .dependsOn.flatMap { dep =>
117
117
classDirectory(dep, wipe = false ).toString +: dependencyClasspath(dep)
118
118
}
119
119
}.distinct
120
120
121
- private def sourceDirectory (workspace : Workspace , wipe : Boolean ): Path = {
122
- val path = TestFile .sourceDir.resolve(workspace .name).toAbsolutePath
121
+ private def sourceDirectory (project : Project , wipe : Boolean ): Path = {
122
+ val path = TestFile .sourceDir.resolve(project .name).toAbsolutePath
123
123
if (wipe) {
124
124
Directory (path).deleteRecursively()
125
125
Files .createDirectories(path)
@@ -128,14 +128,14 @@ class TestServer(testFolder: Path, workspaces: List[Workspace]) {
128
128
}
129
129
130
130
/**
131
- * Sets up the sources of the given workspace , creates the necessary directories
131
+ * Sets up the sources of the given project , creates the necessary directories
132
132
* and compile the sources.
133
133
*
134
- * @param workspace The workspace to set up.
134
+ * @param project The project to set up.
135
135
*/
136
- private def compileWorkspace ( workspace : Workspace ): Unit = {
137
- val sourcesDir = sourceDirectory(workspace , wipe = true )
138
- val sources = workspace .sources.zipWithIndex.map { case (src, id) =>
136
+ private def compileProject ( project : Project ): Unit = {
137
+ val sourcesDir = sourceDirectory(project , wipe = true )
138
+ val sources = project .sources.zipWithIndex.map { case (src, id) =>
139
139
val path = sourcesDir.resolve(src.sourceName(id)).toAbsolutePath
140
140
Files .write(path, src.text.getBytes(" UTF-8" ))
141
141
path.toString
@@ -144,8 +144,8 @@ class TestServer(testFolder: Path, workspaces: List[Workspace]) {
144
144
val compileOptions =
145
145
sources.toArray ++
146
146
Array (
147
- " -classpath" , dependencyClasspath(workspace ).mkString(pathSeparator),
148
- " -d" , classDirectory(workspace , wipe = true ).toString
147
+ " -classpath" , dependencyClasspath(project ).mkString(pathSeparator),
148
+ " -d" , classDirectory(project , wipe = true ).toString
149
149
)
150
150
val reporter = new ThrowingReporter (Reporter .NoReporter )
151
151
Main .process(compileOptions, reporter)
0 commit comments