Skip to content

Commit

Permalink
bugfix: Make sure everything uses didChange first
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Dec 10, 2024
1 parent c1dc156 commit 82ff17b
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,9 @@ abstract class MetalsLspService(
): CompletableFuture[Unit] = {
val path = params.getTextDocument.getUri.toAbsolutePath
savedFiles.add(path)
if (!buffers.contains(path)) {
buffers.put(path, path.toInput.text)
}
Future
.sequence(
List(
Expand Down
6 changes: 4 additions & 2 deletions tests/slow/src/test/scala/tests/bazel/BazelLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class BazelLspSuite
BazelBuildLayout(workspaceLayout, V.bazelScalaVersion, bazelVersion)
)
_ <- server.didOpen("Hello.scala")
_ <- server.didSave("Hello.scala") { _ =>
_ <- server.didChange("Hello.scala") { _ =>
"""|package examples.scala3
|
|sealed trait A
Expand All @@ -251,6 +251,7 @@ class BazelLspSuite
|}
|""".stripMargin
}
_ <- server.didSave("Hello.scala")(identity)
_ = assertNoDiff(
server.client.workspaceDiagnostics,
"""|Hello.scala:11:3: warning: match may not be exhaustive.
Expand All @@ -262,12 +263,13 @@ class BazelLspSuite
|""".stripMargin,
)
// warnings should not disappear after updating
_ <- server.didSave("Hello.scala") { text =>
_ <- server.didChange("Hello.scala") { text =>
s"""|$text
|
|class Additional
|""".stripMargin
}
_ <- server.didSave("Hello.scala")(identity)
_ = assertNoDiff(
server.client.workspaceDiagnostics,
"""|Hello.scala:11:3: warning: match may not be exhaustive.
Expand Down
12 changes: 8 additions & 4 deletions tests/unit/src/main/scala/tests/BaseRenameLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ abstract class BaseRenameLspSuite(name: String) extends BaseLspSuite(name) {
// possible breaking changes for testing
_ <- Future.sequence {
openedFiles.map { file =>
server.didSave(file) { code => breakingChange(code) }
server.didChange(file) { code => breakingChange(code) }
server.didSave(file)(identity)
}
}
_ = if (!expectedError) assertNoDiagnostics()
Expand All @@ -124,9 +125,12 @@ abstract class BaseRenameLspSuite(name: String) extends BaseLspSuite(name) {
Future
.sequence {
files.map { case (file, code) =>
server.didSave(file)(_ =>
code.replaceAll(allMarkersRegex, "")
)
for {
_ <- server.didChange(file)(_ =>
code.replaceAll(allMarkersRegex, "")
)
_ <- server.didSave(file)(identity)
} yield ()
}.toList

}
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/src/main/scala/tests/BaseWorksheetLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -782,12 +782,13 @@ abstract class BaseWorksheetLspSuite(
)
),
)
_ <- server.didSave("a/src/main/scala/foo/Main.worksheet.sc")(
_ <- server.didChange("a/src/main/scala/foo/Main.worksheet.sc")(
_.replace(
"Hi(1, 2, 3)",
"Hi(7, 8, 9)",
)
)
_ <- server.didSave("a/src/main/scala/foo/Main.worksheet.sc")(identity)
export = server.exportEvaluation(
"a/src/main/scala/foo/Main.worksheet.sc"
)
Expand Down
1 change: 1 addition & 0 deletions tests/unit/src/main/scala/tests/TestingServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@ final case class TestingServer(
val abspath = toPath(filename)
val oldText = abspath.toInputFromBuffers(buffers).text
val newText = fn(oldText)
buffers.put(abspath, newText)
didChange(filename, newText)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ abstract class BaseNonCompilingLspSuite(name: String)
|}
|""".stripMargin
input = newText.replace("<<", "").replace(">>", "")
_ <- server.didSave("a/src/main/scala/a/A.scala") { _ =>
_ <- server.didChange("a/src/main/scala/a/A.scala") { _ =>
newText.replace("<<", "").replace(">>", "")
}
_ <- server.didSave("a/src/main/scala/a/A.scala")(identity)
_ <-
server
.assertCodeAction(
Expand All @@ -119,9 +120,10 @@ abstract class BaseNonCompilingLspSuite(name: String)
kind = Nil,
)
// make sure that the now change UniqueObject is not suggested
_ <- server.didSave("a/src/main/scala/a/A.scala") { _ =>
_ <- server.didChange("a/src/main/scala/a/A.scala") { _ =>
input.replace("UniqueObjectOther", "UniqueObject")
}
_ <- server.didSave("a/src/main/scala/a/A.scala")(identity)
_ <-
server
.assertCodeAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ class BuildServerConnectionLspSuite
_ = server.server.bspSession.get.cancel()
_ = assertNoDiagnostics()
_ <- server.executeCommand(ServerCommands.ConnectBuildServer)
_ <- server.didSave("a/src/main/scala/a/A.scala")(
_ <- server.didChange("a/src/main/scala/a/A.scala")(
_.replace("val n = 42", "val n: String = 42")
)
_ <- server.didSave("a/src/main/scala/a/A.scala")(identity)
_ = assertNoDiff(
client.workspaceDiagnostics,
"""|a/src/main/scala/a/A.scala:3:19: error: type mismatch;
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/src/test/scala/tests/DefinitionLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,10 @@ class DefinitionLspSuite
|}
""".stripMargin,
)
_ <- server.didSave("a/src/main/scala/a/Main.scala")(
_ <- server.didChange("a/src/main/scala/a/Main.scala")(
_.replace("max(1, 2)", "max")
)
_ <- server.didSave("a/src/main/scala/a/Main.scala")(identity)
_ = assertNoDiff(
server.workspaceDefinitions,
"""|/a/src/main/scala/a/Main.scala
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/src/test/scala/tests/DiagnosticsLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,10 @@ class DiagnosticsLspSuite extends BaseLspSuite("diagnostics") {
| ^^
|""".stripMargin,
)
_ <- server.didSave("a/src/main/scala/a/A.scala")(
_ <- server.didChange("a/src/main/scala/a/A.scala")(
_.replace("val n: Int = \"\"", "val n: Int = \" ")
)
_ <- server.didSave("a/src/main/scala/a/A.scala")(identity)
_ = assertNoDiff(
client.workspaceDiagnostics,
"""|a/src/main/scala/a/A.scala:2:16: error: unclosed string literal
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/src/test/scala/tests/DidFocusLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,26 @@ class DidFocusWhileCompilingLspSuite
|""".stripMargin
}
_ = fakeTime.elapseSeconds(10)
_ <- server.didSave("a/src/main/scala/a/A.scala")(
_ <- server.didChange("a/src/main/scala/a/A.scala")(
_.replace("1", "\"\"")
)
_ <- server.didSave("a/src/main/scala/a/A.scala")(identity)
_ = assertNoDiff(
client.workspaceDiagnostics,
xMismatch,
)
_ <- server.didSave("b/src/main/scala/b/B.scala")(
_ <- server.didChange("b/src/main/scala/b/B.scala")(
_.replace("2", "\"\"")
)
_ <- server.didSave("b/src/main/scala/b/B.scala")(identity)
_ = assertNoDiff(
client.workspaceDiagnostics,
xMismatch,
)
_ <- server.didSave("a/src/main/scala/a/A.scala")(
_ <- server.didChange("a/src/main/scala/a/A.scala")(
_.replace("Int", "String")
)
_ <- server.didSave("a/src/main/scala/a/A.scala")(identity)
_ = assertNoDiff(
client.workspaceDiagnostics,
"""|b/src/main/scala/b/B.scala:3:16: error: type mismatch;
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/src/test/scala/tests/FingerprintsLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ class FingerprintsLspSuite extends BaseLspSuite("fingerprints") {
_ <- server.executeCommand(ServerCommands.CascadeCompile)
_ = assertNoDiff(client.workspaceDiagnostics, "")
_ = server.assertReferenceDefinitionBijection()
_ <- server.didSave("a/src/main/scala/a/Names.scala")(text =>
_ <- server.didChange("a/src/main/scala/a/Names.scala")(text =>
text.replace("+ surname", "+ surname2")
)
_ <- server.didSave("a/src/main/scala/a/Adresses.scala")(text =>
_ <- server.didSave("a/src/main/scala/a/Names.scala")(identity)

_ <- server.didChange("a/src/main/scala/a/Adresses.scala")(text =>
text.replace("+ number", "+ number2")
)
_ <- server.didSave("a/src/main/scala/a/Names.scala")(identity)
_ = assertNoDiff(
client.workspaceDiagnostics,
"""|a/src/main/scala/a/Adresses.scala:5:44: error: not found: value number2
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/src/test/scala/tests/TreeViewLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,10 @@ class TreeViewLspSuite extends BaseLspSuite("tree-view") {
|c symbol-variable
|""".stripMargin,
)
_ <- server.didSave("a/src/main/scala/a/Zero.scala") { text =>
_ <- server.didChange("a/src/main/scala/a/Zero.scala") { text =>
text.replace("val a = 1", "val a = 1\nval b = 1.0")
}
_ <- server.didSave("a/src/main/scala/a/Zero.scala")(identity)
_ = assertEquals(
server.client.workspaceTreeViewChanges,
s"metalsPackages projects-$folder:${server.buildTarget("a")}!/_root_/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class BestEffortCompilationSuite
|""".stripMargin
}
_ <- server.didOpen("a/src/main/scala/a/A.scala")
_ <- server.didOpen("b/src/main/scala/b/B.scala")
_ = assertNoDiff(
client.workspaceDiagnostics,
"""|a/src/main/scala/a/A.scala:5:3: error: value completionUnknown is not a member of object B
Expand Down

0 comments on commit 82ff17b

Please sign in to comment.