@@ -10,63 +10,63 @@ import dotty.tools.dotc.Main
1010import dotty .tools .dotc .reporting .{Reporter , ThrowingReporter }
1111import dotty .tools .io .Directory
1212import dotty .tools .languageserver .DottyLanguageServer
13- import dotty .tools .languageserver .util .Code .{TastyWithPositions , Workspace }
13+ import dotty .tools .languageserver .util .Code .{TastyWithPositions , Project }
1414import org .eclipse .lsp4j .{ DidOpenTextDocumentParams , InitializeParams , InitializeResult , TextDocumentItem }
1515
16- class TestServer (testFolder : Path , workspaces : List [Workspace ]) {
16+ class TestServer (testFolder : Path , projects : List [Project ]) {
1717
1818 val server = new DottyLanguageServer
1919 var client : TestClient = _
2020
2121 init()
2222
2323 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
3232 }
3333
3434 /**
35- * Set up given workspace , return JSON config.
35+ * Set up given project , return JSON config.
3636 *
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 .
3939 *
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 .
4242 */
43- def workspaceSetup ( workspace : Workspace ): String = {
43+ def projectSetup ( project : Project ): String = {
4444 def showSeq [T ](lst : Seq [T ]): String =
4545 lst
4646 .map(elem => '"' + elem.toString.replace('\\ ' , '/' ) + '"' )
4747 .mkString(" [ " , " , " , " ]" )
4848
49- if (workspace .sources.exists(_.isInstanceOf [TastyWithPositions ])) {
50- compileWorkspaceAndDependencies(workspace )
49+ if (project .sources.exists(_.isInstanceOf [TastyWithPositions ])) {
50+ compileProjectAndDependencies(project )
5151 } 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 )
5454 }
5555
5656 s """ {
57- | "id" : " ${workspace .name}",
57+ | "id" : " ${project .name}",
5858 | "compilerVersion" : " ${BuildInfo .ideTestsCompilerVersion}",
5959 | "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('\\ ' ,'/' )}"
6363 |}
6464 | """ .stripMargin
6565 }
6666
6767 Files .createDirectories(testFolder)
6868 val configFile = testFolder.resolve(DottyLanguageServer .IDE_CONFIG_FILE )
69- val configuration = workspaces .map(workspaceSetup ).mkString(" [" , " ," , " ]" )
69+ val configuration = projects .map(projectSetup ).mkString(" [" , " ," , " ]" )
7070
7171 new PrintWriter (configFile.toString) {
7272 write(configuration)
@@ -87,8 +87,8 @@ class TestServer(testFolder: Path, workspaces: List[Workspace]) {
8787 * @param openInIDE If true, send `textDocument/didOpen` to the server.
8888 * @return the file opened
8989 */
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)
9292 val tdi = new TextDocumentItem ()
9393 tdi.setUri(testFile.uri)
9494 tdi.setText(code)
@@ -102,24 +102,24 @@ class TestServer(testFolder: Path, workspaces: List[Workspace]) {
102102 testFile
103103 }
104104
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" )
107107 if (wipe) {
108108 Directory (path).deleteRecursively()
109109 Files .createDirectories(path)
110110 }
111111 path.toAbsolutePath
112112 }
113113
114- private def dependencyClasspath (workspace : Workspace ): Seq [String ] = {
114+ private def dependencyClasspath (project : Project ): Seq [String ] = {
115115 BuildInfo .ideTestsDependencyClasspath.map(_.getAbsolutePath) ++
116- workspace .dependsOn.flatMap { dep =>
116+ project .dependsOn.flatMap { dep =>
117117 classDirectory(dep, wipe = false ).toString +: dependencyClasspath(dep)
118118 }
119119 }.distinct
120120
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
123123 if (wipe) {
124124 Directory (path).deleteRecursively()
125125 Files .createDirectories(path)
@@ -128,14 +128,14 @@ class TestServer(testFolder: Path, workspaces: List[Workspace]) {
128128 }
129129
130130 /**
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
132132 * and compile the sources.
133133 *
134- * @param workspace The workspace to set up.
134+ * @param project The project to set up.
135135 */
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) =>
139139 val path = sourcesDir.resolve(src.sourceName(id)).toAbsolutePath
140140 Files .write(path, src.text.getBytes(" UTF-8" ))
141141 path.toString
@@ -144,8 +144,8 @@ class TestServer(testFolder: Path, workspaces: List[Workspace]) {
144144 val compileOptions =
145145 sources.toArray ++
146146 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
149149 )
150150 val reporter = new ThrowingReporter (Reporter .NoReporter )
151151 Main .process(compileOptions, reporter)
0 commit comments