Skip to content

Commit c2849d4

Browse files
committed
Adjust tests for fuzzy searched completions
1 parent 446b98f commit c2849d4

File tree

10 files changed

+112
-106
lines changed

10 files changed

+112
-106
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import dotty.tools.dotc.ast.untpd
1616
import dotty.tools.dotc.core.Comments.Comment
1717
import dotty.tools.dotc.core.Constants.Constant
1818
import dotty.tools.dotc.core.Contexts.*
19+
import dotty.tools.dotc.core.Denotations.SingleDenotation
1920
import dotty.tools.dotc.core.Flags
2021
import dotty.tools.dotc.core.Flags.*
2122
import dotty.tools.dotc.core.NameOps.*
@@ -26,14 +27,13 @@ import dotty.tools.dotc.core.Symbols.*
2627
import dotty.tools.dotc.core.Types.*
2728
import dotty.tools.dotc.interactive.Completion
2829
import dotty.tools.dotc.interactive.Completion.Mode
30+
import dotty.tools.dotc.interactive.Interactive
2931
import dotty.tools.dotc.util.SourcePosition
3032
import dotty.tools.dotc.util.SrcPos
3133
import dotty.tools.pc.AutoImports.AutoImportsGenerator
32-
import dotty.tools.pc.completions.OverrideCompletions.OverrideExtractor
3334
import dotty.tools.pc.buildinfo.BuildInfo
35+
import dotty.tools.pc.completions.OverrideCompletions.OverrideExtractor
3436
import dotty.tools.pc.utils.MtagsEnrichments.*
35-
import dotty.tools.dotc.core.Denotations.SingleDenotation
36-
3737

3838
class Completions(
3939
text: String,
@@ -103,7 +103,8 @@ class Completions(
103103
end includeSymbol
104104

105105
val fuzzyMatcher: Name => Boolean = name =>
106-
Fuzzy.matchesSubCharacters(completionPos.query, name.toString)
106+
if completionMode.is(Mode.Member) then CompletionFuzzy.matchesSubCharacters(completionPos.query, name.toString)
107+
else CompletionFuzzy.matches(completionPos.query, name.toString)
107108

108109
def enrichedCompilerCompletions(qualType: Type): (List[CompletionValue], SymbolSearch.Result) =
109110
val compilerCompletions = Completion
@@ -119,8 +120,9 @@ class Completions(
119120
val (all, result) =
120121
if exclusive then (advanced, SymbolSearch.Result.COMPLETE)
121122
else
122-
val keywords = KeywordsCompletions.contribute(adjustedPath, completionPos, comments)
123+
val keywords = KeywordsCompletions.contribute(path, completionPos, comments)
123124
val allAdvanced = advanced ++ keywords
125+
124126
path match
125127
// should not show completions for toplevel
126128
case Nil | (_: PackageDef) :: _ if !completionPos.originalCursorPosition.source.file.ext.isScalaScript =>
@@ -423,7 +425,7 @@ class Completions(
423425

424426
// class Fo@@
425427
case (td: TypeDef) :: _
426-
if Fuzzy.matches(
428+
if CompletionFuzzy.matches(
427429
td.symbol.name.decoded.replace(Cursor.value, "").nn,
428430
filename
429431
) =>

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
@@ -691,28 +691,26 @@ class CompletionKeywordSuite extends BaseCompletionSuite:
691691

692692
@Test def `derives-with-extends` =
693693
check(
694-
"""
695-
|package foo
696-
|
697-
|trait Bar {}
698-
|trait Baz {}
699-
|
700-
|class Foo(x: Int) extends Bar with Baz der@@
701-
""".stripMargin,
694+
"""|package foo
695+
|
696+
|trait Bar {}
697+
|trait Baz {}
698+
|
699+
|class Foo(x: Int) extends Bar with Baz der@@
700+
|""".stripMargin,
702701
"""|derives
703702
|""".stripMargin
704703
)
705704

706705
@Test def `derives-with-constructor-extends` =
707706
check(
708-
"""
709-
|package foo
710-
|
711-
|trait Bar {}
712-
|class Baz(b: Int) {}
713-
|
714-
|class Foo(x: Int) extends Bar with Baz(1) @@
715-
""".stripMargin,
707+
"""|package foo
708+
|
709+
|trait Bar {}
710+
|class Baz(b: Int) {}
711+
|
712+
|class Foo(x: Int) extends Bar with Baz(1) der@@
713+
|""".stripMargin,
716714
"""|derives
717715
|""".stripMargin
718716
)
@@ -730,63 +728,3 @@ class CompletionKeywordSuite extends BaseCompletionSuite:
730728
""".stripMargin,
731729
""
732730
)
733-
734-
@Test def `only-keywords` =
735-
check(
736-
"""
737-
|package foo
738-
|
739-
|object Main {
740-
| class Baz(x: Int) @@
741-
|}
742-
""".stripMargin,
743-
""
744-
)
745-
746-
@Test def `only-keywords-1` =
747-
check(
748-
"""
749-
|package foo
750-
|
751-
|object Main {
752-
| class Baz(x: Int)
753-
| p@@
754-
|}
755-
""".stripMargin,
756-
""
757-
)
758-
759-
@Test def `only-keywords-2` =
760-
check(
761-
"""
762-
|package foo
763-
|
764-
|class Baz(x: Int) @@
765-
""".stripMargin,
766-
""
767-
)
768-
769-
@Test def `def-after-extension` =
770-
check(
771-
"""
772-
|object Main {
773-
| extension (x: Int) @@
774-
|}
775-
""".stripMargin,
776-
"""|derives
777-
|private
778-
|""".stripMargin
779-
)
780-
781-
@Test def `def-after-extension-newline` =
782-
check(
783-
"""
784-
|object Main {
785-
| extension (x: Int)
786-
| @@
787-
|}
788-
""".stripMargin,
789-
"""|derives
790-
|private
791-
|""".stripMargin
792-
)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,12 +925,13 @@ class CompletionOverrideSuite extends BaseCompletionSuite:
925925
| def@@
926926
|}
927927
|""".stripMargin,
928+
928929
"""|def hello1: Int
929930
|override def equals(x$0: Any): Boolean
930931
|override def hashCode(): Int
931932
|""".stripMargin,
932933
includeDetail = false,
933-
topLines = Some(3)
934+
topLines = Some(5)
934935
)
935936

936937
@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` =

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class CompletionSnippetSuite extends BaseCompletionSuite:
1515
|}
1616
|""".stripMargin,
1717
"""|apply($0)
18+
|unapplySeq($0)
1819
|""".stripMargin
1920
)
2021

@@ -429,7 +430,8 @@ class CompletionSnippetSuite extends BaseCompletionSuite:
429430
| extension (s: String)
430431
| def bar = 0
431432
| val bar = "abc".bar
432-
""".stripMargin
433+
""".stripMargin,
434+
filter = _.contains("bar: Int")
433435
)
434436

435437
// https://github.com/scalameta/metals/issues/4004
@@ -446,5 +448,6 @@ class CompletionSnippetSuite extends BaseCompletionSuite:
446448
| extension (s: String)
447449
| def bar() = 0
448450
| val bar = "abc".bar()
449-
""".stripMargin
451+
""".stripMargin,
452+
filter = _.contains("bar: Int")
450453
)

0 commit comments

Comments
 (0)