Skip to content

Commit f702cab

Browse files
committed
Adjust tests for fuzzy searched completions
1 parent 6e02dc3 commit f702cab

File tree

11 files changed

+206
-128
lines changed

11 files changed

+206
-128
lines changed

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ object Completion:
131131
def completionPrefix(path: List[untpd.Tree], pos: SourcePosition)(using Context): String =
132132
def fallback: Int =
133133
var i = pos.point - 1
134-
while i >= 0 && Chars.isIdentifierPart(pos.source.content()(i)) do i -= 1
134+
while i >= 0 && Character.isUnicodeIdentifierPart(pos.source.content()(i)) do i -= 1
135135
i + 1
136136

137137
path match

presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
package dotty.tools.pc
22
package completions
33

4-
import java.nio.file.Path
5-
import java.nio.file.Paths
6-
7-
import scala.collection.mutable
8-
import scala.meta.internal.metals.Fuzzy
9-
import scala.meta.internal.metals.ReportContext
10-
import scala.meta.internal.mtags.CoursierComplete
11-
import scala.meta.internal.pc.{IdentifierComparator, MemberOrdering}
12-
import scala.meta.pc.*
13-
4+
import dotty.tools.dotc.ast.NavigateAST
145
import dotty.tools.dotc.ast.tpd.*
156
import dotty.tools.dotc.ast.untpd
16-
import dotty.tools.dotc.ast.NavigateAST
177
import dotty.tools.dotc.core.Comments.Comment
188
import dotty.tools.dotc.core.Constants.Constant
199
import dotty.tools.dotc.core.Contexts.*
10+
import dotty.tools.dotc.core.Denotations.SingleDenotation
2011
import dotty.tools.dotc.core.Flags
2112
import dotty.tools.dotc.core.Flags.*
2213
import dotty.tools.dotc.core.NameOps.*
@@ -27,14 +18,23 @@ import dotty.tools.dotc.core.Symbols.*
2718
import dotty.tools.dotc.core.Types.*
2819
import dotty.tools.dotc.interactive.Completion
2920
import dotty.tools.dotc.interactive.Completion.Mode
21+
import dotty.tools.dotc.interactive.Interactive
3022
import dotty.tools.dotc.util.SourcePosition
3123
import dotty.tools.dotc.util.SrcPos
3224
import dotty.tools.pc.AutoImports.AutoImportsGenerator
33-
import dotty.tools.pc.completions.OverrideCompletions.OverrideExtractor
3425
import dotty.tools.pc.buildinfo.BuildInfo
26+
import dotty.tools.pc.completions.OverrideCompletions.OverrideExtractor
3527
import dotty.tools.pc.utils.MtagsEnrichments.*
36-
import dotty.tools.dotc.core.Denotations.SingleDenotation
37-
import dotty.tools.dotc.interactive.Interactive
28+
29+
import java.nio.file.Path
30+
import java.nio.file.Paths
31+
import scala.collection.mutable
32+
import scala.meta.internal.metals.ReportContext
33+
import scala.meta.internal.mtags.CoursierComplete
34+
import scala.meta.internal.pc.CompletionFuzzy
35+
import scala.meta.internal.pc.IdentifierComparator
36+
import scala.meta.internal.pc.MemberOrdering
37+
import scala.meta.pc.*
3838

3939
class Completions(
4040
text: String,
@@ -110,10 +110,11 @@ class Completions(
110110
val (all, result) =
111111
if exclusive then (advanced, SymbolSearch.Result.COMPLETE)
112112
else
113-
val keywords = KeywordsCompletions.contribute(adjustedPath, completionPos, comments)
113+
val keywords = KeywordsCompletions.contribute(path, completionPos, comments)
114114
val allAdvanced = advanced ++ keywords
115115
val fuzzyMatcher: Name => Boolean = name =>
116-
Fuzzy.matchesSubCharacters(completionPos.query, name.toString)
116+
if completionMode.is(Mode.Member) then CompletionFuzzy.matchesSubCharacters(completionPos.query, name.toString)
117+
else CompletionFuzzy.matches(completionPos.query, name.toString)
117118

118119
path match
119120
// should not show completions for toplevel
@@ -387,7 +388,7 @@ class Completions(
387388

388389
// class Fo@@
389390
case (td: TypeDef) :: _
390-
if Fuzzy.matches(
391+
if CompletionFuzzy.matches(
391392
td.symbol.name.decoded.replace(Cursor.value, "").nn,
392393
filename
393394
) =>
@@ -883,14 +884,13 @@ class Completions(
883884
val byLocalSymbol = compareLocalSymbols(s1, s2)
884885
if byLocalSymbol != 0 then byLocalSymbol
885886
else
886-
val byRelevance = compareByRelevance(o1, o2)
887-
if byRelevance != 0 then byRelevance
887+
val f1 = fuzzyScore(sym1)
888+
val f2 = fuzzyScore(sym2)
889+
val byFuzzy = Integer.compare(f1, f2)
890+
if byFuzzy != 0 then byFuzzy
888891
else
889-
val byFuzzy = Integer.compare(
890-
fuzzyScore(sym1),
891-
fuzzyScore(sym2)
892-
)
893-
if byFuzzy != 0 then byFuzzy
892+
val byRelevance = compareByRelevance(o1, o2)
893+
if byRelevance != 0 then byRelevance
894894
else
895895
val byIdentifier = IdentifierComparator.compare(
896896
s1.name.show,

presentation-compiler/src/main/dotty/tools/pc/completions/KeywordsCompletions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import scala.meta.internal.pc.Keyword
55

66
import dotty.tools.dotc.ast.NavigateAST
77
import dotty.tools.dotc.ast.Positioned
8-
import dotty.tools.dotc.ast.untpd.*
8+
import dotty.tools.dotc.ast.tpd.*
99
import dotty.tools.dotc.ast.untpd
1010
import dotty.tools.dotc.ast.untpd.UntypedTreeTraverser
1111
import dotty.tools.dotc.core.Comments

presentation-compiler/test/dotty/tools/pc/base/BaseCompletionSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ abstract class BaseCompletionSuite extends BasePCSuite:
123123

124124
if (assertSingleItem && items.length != 1) then
125125
fail(
126-
s"expected single completion item, obtained ${items.length} items.\n${items}"
126+
s"expected single completion item, obtained ${items.length} items.\n${items.map(_.getLabel.nn + "\n")}"
127127
)
128128

129129
if (items.size <= itemIndex) then

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionDocSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ class CompletionDocSuite extends BaseCompletionSuite:
156156
|Found documentation for scala/collection/Iterator.
157157
|Iterator scala.collection
158158
|""".stripMargin,
159-
160-
includeDocs = true
159+
includeDocs = true,
160+
topLines = Some(1)
161161
)
162162

163163
@Test def `scala5` =

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionExtensionSuite.scala

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,24 @@ class CompletionExtensionSuite extends BaseCompletionSuite:
1717
|def main = 100.inc@@
1818
|""".stripMargin,
1919
"""|incr: Int (extension)
20+
|asInstanceOf[X0]: X0
21+
|isInstanceOf[X0]: Boolean
2022
|""".stripMargin
2123
)
2224

2325
@Test def `simple-old-syntax` =
2426
check(
25-
"""|package example
27+
"""package example
2628
|
2729
|object Test:
2830
| implicit class TestOps(a: Int):
2931
| def testOps(b: Int): String = ???
3032
|
3133
|def main = 100.test@@
3234
|""".stripMargin,
33-
"""|testOps(b: Int): String (implicit)
34-
|""".stripMargin
35+
"""testOps(b: Int): String (implicit)
36+
|""".stripMargin,
37+
topLines = Some(1)
3538
)
3639

3740
@Test def `simple2` =
@@ -93,7 +96,10 @@ class CompletionExtensionSuite extends BaseCompletionSuite:
9396
|
9497
|def main = "foo".iden@@
9598
|""".stripMargin,
96-
"""|identity: String (implicit)
99+
"""|identity: String (implicit)
100+
|indent(x$0: Int): String
101+
|stripIndent(): String
102+
|isDefinedAt(idx: Int): Boolean
97103
|""".stripMargin // identity2 won't be available
98104
)
99105

@@ -152,7 +158,8 @@ class CompletionExtensionSuite extends BaseCompletionSuite:
152158
| def incr: Int = num + 1
153159
|
154160
|def main = 100.incr
155-
|""".stripMargin
161+
|""".stripMargin,
162+
assertSingleItem = false
156163
)
157164

158165
@Test def `simple-edit-old` =
@@ -174,7 +181,8 @@ class CompletionExtensionSuite extends BaseCompletionSuite:
174181
| def incr: Int = num + 1
175182
|
176183
|def main = 100.incr
177-
|""".stripMargin
184+
|""".stripMargin,
185+
assertSingleItem = false
178186
)
179187

180188
@Test def `simple-edit-suffix` =
@@ -262,6 +270,8 @@ class CompletionExtensionSuite extends BaseCompletionSuite:
262270
| def main = 100.inc@@
263271
|""".stripMargin,
264272
"""|incr: Int (extension)
273+
|asInstanceOf[X0]: X0
274+
|isInstanceOf[X0]: Boolean
265275
|""".stripMargin
266276
)
267277

@@ -276,6 +286,8 @@ class CompletionExtensionSuite extends BaseCompletionSuite:
276286
| def main = 100.inc@@
277287
|""".stripMargin,
278288
"""|incr: Int (implicit)
289+
|asInstanceOf[X0]: X0
290+
|isInstanceOf[X0]: Boolean
279291
|""".stripMargin
280292
)
281293

@@ -290,6 +302,8 @@ class CompletionExtensionSuite extends BaseCompletionSuite:
290302
| def main = 100.inc@@
291303
|""".stripMargin,
292304
"""|incr: Int (extension)
305+
|asInstanceOf[X0]: X0
306+
|isInstanceOf[X0]: Boolean
293307
|""".stripMargin
294308
)
295309

@@ -304,6 +318,8 @@ class CompletionExtensionSuite extends BaseCompletionSuite:
304318
| def main = 100.inc@@
305319
|""".stripMargin,
306320
"""|incr: Int (implicit)
321+
|asInstanceOf[X0]: X0
322+
|isInstanceOf[X0]: Boolean
307323
|""".stripMargin
308324
)
309325

@@ -391,7 +407,8 @@ class CompletionExtensionSuite extends BaseCompletionSuite:
391407
|testVal: Int (implicit)
392408
|testVar: Int (implicit)
393409
|testOps(b: Int): String (implicit)
394-
|""".stripMargin
410+
|""".stripMargin,
411+
topLines = Some(4)
395412
)
396413

397414
@Test def `implicit-val-edit` =
@@ -413,5 +430,6 @@ class CompletionExtensionSuite extends BaseCompletionSuite:
413430
| val testVal: Int = 42
414431
|
415432
|def main = 100.testVal
416-
|""".stripMargin
433+
|""".stripMargin,
434+
assertSingleItem = false
417435
)

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionKeywordSuite.scala

Lines changed: 14 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -698,28 +698,26 @@ class CompletionKeywordSuite extends BaseCompletionSuite:
698698

699699
@Test def `derives-with-extends` =
700700
check(
701-
"""
702-
|package foo
703-
|
704-
|trait Bar {}
705-
|trait Baz {}
706-
|
707-
|class Foo(x: Int) extends Bar with Baz der@@
708-
""".stripMargin,
701+
"""|package foo
702+
|
703+
|trait Bar {}
704+
|trait Baz {}
705+
|
706+
|class Foo(x: Int) extends Bar with Baz der@@
707+
|""".stripMargin,
709708
"""|derives
710709
|""".stripMargin
711710
)
712711

713712
@Test def `derives-with-constructor-extends` =
714713
check(
715-
"""
716-
|package foo
717-
|
718-
|trait Bar {}
719-
|class Baz(b: Int) {}
720-
|
721-
|class Foo(x: Int) extends Bar with Baz(1) @@
722-
""".stripMargin,
714+
"""|package foo
715+
|
716+
|trait Bar {}
717+
|class Baz(b: Int) {}
718+
|
719+
|class Foo(x: Int) extends Bar with Baz(1) der@@
720+
|""".stripMargin,
723721
"""|derives
724722
|""".stripMargin
725723
)
@@ -737,63 +735,3 @@ class CompletionKeywordSuite extends BaseCompletionSuite:
737735
""".stripMargin,
738736
""
739737
)
740-
741-
@Test def `only-keywords` =
742-
check(
743-
"""
744-
|package foo
745-
|
746-
|object Main {
747-
| class Baz(x: Int) @@
748-
|}
749-
""".stripMargin,
750-
""
751-
)
752-
753-
@Test def `only-keywords-1` =
754-
check(
755-
"""
756-
|package foo
757-
|
758-
|object Main {
759-
| class Baz(x: Int)
760-
| p@@
761-
|}
762-
""".stripMargin,
763-
""
764-
)
765-
766-
@Test def `only-keywords-2` =
767-
check(
768-
"""
769-
|package foo
770-
|
771-
|class Baz(x: Int) @@
772-
""".stripMargin,
773-
""
774-
)
775-
776-
@Test def `def-after-extension` =
777-
check(
778-
"""
779-
|object Main {
780-
| extension (x: Int) @@
781-
|}
782-
""".stripMargin,
783-
"""|derives
784-
|private
785-
|""".stripMargin
786-
)
787-
788-
@Test def `def-after-extension-newline` =
789-
check(
790-
"""
791-
|object Main {
792-
| extension (x: Int)
793-
| @@
794-
|}
795-
""".stripMargin,
796-
"""|derives
797-
|private
798-
|""".stripMargin
799-
)

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionOverrideSuite.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,12 +925,15 @@ class CompletionOverrideSuite extends BaseCompletionSuite:
925925
| def@@
926926
|}
927927
|""".stripMargin,
928+
928929
"""|def hello1: Int
929-
|override val hello2: Int
930930
|override def equals(x$0: Any): Boolean
931+
|override def hashCode(): Int
932+
|override def toString(): String
933+
|override val hello2: Int
931934
|""".stripMargin,
932935
includeDetail = false,
933-
topLines = Some(3)
936+
topLines = Some(5)
934937
)
935938

936939
@Test def `path-dependent` =

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSnippetNegSuite.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ class CompletionSnippetNegSuite extends BaseCompletionSuite:
1616

1717
@Test def `member` =
1818
checkSnippet(
19-
"""
20-
|object Main {
21-
| List.appl@@
22-
|}
23-
|""".stripMargin,
24-
"apply"
19+
"""|object Main {
20+
| List.appl@@
21+
|}
22+
|""".stripMargin,
23+
"""|apply
24+
|unapplySeq""".stripMargin
2525
)
2626

2727
@Test def `scope` =

0 commit comments

Comments
 (0)