Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Apr 19, 2024
1 parent b1b8e73 commit 16d3bea
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
Expand Up @@ -218,7 +218,6 @@ class MetalsGlobal(
else false
}

// TODO the same in autoimports TEST
if (query.isEmpty) SymbolSearch.Result.INCOMPLETE
else {
val context = doLocateContext(pos)
Expand Down
69 changes: 68 additions & 1 deletion tests/unit/src/test/scala/tests/CompilersLspSuite.scala
Expand Up @@ -135,7 +135,7 @@ class CompilersLspSuite extends BaseCompletionLspSuite("compilers") {
|}
|""".stripMargin,
)
// check if the change name is piecked up despite the file not compiling
// check if the change name is picked up despite the file not compiling
newText = """|package a
|
|class A {
Expand Down Expand Up @@ -334,4 +334,71 @@ class CompilersLspSuite extends BaseCompletionLspSuite("compilers") {
)
} yield ()
}

test("imports-for-non-compiling") {
cleanWorkspace()
for {
_ <- initialize(
"""/metals.json
|{
| "a": {}
|}
|/a/src/main/scala/a/A.scala
|package a
|
|/a/src/main/scala/b/B.scala
|package b
|
|object O {
| class UniqueObject {
| }
|}
|""".stripMargin
)
_ <- server.didOpen("a/src/main/scala/b/B.scala")
_ <- server.didChange("a/src/main/scala/b/B.scala") { _ =>
"""|package b
|object W {
| class UniqueObject {
| val i: Int = "aaa"
| }
|}
|""".stripMargin
}
_ <- server.didSave("a/src/main/scala/b/B.scala")(identity)
// check if the change name is picked up despite the file not compiling
newText = """|package a
|
|object A {
| // @@
| val k: <<UniqueObject>> = ???
|}
|""".stripMargin
input = newText.replace("<<", "").replace(">>", "")
_ <- server.didChange("a/src/main/scala/a/A.scala")(_ => input)
_ <- server.didSave("a/src/main/scala/a/A.scala")(identity)
codeActions <-
server
.assertCodeAction(
"a/src/main/scala/a/A.scala",
newText,
s"""|${ImportMissingSymbol.title("UniqueObject", "b.W")}
|${CreateNewSymbol.title("UniqueObject")}
|""".stripMargin,
kind = Nil,
)
_ <- assertCompletionEdit(
"UniqueObject@@",
"""|package a
|
|import b.W.UniqueObject
|
|object A {
| UniqueObject
| val k: UniqueObject = ???
|}
|""".stripMargin,
)
} yield ()
}
}

0 comments on commit 16d3bea

Please sign in to comment.