Skip to content

Commit 82d37e5

Browse files
committed
Rename Workspace to Project
1 parent 6751616 commit 82d37e5

File tree

4 files changed

+80
-80
lines changed

4 files changed

+80
-80
lines changed

language-server/test/dotty/tools/languageserver/DefinitionTest.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@ class DefinitionTest {
3737
.definition(m13 to m14, List(m3 to m4))
3838
}
3939

40-
@Test def classDefinitionDifferentWorkspace: Unit = {
41-
val w0 = Workspace.withSources(
40+
@Test def classDefinitionDifferentProject: Unit = {
41+
val p0 = Project.withSources(
4242
code"""class ${m1}Foo${m2}"""
4343
)
4444

45-
val w1 = Workspace.dependingOn(w0).withSources(
45+
val p1 = Project.dependingOn(p0).withSources(
4646
code"""class Bar { new ${m3}Foo${m4} }"""
4747
)
4848

49-
val w2 = Workspace.dependingOn(w1).withSources(
49+
val p2 = Project.dependingOn(p1).withSources(
5050
code"""class Baz extends ${m5}Foo${m6}"""
5151
)
5252

53-
withWorkspaces(w0, w1, w2)
53+
withProjects(p0, p1, p2)
5454
.definition(m1 to m2, List(m1 to m2))
5555
.definition(m3 to m4, List(m1 to m2))
5656
.definition(m5 to m6, List(m1 to m2))

language-server/test/dotty/tools/languageserver/util/Code.scala

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ object Code {
110110
}
111111
}
112112

113-
/** A new `CodeTester` working with a single workspace containing `sources`. */
114-
def withSources(sources: SourceWithPositions*): CodeTester = withWorkspaces(Workspace(sources.toList))
113+
/** A new `CodeTester` working with a single project containing `sources`. */
114+
def withSources(sources: SourceWithPositions*): CodeTester = withProjects(Project(sources.toList))
115115

116-
/** A new `CodeTester` working with `workspaces`. */
117-
def withWorkspaces(workspaces: Workspace*): CodeTester = new CodeTester(workspaces.toList)
116+
/** A new `CodeTester` working with `projects`. */
117+
def withProjects(projects: Project*): CodeTester = new CodeTester(projects.toList)
118118

119119
sealed trait SourceWithPositions {
120120

@@ -127,7 +127,7 @@ object Code {
127127
/** The positions of the markers that have been set. */
128128
def positions: List[(CodeMarker, Int, Int)]
129129

130-
/** A new `CodeTester` with only this source in the workspace. */
130+
/** A new `CodeTester` with only this source in the project. */
131131
def withSource: CodeTester = withSources(this)
132132

133133
}
@@ -165,40 +165,40 @@ object Code {
165165
/**
166166
* A group of sources belonging to the same project.
167167
*
168-
* @param sources The sources that this workspace holds.
169-
* @param name The name of this workspace
170-
* @param dependsOn The other workspaces on which this workspace depend.
168+
* @param sources The sources that this project holds.
169+
* @param name The name of this project
170+
* @param dependsOn The other projects on which this project depend.
171171
*/
172-
case class Workspace(sources: List[SourceWithPositions],
173-
name: String = Workspace.freshName,
174-
dependsOn: List[Workspace] = Nil) {
172+
case class Project(sources: List[SourceWithPositions],
173+
name: String = Project.freshName,
174+
dependsOn: List[Project] = Nil) {
175175

176176
/**
177-
* Add `sources` to the sources of this workspace.
177+
* Add `sources` to the sources of this project.
178178
*/
179-
def withSources(sources: SourceWithPositions*): Workspace = copy(sources = this.sources ::: sources.toList)
179+
def withSources(sources: SourceWithPositions*): Project = copy(sources = this.sources ::: sources.toList)
180180

181181
}
182182

183-
object Workspace {
183+
object Project {
184184
private[this] val count = new java.util.concurrent.atomic.AtomicInteger()
185-
private def freshName: String = s"workspace${count.incrementAndGet()}"
185+
private def freshName: String = s"project${count.incrementAndGet()}"
186186

187187
/**
188-
* Creates a new workspace that depends on `workspaces`.
188+
* Creates a new project that depends on `projects`.
189189
*
190-
* @param workspaces The dependencies of the new workspace.
191-
* @return An empty workspace with a dependency on the specified workspaces.
190+
* @param projects The dependencies of the new project.
191+
* @return An empty project with a dependency on the specified projects.
192192
*/
193-
def dependingOn(workspaces: Workspace*) = new Workspace(Nil, dependsOn = workspaces.toList)
193+
def dependingOn(projects: Project*) = new Project(Nil, dependsOn = projects.toList)
194194

195195
/**
196-
* Create a new workspace with the given sources.
196+
* Create a new project with the given sources.
197197
*
198-
* @param sources The sources to add to this workspace.
199-
* @return a new workspace containing the specified sources.
198+
* @param sources The sources to add to this project.
199+
* @return a new project containing the specified sources.
200200
*/
201-
def withSources(sources: SourceWithPositions*): Workspace = new Workspace(sources.toList)
201+
def withSources(sources: SourceWithPositions*): Project = new Project(sources.toList)
202202
}
203203

204204
}

language-server/test/dotty/tools/languageserver/util/CodeTester.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ import dotty.tools.languageserver.util.server.{TestFile, TestServer}
77
import org.eclipse.lsp4j.{CompletionItemKind, DocumentHighlightKind}
88

99
/**
10-
* Simulates an LSP client for test in a workspace defined by `sources`.
10+
* Simulates an LSP client for test in a project defined by `sources`.
1111
*
12-
* @param sources The list of sources in the workspace
12+
* @param sources The list of sources in the project
1313
*/
14-
class CodeTester(workspaces: List[Workspace]) {
14+
class CodeTester(projects: List[Project]) {
1515

16-
private val testServer = new TestServer(TestFile.testDir, workspaces)
16+
private val testServer = new TestServer(TestFile.testDir, projects)
1717

18-
private val sources = for { workspace <- workspaces
19-
source <- workspace.sources } yield (workspace, source)
18+
private val sources = for { project <- projects
19+
source <- project.sources } yield (project, source)
2020

2121
private val files =
22-
for { workspace <- workspaces
23-
(source, id) <- workspace.sources.zipWithIndex } yield source match {
24-
case src @ TastyWithPositions(text, _) => testServer.openCode(text, workspace, src.sourceName(id), openInIDE = false)
25-
case other => testServer.openCode(other.text, workspace, other.sourceName(id), openInIDE = true)
22+
for { project <- projects
23+
(source, id) <- project.sources.zipWithIndex } yield source match {
24+
case src @ TastyWithPositions(text, _) => testServer.openCode(text, project, src.sourceName(id), openInIDE = false)
25+
case other => testServer.openCode(other.text, project, other.sourceName(id), openInIDE = true)
2626
}
2727

2828
private val positions: PositionContext = getPositions(files)
@@ -165,8 +165,8 @@ class CodeTester(workspaces: List[Workspace]) {
165165
case ex: AssertionError =>
166166
val sourcesStr =
167167
sources.zip(files).map {
168-
case ((workspace, source), file) =>
169-
s"""// ${file.file} in workspace ${workspace.name}
168+
case ((project, source), file) =>
169+
s"""// ${file.file} in project ${project.name}
170170
|${source.text}""".stripMargin
171171
}.mkString(System.lineSeparator)
172172

language-server/test/dotty/tools/languageserver/util/server/TestServer.scala

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,63 +10,63 @@ import dotty.tools.dotc.Main
1010
import dotty.tools.dotc.reporting.{Reporter, ThrowingReporter}
1111
import dotty.tools.io.Directory
1212
import dotty.tools.languageserver.DottyLanguageServer
13-
import dotty.tools.languageserver.util.Code.{TastyWithPositions, Workspace}
13+
import dotty.tools.languageserver.util.Code.{TastyWithPositions, Project}
1414
import 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

Comments
 (0)