From 0dd2cd8e421c2aa76064b84a6a40f30f86bbe7b5 Mon Sep 17 00:00:00 2001 From: Jakub Ciesluk <323892@uwr.edu.pl> Date: Tue, 20 Jun 2023 12:44:16 +0200 Subject: [PATCH] fix: Remove pattern only completions for tuple type It was hard to detect we are in `yield @@` or `case (@@)` and this completion was not really usefull, so it was best to remove it --- .../pc/completions/MatchCaseCompletions.scala | 24 ++++++++++-------- .../pc/completions/MatchCaseCompletions.scala | 25 +++++++------------ .../scala/tests/pc/CompletionCaseSuite.scala | 12 +++++++++ 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/mtags/src/main/scala-2/scala/meta/internal/pc/completions/MatchCaseCompletions.scala b/mtags/src/main/scala-2/scala/meta/internal/pc/completions/MatchCaseCompletions.scala index 7307d6b5d65..29705fc9f5b 100644 --- a/mtags/src/main/scala-2/scala/meta/internal/pc/completions/MatchCaseCompletions.scala +++ b/mtags/src/main/scala-2/scala/meta/internal/pc/completions/MatchCaseCompletions.scala @@ -84,18 +84,20 @@ trait MatchCaseCompletions { this: MetalsGlobal => // Special handle case when selector is a tuple or `FunctionN`. if (definitions.isTupleType(parents.selector)) { - List( - new TextEditMember( - "case () =>", - new l.TextEdit( - editRange, - if (clientSupportsSnippets) "case ($0) =>" else "case () =>" - ), - selectorSym, - label = Some(s"case ${parents.selector} =>"), - command = metalsConfig.parameterHintsCommand().asScala + if (patternOnly.isEmpty) + List( + new TextEditMember( + "case () =>", + new l.TextEdit( + editRange, + if (clientSupportsSnippets) "case ($0) =>" else "case () =>" + ), + selectorSym, + label = Some(s"case ${parents.selector} =>"), + command = metalsConfig.parameterHintsCommand().asScala + ) ) - ) + else Nil } else { val completionGenerator = new CompletionValueGenerator( editRange, diff --git a/mtags/src/main/scala-3/scala/meta/internal/pc/completions/MatchCaseCompletions.scala b/mtags/src/main/scala-3/scala/meta/internal/pc/completions/MatchCaseCompletions.scala index 1b62002990f..d3542b72fc5 100644 --- a/mtags/src/main/scala-3/scala/meta/internal/pc/completions/MatchCaseCompletions.scala +++ b/mtags/src/main/scala-3/scala/meta/internal/pc/completions/MatchCaseCompletions.scala @@ -86,8 +86,7 @@ object CaseKeywordCompletion: case _ => new Parents(NoType, definitions) case sel => - val selectorTpe = sel.tpe - new Parents(selectorTpe, definitions) + new Parents(sel.tpe, definitions) val selectorSym = parents.selector.widen.metalsDealias.typeSymbol @@ -96,24 +95,19 @@ object CaseKeywordCompletion: selectorSym ) then - val selectorTpe = parents.selector.show - val tpeLabel = - if !selectorTpe.contains("x$1") then selectorTpe - else selector.symbol.info.show - val label = - if patternOnly.isEmpty then s"case ${tpeLabel} =>" - else tpeLabel - if completionGenerator.fuzzyMatches(label) then + if patternOnly.isEmpty then + val selectorTpe = parents.selector.show + val tpeLabel = + if !selectorTpe.contains("x$1") then selectorTpe + else selector.symbol.info.show + val label = s"case ${tpeLabel} =>" List( CompletionValue.CaseKeyword( selectorSym, label, Some( - if patternOnly.isEmpty then - if config.isCompletionSnippetsEnabled() then "case ($0) =>" - else "case () =>" - else if config.isCompletionSnippetsEnabled() then "($0)" - else "()" + if config.isCompletionSnippetsEnabled() then "case ($0) =>" + else "case () =>" ), Nil, range = Some(completionPos.toEditRange), @@ -121,7 +115,6 @@ object CaseKeywordCompletion: ) ) else Nil - end if else val result = ListBuffer.empty[SymbolImport] val isVisited = mutable.Set.empty[Symbol] diff --git a/tests/cross/src/test/scala/tests/pc/CompletionCaseSuite.scala b/tests/cross/src/test/scala/tests/pc/CompletionCaseSuite.scala index 31a75fe27e2..590da997300 100644 --- a/tests/cross/src/test/scala/tests/pc/CompletionCaseSuite.scala +++ b/tests/cross/src/test/scala/tests/pc/CompletionCaseSuite.scala @@ -753,4 +753,16 @@ class CompletionCaseSuite extends BaseCompletionSuite { "", ) + check( + "lambda-case-tuple", + """|object A { + | val a = List((1,2)).foreach { + | case (a,b) => println(a) + | case@@ + | } + |} + |""".stripMargin, + "case (Int, Int) => scala", + ) + }