Skip to content

Commit

Permalink
refactor: Remove fn from didSave, force didChange before to simulate …
Browse files Browse the repository at this point in the history
…editor behaviour better
  • Loading branch information
tgodzik committed Dec 23, 2024
1 parent 6a1cd9b commit 3aba01d
Show file tree
Hide file tree
Showing 46 changed files with 278 additions and 199 deletions.
28 changes: 15 additions & 13 deletions tests/slow/src/test/scala/tests/bazel/BazelLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ class BazelLspSuite
_ = assertStatus(_.isInstalled)
_ = assertNoDiff(client.workspaceDiagnostics, "")
_ <- server.didChange("WORKSPACE")(_ + "\n# comment")
_ <- server.didSave("WORKSPACE")(identity)
_ <- server.didSave("WORKSPACE")
// Comment changes do not trigger "re-import project" request
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ <- server.didChange("Hello.scala") { text =>
text.replace("def hello: String", "def hello: Int")
}
_ <- server.didSave("Hello.scala")(identity)
_ <- server.didSave("Hello.scala")
_ = assertNoDiff(
client.workspaceDiagnostics,
"""|Hello.scala:4:20: error: type mismatch;
Expand All @@ -78,7 +78,7 @@ class BazelLspSuite
}
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ = client.generateBspAndConnect = GenerateBspAndConnect.yes
_ <- server.didSave(s"BUILD")(identity)
_ <- server.didSave(s"BUILD")
} yield {
assertNoDiff(
client.workspaceMessageRequests,
Expand All @@ -105,7 +105,7 @@ class BazelLspSuite
_ <- server.didChange(s"BUILD") { text =>
text.replace("\"hello\"", "\"hello1\"")
}
_ <- server.didSave(s"BUILD")(identity)
_ <- server.didSave(s"BUILD")
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ = server.headServer.connectionProvider.buildServerPromise = Promise()
_ <- server.executeCommand(ServerCommands.GenerateBspConfig)
Expand All @@ -114,7 +114,7 @@ class BazelLspSuite
_ <- server.didChange("Hello.scala") { text =>
text.replace("def hello: String", "def hello: Int")
}
_ <- server.didSave("Hello.scala")(identity)
_ <- server.didSave("Hello.scala")
_ = assertNoDiff(
client.workspaceDiagnostics,
"""|Hello.scala:4:20: error: type mismatch;
Expand Down Expand Up @@ -158,7 +158,7 @@ class BazelLspSuite
_ <- server.didChange(s"BUILD") { text =>
text.replace("\"hello\"", "\"hello1\"")
}
_ <- server.didSave(s"BUILD")(identity)
_ <- server.didSave(s"BUILD")
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ = server.headServer.connectionProvider.buildServerPromise = Promise()
_ <- server.executeCommand(ServerCommands.ImportBuild)
Expand Down Expand Up @@ -209,7 +209,7 @@ class BazelLspSuite
)
_ <- server.didOpen("Hello.scala")
_ <- server.didOpen("Main.scala")
_ <- server.didSave("Main.scala")(identity)
_ <- server.didSave("Main.scala")
references <- server.references("Hello.scala", "hello")
_ = assertNoDiff(
references,
Expand Down Expand Up @@ -251,7 +251,7 @@ class BazelLspSuite
|}
|""".stripMargin
}
_ <- server.didSave("Hello.scala")(identity)
_ <- server.didSave("Hello.scala")
_ = assertNoDiff(
server.client.workspaceDiagnostics,
"""|Hello.scala:11:3: warning: match may not be exhaustive.
Expand All @@ -269,7 +269,7 @@ class BazelLspSuite
|class Additional
|""".stripMargin
}
_ <- server.didSave("Hello.scala")(identity)
_ <- server.didSave("Hello.scala")
_ = assertNoDiff(
server.client.workspaceDiagnostics,
"""|Hello.scala:11:3: warning: match may not be exhaustive.
Expand Down Expand Up @@ -315,7 +315,7 @@ class BazelLspSuite
_ <- server.didChange("Hello.scala") { text =>
text.replace("def hello: String", "def hello: Int")
}
_ <- server.didSave("Hello.scala")(identity)
_ <- server.didSave("Hello.scala")
_ = assertNoDiff(
client.workspaceDiagnostics,
"""|Hello.scala:4:20: error: type mismatch;
Expand Down Expand Up @@ -353,7 +353,7 @@ class BazelLspSuite
_ <- server.didChange("Hello.scala") { text =>
text.replace("def hello: String", "def hello: Int")
}
_ <- server.didSave("Hello.scala")(identity)
_ <- server.didSave("Hello.scala")
_ = assertNoDiff(
client.workspaceDiagnostics,
"""|Hello.scala:4:20: error: type mismatch;
Expand All @@ -367,12 +367,14 @@ class BazelLspSuite
)
_ = client.messageRequests.clear()
_ <- server.didOpen("Hello.scala")
_ <- server.didSave("Hello.scala") { text =>
_ <- server.didChange("Hello.scala") { text =>
text.replace("def hello: Int", "def hello: String")
}
_ <- server.didSave("Hello.scala")
_ = assertNoDiagnostics()
_ <- server.didOpen("projectview.bazelproject")
_ <- server.didSave("projectview.bazelproject")(_ => "")
_ <- server.didChange("projectview.bazelproject")(_ => "")
_ <- server.didSave("projectview.bazelproject")
_ = assertNoDiff(
client.workspaceMessageRequests,
ImportBuildChanges.params("bazel").getMessage(),
Expand Down
4 changes: 2 additions & 2 deletions tests/slow/src/test/scala/tests/feature/AmmoniteSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Ammonite213Suite extends tests.BaseAmmoniteSuite(V.ammonite213) {
|""".stripMargin
)
_ <- server.didOpen("main.sc")
_ <- server.didSave("main.sc")(identity)
_ <- server.didSave("main.sc")
_ <- server.executeCommand(ServerCommands.StartAmmoniteBuildServer)

groupCompletionList <- server.completion(
Expand Down Expand Up @@ -52,7 +52,7 @@ class Ammonite212Suite extends tests.BaseAmmoniteSuite(V.ammonite212) {
|""".stripMargin
)
_ <- server.didOpen("main.sc")
_ <- server.didSave("main.sc")(identity)
_ <- server.didSave("main.sc")
_ <- server.executeCommand(ServerCommands.StartAmmoniteBuildServer)
} yield {
assertEmpty(client.workspaceErrorShowMessages)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class MultipleBuildFilesLspSuite
text + "\nversion := \"1.0.0\"\n"
}
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ <- server.didSave("build.sbt")(identity)
_ <- server.didSave("build.sbt")
} yield {
assertNoDiff(
client.workspaceMessageRequests,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ class SyntaxErrorLspSuite extends BaseLspSuite("syntax-error") {
_ = assertNoDiff(client.workspaceDiagnostics, "")
_ <- server.didOpen("Main.scala")
_ <- server.didOpen("project/plugins.sbt")
_ <- server.didSave("Main.scala")(_ => "object A\n")
_ <- server.didChange("Main.scala")(_ => "object A\n")
_ <- server.didSave("Main.scala")
_ = assertNoDiff(
client.workspaceDiagnostics,
"""|project/plugins.sbt:1:8: error: `identifier` expected but `object` found
|object object val x = 1
| ^^^^^^
|""".stripMargin,
)
_ <- server.didSave("project/plugins.sbt")(_ => "lazy val x = 1\n")
_ <- server.didChange("project/plugins.sbt")(_ => "lazy val x = 1\n")
_ <- server.didSave("project/plugins.sbt")
_ = assertNoDiff(client.workspaceDiagnostics, "")
} yield ()
}
Expand Down
23 changes: 13 additions & 10 deletions tests/slow/src/test/scala/tests/gradle/GradleLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ class GradleLspSuite extends BaseImportSuite("gradle-import") {
_ = assertStatus(_.isInstalled)
_ <- server.didChange("build.gradle")(_ + "\n// comment")
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ <- server.didSave("build.gradle")(identity)
_ <- server.didSave("build.gradle")
// Comment changes do not trigger "re-import project" request
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ <- server.didChange("build.gradle") { text =>
text + "\ndef version = \"1.0.0\"\n"
}
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ = client.importBuildChanges = ImportBuildChanges.yes
_ <- server.didSave("build.gradle")(identity)
_ <- server.didSave("build.gradle")
} yield {
assertNoDiff(
client.workspaceMessageRequests,
Expand Down Expand Up @@ -97,7 +97,7 @@ class GradleLspSuite extends BaseImportSuite("gradle-import") {
workspace.resolve("inner"),
)
_ <- server.didOpen("inner/src/main/scala/A.scala")
_ <- server.didSave("inner/src/main/scala/A.scala")(identity)
_ <- server.didSave("inner/src/main/scala/A.scala")
_ = assertNoDiff(
client.pathDiagnostics("inner/src/main/scala/A.scala"),
"""|inner/src/main/scala/A.scala:2:18: error: type mismatch;
Expand Down Expand Up @@ -148,14 +148,14 @@ class GradleLspSuite extends BaseImportSuite("gradle-import") {
_ = assertStatus(_.isInstalled)
_ <- server.didChange("build.gradle")(_ + "\n// comment")
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ <- server.didSave("build.gradle")(identity)
_ <- server.didSave("build.gradle")
// Comment changes do not trigger "re-import project" request
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ <- server.didChange("build.gradle") { text =>
text + "\ndef version = \"1.0.0\"\n"
}
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ <- server.didSave("build.gradle")(identity)
_ <- server.didSave("build.gradle")
} yield {
assertNoDiff(
client.workspaceMessageRequests,
Expand Down Expand Up @@ -196,7 +196,7 @@ class GradleLspSuite extends BaseImportSuite("gradle-import") {
)
_ = client.messageRequests.clear()
_ = assertStatus(_.isInstalled)
_ <- server.didSave("src/main/java/a/Main.java")(identity)
_ <- server.didSave("src/main/java/a/Main.java")
debugger <- server.startDebugging(
javaOnlyTestName,
DebugSessionParamsDataKind.SCALA_MAIN_CLASS,
Expand Down Expand Up @@ -301,19 +301,21 @@ class GradleLspSuite extends BaseImportSuite("gradle-import") {
_ <- server.didOpen("src/main/scala/reload/Main.scala")
_ = assertNoDiff(client.workspaceDiagnostics, "")
_ = client.importBuildChanges = ImportBuildChanges.yes
_ <- server.didSave("build.gradle") { text =>
_ <- server.didChange("build.gradle") { text =>
s"""$text
|dependencies {
| implementation 'com.lihaoyi:sourcecode_2.12:0.1.4'
|}
|""".stripMargin
}
_ <- server.didSave("build.gradle")
_ <-
server
.didSave("src/main/scala/reload/Main.scala") { text =>
.didChange("src/main/scala/reload/Main.scala") { text =>
text.replaceAll("\"", "")
}
.recover { case e => scribe.error("compile", e) }
_ <- server.didSave("src/main/scala/reload/Main.scala")
_ = assertNoDiff(client.workspaceDiagnostics, "")
} yield ()
}
Expand All @@ -339,7 +341,7 @@ class GradleLspSuite extends BaseImportSuite("gradle-import") {
)
_ = assertStatus(!_.isInstalled)
_ = client.messageRequests.clear()
_ <- server.didSave("build.gradle") { _ =>
_ <- server.didChange("build.gradle") { _ =>
s"""|plugins {
| id 'scala'
|}
Expand All @@ -351,6 +353,7 @@ class GradleLspSuite extends BaseImportSuite("gradle-import") {
|}
|""".stripMargin
}
_ <- server.didSave("build.gradle")
_ = assertNoDiff(
client.workspaceMessageRequests,
importBuildMessage,
Expand Down Expand Up @@ -528,7 +531,7 @@ class GradleLspSuite extends BaseImportSuite("gradle-import") {
"rootProject.name = 'new-name'\n"
)
_ = client.importBuildChanges = ImportBuildChanges.yes
_ <- server.didSave("inner/settings.gradle")(identity)
_ <- server.didSave("inner/settings.gradle")
_ = assert(
server.server.buildTargets.all
.exists(_.getDisplayName() == "new-name"),
Expand Down
15 changes: 10 additions & 5 deletions tests/slow/src/test/scala/tests/maven/MavenLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ class MavenLspSuite extends BaseImportSuite("maven-import") {
.replace("<!--URL-->", "<!--Your comment--><!--MARKER-->")
)
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ <- server.didSave("pom.xml")(identity)
_ <- server.didSave("pom.xml")
// Comment changes do not trigger "re-import project" request
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ <- server.didChange("pom.xml") { _ =>
defaultPom.replace("<!--URL-->", "http://www.example.com")
}
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ = client.importBuildChanges = ImportBuildChanges.yes
_ <- server.didSave("pom.xml")(identity)
_ <- server.didSave("pom.xml")
} yield {
assertNoDiff(
client.workspaceMessageRequests,
Expand Down Expand Up @@ -146,7 +146,7 @@ class MavenLspSuite extends BaseImportSuite("maven-import") {
_ <- server.didOpen("src/main/scala/reload/Main.scala")
_ = assertNoDiff(client.workspaceDiagnostics, "")
_ = client.importBuildChanges = ImportBuildChanges.yes
_ <- server.didSave("pom.xml") { text =>
_ <- server.didChange("pom.xml") { text =>
text.replace(
"<!--DEPENDENCY-->",
s"""
Expand All @@ -158,12 +158,16 @@ class MavenLspSuite extends BaseImportSuite("maven-import") {
|""".stripMargin,
)
}
_ <- server.didSave("pom.xml")
_ <-
server
.didSave("src/main/scala/reload/Main.scala") { text =>
.didChange("src/main/scala/reload/Main.scala") { text =>
text.replaceAll("\"", "")
}
.recover { case e => scribe.error("compile", e) }
_ <-
server
.didSave("src/main/scala/reload/Main.scala")
_ = assertNoDiff(client.workspaceDiagnostics, "")
} yield ()
}
Expand Down Expand Up @@ -197,7 +201,8 @@ class MavenLspSuite extends BaseImportSuite("maven-import") {
)
_ = assertStatus(!_.isInstalled)
_ = client.messageRequests.clear()
_ <- server.didSave("pom.xml")(_ => defaultPom)
_ <- server.didChange("pom.xml")(_ => defaultPom)
_ <- server.didSave("pom.xml")
_ = assertNoDiff(
client.workspaceMessageRequests,
importBuildMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ class MillDebugDiscoverySuite
)
)
_ <- server.didOpen("a/src/Main.scala")
_ <- server.didSave("a/src/Main.scala")(
identity
_ <- server.didSave(
"a/src/Main.scala"
) // making sure it gets compiled to the correct destination
_ <- server.didOpen(barPath)
_ <- server.didSave(barPath)(identity)
_ <- server.didSave(barPath)
_ <- server.waitFor(TimeUnit.SECONDS.toMillis(10))
debugger <- server.startDebuggingUnresolved(
new DebugDiscoveryParams(
Expand Down Expand Up @@ -108,7 +108,7 @@ class MillDebugDiscoverySuite
)
)
_ <- server.didOpen(fooPath)
_ <- server.didSave(fooPath)(identity)
_ <- server.didSave(fooPath)
_ <- server.waitFor(TimeUnit.SECONDS.toMillis(10))
debugger <- server.startDebugging(
"a.test",
Expand Down Expand Up @@ -148,7 +148,7 @@ class MillDebugDiscoverySuite
)
)
_ <- server.didOpen(fooPath)
_ <- server.didSave(fooPath)(identity)
_ <- server.didSave(fooPath)
_ <- server.waitFor(TimeUnit.SECONDS.toMillis(10))
debugger <- server.startDebugging(
"a.test",
Expand Down
Loading

0 comments on commit 3aba01d

Please sign in to comment.