Skip to content

Commit 17f1803

Browse files
authored
pc: completions - do not add [] for ... derives TC@@ (#23811)
Currently it incorectly adds completion members with square brackets. Exmaple: ```scala class X derives CanEqua@@ // returns `CanEqual[@@]` and `CanEqual` // should return only `CanEqual` ```
1 parent a431d3a commit 17f1803

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,15 @@ class Completions(
7474
case tpe :: (appl: AppliedTypeTree) :: _ if appl.tpt == tpe => false
7575
case sel :: (funSel @ Select(fun, name)) :: (appl: GenericApply) :: _
7676
if appl.fun == funSel && sel == fun => false
77-
case _ => true)
77+
case _ => true) &&
78+
(adjustedPath match
79+
/* In case of `class X derives TC@@` we shouldn't add `[]`
80+
*/
81+
case Ident(_) :: (templ: untpd.DerivingTemplate) :: _ =>
82+
val pos = completionPos.toSourcePosition
83+
!templ.derived.exists(_.sourcePos.contains(pos))
84+
case _ => true
85+
)
7886

7987
private lazy val isNew: Boolean = Completion.isInNewContext(adjustedPath)
8088

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,3 +2285,11 @@ class CompletionSuite extends BaseCompletionSuite:
22852285
|""".stripMargin,
22862286
"asTerm: Term"
22872287
)
2288+
2289+
@Test def `derives-no-square-brackets` =
2290+
check(
2291+
"""
2292+
|case class Miau(y: Int) derives Ordering, CanEqu@@
2293+
|""".stripMargin,
2294+
"CanEqual scala"
2295+
)

0 commit comments

Comments
 (0)