Skip to content

Commit

Permalink
bugfix: textDocument/documentSymbol for scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek authored and tgodzik committed Jul 10, 2023
1 parent 993141a commit f9bd535
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ final class DocumentSymbolProvider(
addChild(s"new $name", SymbolKind.Interface, t.pos, selection, "")
newOwner()
} else continue()
case _: Source | _: Template =>
case _: Source | _: Template | _: MultiSource =>
continue()
case block: Term.Block =>
if (owner.getName() == "try") {
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/src/main/scala/tests/TestingClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class TestingClient(workspace: AbsolutePath, val buffers: Buffers)
actions =>
actions.find(_.getTitle == "a.Main").get
}
var importScalaCliScript = new MessageActionItem(ImportScalaScript.dismiss)

val resources = new ResourceOperations(buffers)
val diagnostics: TrieMap[AbsolutePath, Seq[Diagnostic]] =
Expand Down Expand Up @@ -336,6 +337,8 @@ class TestingClient(workspace: AbsolutePath, val buffers: Buffers)
chooseMainClass(params.getActions.asScala.toSeq)
} else if (isNewBuildToolDetectedMessage()) {
switchBuildTool
} else if (ImportScalaScript.params() == params) {
importScalaCliScript
} else {
throw new IllegalArgumentException(params.toString)
}
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/src/test/scala/tests/DocumentSymbolLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tests
class DocumentSymbolLspSuite extends BaseLspSuite("documentSymbol") {

test("parse-error") {
cleanWorkspace()
for {
// start with code that does not parse (notice the first char in Main.scala)
_ <- initialize(
Expand Down Expand Up @@ -77,4 +78,31 @@ class DocumentSymbolLspSuite extends BaseLspSuite("documentSymbol") {
} yield ()
}

test("scala-script") {
cleanWorkspace()
for {
_ <- initialize(
"""|
|/metals.json
|{
| "a": { }
|}
|/a/src/main/scala/a/Main.sc
|object Outer {
| class Inner
|}
|""".stripMargin
)
_ <- server.didOpen("a/src/main/scala/a/Main.sc")
symbols <- server.documentSymbols("a/src/main/scala/a/Main.sc")
_ = assertNoDiff(
symbols,
"""|
|/*Outer(Module):3*/object Outer {
| /*Outer.Inner(Class):2*/class Inner
|}""".stripMargin,
)
} yield ()
}

}

0 comments on commit f9bd535

Please sign in to comment.