Skip to content

Commit 3e47ac7

Browse files
committed
Address review comments
1 parent 7c1364a commit 3e47ac7

File tree

7 files changed

+21
-30
lines changed

7 files changed

+21
-30
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ class CompletionTest {
99

1010
@Test def completion0: Unit = {
1111
code"class Foo { val xyz: Int = 0; def y: Int = xy$m1 }".withSource
12-
.completion(m1, List(("xyz", CompletionItemKind.Field, "Int")))
12+
.completion(m1, Set(("xyz", CompletionItemKind.Field, "Int")))
1313
}
1414
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ object Code {
5656

5757
ai.next() match {
5858
case emb: CodeMarker =>
59-
positions += Tuple3(emb, line, char)
59+
positions += ((emb, line, char))
6060

6161
case emb: CodeInRange =>
62-
positions += Tuple3(emb.range.start, line, char)
62+
positions += ((emb.range.start, line, char))
6363
scan(emb.text)
6464
stringBuilder.append(emb.text)
65-
positions += Tuple3(emb.range.end, line, char)
65+
positions += ((emb.range.end, line, char))
6666
}
6767

6868
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import PositionContext._
1414
* @param end The end marker.
1515
*/
1616
case class CodeRange(start: CodeMarker, end: CodeMarker) {
17-
private var checked = false
17+
private[this] var checked = false
1818
def check(): PosCtx[Unit] = {
1919
if (!checked) {
2020
assert(start.file == end.file, s"$start and $end where not in the same file")
@@ -29,11 +29,6 @@ case class CodeRange(start: CodeMarker, end: CodeMarker) {
2929
start.file
3030
}
3131

32-
def toTuple: PosCtx[(Int, Int, Int, Int)] = {
33-
check()
34-
(start.line, start.character, end.line, end.character)
35-
}
36-
3732
def withCode(text: String): CodeInRange = CodeInRange(text, this)
3833

3934
def symInfo(name: String, kind: SymbolKind, container: String = null): SymInfo =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class CodeTester(sources: List[SourceWithPositions], actions: List[Action]) {
8181
*
8282
* @see dotty.tools.languageserver.util.actions.CodeCompletion
8383
*/
84-
def completion(marker: CodeMarker, expected: List[(String, CompletionItemKind, String)]): CodeTester =
84+
def completion(marker: CodeMarker, expected: Set[(String, CompletionItemKind, String)]): CodeTester =
8585
doAction(new CodeCompletion(marker, expected))
8686

8787
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import dotty.tools.languageserver.util.embedded.CodeMarker
44
import dotty.tools.languageserver.util.server.TestFile
55

66
class PositionContext(positionMap: Map[CodeMarker, (TestFile, Int, Int)]) {
7-
private var lastKey: CodeMarker = _
8-
private var lastValue: (TestFile, Int, Int) = _
7+
private[this] var lastKey: CodeMarker = _
8+
private[this] var lastValue: (TestFile, Int, Int) = _
99
def positionOf(pos: CodeMarker): (TestFile, Int, Int) = {
1010
if (lastKey eq pos) lastValue
1111
else {

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,24 @@ import org.eclipse.lsp4j.CompletionItemKind
99
import scala.collection.JavaConverters._
1010

1111
/**
12-
* An action requesting for code completion at `marker`, expecting `completions`.
12+
* An action requesting for code completion at `marker`, expecting `expected`.
1313
* This action corresponds to the `textDocument/completion` method of the Language Server Protocol.
1414
*
15-
* @param marker The marker indicating the position where completion should be requested.
16-
* @param completions The expected results from the language server.
15+
* @param marker The marker indicating the position where completion should be requested.
16+
* @param expected The expected results from the language server.
1717
*/
1818
class CodeCompletion(override val marker: CodeMarker,
19-
completions: List[(String, CompletionItemKind, String)]) extends ActionOnMarker {
19+
expected: Set[(String, CompletionItemKind, String)]) extends ActionOnMarker {
2020

2121
override def execute(): Exec[Unit] = {
2222
val result = server.completion(marker.toTextDocumentPositionParams).get()
2323
assert(result.isRight, result)
24-
val cList = result.getRight
25-
assert(!cList.isIncomplete, result)
26-
completions.foreach { completion =>
27-
assert(
28-
cList.getItems.asScala.exists(item =>
29-
completion == (item.getLabel, item.getKind, item.getDetail)
30-
),
31-
"Did not return completion for " + completion + "\n" + cList.getItems.asScala.toList
32-
)
24+
assert(!result.getRight.isIncomplete, s"Completion results were 'incomplete': $result")
25+
val completionResults = result.getRight.getItems.asScala.toSet.map { item =>
26+
(item.getLabel, item.getKind, item.getDetail)
3327
}
3428
}
3529

3630
override def show: PositionContext.PosCtx[String] =
37-
s"CodeCompletion(${marker.show}, $completions)"
31+
s"CodeCompletion(${marker.show}, $expected)"
3832
}

language-server/test/dotty/tools/languageserver/util/embedded/CodeMarker.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ class CodeMarker(val name: String) extends Embedded {
1414
def to(other: CodeMarker): CodeRange = CodeRange(this, other)
1515

1616
/** The file containing this marker. */
17-
def file: PosCtx[TestFile] = implicitly[PositionContext].positionOf(this)._1
17+
def file: PosCtx[TestFile] = posCtx.positionOf(this)._1
1818

1919
/** The line containing this marker. */
20-
def line: PosCtx[Int] = implicitly[PositionContext].positionOf(this)._2
20+
def line: PosCtx[Int] = posCtx.positionOf(this)._2
2121

2222
/** The columng number of this marker. */
23-
def character: PosCtx[Int] = implicitly[PositionContext].positionOf(this)._3
23+
def character: PosCtx[Int] = posCtx.positionOf(this)._3
2424

2525
/** Converts this marker to a position. */
2626
def toPosition: PosCtx[Position] = new Position(line, character)
@@ -46,4 +46,6 @@ class CodeMarker(val name: String) extends Embedded {
4646

4747
def show: PosCtx[String] = s"($name,line=$line,char=$character)"
4848
override def toString: String = s"CodePosition($name)"
49+
50+
private implicit def posCtx(implicit ctx: PositionContext): PositionContext = ctx
4951
}

0 commit comments

Comments
 (0)