Skip to content

Commit cc0cb29

Browse files
committed
Support multiple results in CodeDefinition
1 parent 2e5211e commit cc0cb29

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@ import dotty.tools.languageserver.util.Code._
77
class DefinitionTest {
88

99
@Test def classDefinitionNotFound0: Unit =
10-
code"class Foo { new ${m1}Bar$m2 }".withSource.definition(m1 to m2, None)
10+
code"class Foo { new ${m1}Bar$m2 }".withSource.definition(m1 to m2, Nil)
1111

1212
@Test def classDefinition0: Unit = {
1313
withSources(
1414
code"class ${m1}Foo$m2 { new Foo }",
1515
code"class Bar { val foo: ${m3}Foo$m4 = new ${m5}Foo$m6 }"
16-
) .definition(m1 to m2, Some(m1 to m2))
17-
.definition(m3 to m4, Some(m1 to m2))
18-
.definition(m5 to m6, Some(m1 to m2))
16+
) .definition(m1 to m2, List(m1 to m2))
17+
.definition(m3 to m4, List(m1 to m2))
18+
.definition(m5 to m6, List(m1 to m2))
1919
}
2020

2121
@Test def valDefinition0: Unit = {
2222
withSources(
2323
code"class Foo { val ${m1}x$m2 = 0; ${m3}x$m4 }",
2424
code"class Bar { val foo = new Foo; foo.${m5}x$m6 }"
25-
) .definition(m1 to m2, Some(m1 to m2))
26-
.definition(m3 to m4, Some(m1 to m2))
27-
.definition(m5 to m6, Some(m1 to m2))
25+
) .definition(m1 to m2, List(m1 to m2))
26+
.definition(m3 to m4, List(m1 to m2))
27+
.definition(m5 to m6, List(m1 to m2))
2828
}
2929

3030
@Test def defDefinition0: Unit = {
3131
withSources(
3232
code"class Foo { def ${m1}x$m2 = 0; ${m3}x$m4 }",
3333
code"class Bar { val foo = new Foo; foo.${m5}x$m6 }"
34-
) .definition(m1 to m2, Some(m1 to m2))
35-
.definition(m3 to m4, Some(m1 to m2))
36-
.definition(m5 to m6, Some(m1 to m2))
34+
) .definition(m1 to m2, List(m1 to m2))
35+
.definition(m3 to m4, List(m1 to m2))
36+
.definition(m5 to m6, List(m1 to m2))
3737
}
3838

3939
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class CodeTester(sources: List[SourceWithPositions], actions: List[Action]) {
1818
def hover(range: CodeRange, expected: String): CodeTester =
1919
doAction(new CodeHover(range, expected))
2020

21-
def definition(range: CodeRange, refOpt: Option[CodeRange]): CodeTester =
21+
def definition(range: CodeRange, refOpt: Seq[CodeRange]): CodeTester =
2222
doAction(new CodeDefinition(range, refOpt))
2323

2424
def highlight(range: CodeRange, highs: (CodeRange, String)*): CodeTester =

language-server/test/dotty/tools/languageserver/util/actions/CodeDefinition.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ package dotty.tools.languageserver.util.actions
33
import dotty.tools.languageserver.util._
44
import dotty.tools.languageserver.util.embedded.CodeMarker
55

6-
class CodeDefinition(val range: CodeRange, refOpt: Option[CodeRange]) extends ActionOnRange {
6+
class CodeDefinition(val range: CodeRange, expected: Seq[CodeRange]) extends ActionOnRange {
77

88
override def onMarker(marker: CodeMarker): Exec[Unit] = {
9-
val res = server.definition(fix(marker.toTextDocumentPositionParams)).get()
10-
assert(res.size() == refOpt.size, res)
11-
refOpt.foreach(ref => assert(res.get(0) == ref.toLocation, res))
9+
val results = server.definition(fix(marker.toTextDocumentPositionParams)).get()
10+
assert(results.size == expected.size, s"Expected ${expected.size} matches, found ${results.size}")
11+
(0 until results.size).foreach { i =>
12+
assert(results.get(i) == expected(i).toLocation, s"Expected ${expected(i).toLocation}, found ${results.get(i)}.")
13+
}
1214
}
1315

1416
override def show: PositionContext.PosCtx[String] =
15-
s"CodeDefinition(${range.show}, ${refOpt.map(_.show)})"
17+
s"CodeDefinition(${range.show}, ${expected.map(_.show)})"
1618
}

0 commit comments

Comments
 (0)