Skip to content

Commit

Permalink
bugfix: match completions for type aliases scala 3
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Oct 5, 2023
1 parent e3b108a commit 2a8d00e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ object CaseKeywordCompletion:
* @param selector `selector` of `selector match { cases }` or `EmptyTree` when
* not in a match expression (for example `List(1).foreach { case@@ }`.
* @param completionPos the position of the completion
* @param typedtree typed tree of the file, used for generating auto imports
* @param indexedContext
* @param config
* @param parent the parent tree node of the pattern match, for example `Apply(_, _)` when in
Expand Down Expand Up @@ -88,7 +87,7 @@ object CaseKeywordCompletion:
new Parents(NoType, definitions)
case sel => new Parents(sel.tpe, definitions)

val selectorSym = parents.selector.typeSymbol
val selectorSym = parents.selector.metalsDealias.typeSymbol

// Special handle case when selector is a tuple or `FunctionN`.
if definitions.isTupleClass(selectorSym) || definitions.isFunctionClass(
Expand Down Expand Up @@ -240,8 +239,8 @@ object CaseKeywordCompletion:
clientSupportsSnippets,
)
val tpe = selector.tpe.widen.bounds.hi match
case tr @ TypeRef(_, _) => tr.underlying
case t => t
case tr @ TypeRef(_, _) => tr.underlying.metalsDealias
case t => t.metalsDealias

val sortedSubclasses =
val subclasses =
Expand Down
48 changes: 48 additions & 0 deletions tests/cross/src/test/scala/tests/pc/CompletionMatchSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -734,4 +734,52 @@ class CompletionMatchSuite extends BaseCompletionSuite {
filter = _.contains("exhaustive"),
)

checkEdit(
"type-alias".tag(IgnoreScala2),
s"""|object O {
| type Id[A] = A
|
| enum Animal:
| case Cat, Dog
|
| val animal: Id[Animal] = ???
|
| animal ma@@
|}
|""".stripMargin,
s"""object O {
| type Id[A] = A
|
| enum Animal:
| case Cat, Dog
|
| val animal: Id[Animal] = ???
|
| animal match
|\tcase Animal.Cat => $$0
|\tcase Animal.Dog =>
|
|}
|""".stripMargin,
filter = _.contains("exhaustive"),
)

check(
"type-alias2".tag(IgnoreScala2),
s"""|object O {
| type Id[A] = A
|
| enum Animal:
| case Cat, Dog
|
| val animal: Id[Animal] = ???
|
| animal match {
| \tcase Animal.C@@
| }
|}
|""".stripMargin,
"Cat: Animal",
)

}

0 comments on commit 2a8d00e

Please sign in to comment.