Skip to content

Commit 48acd71

Browse files
authored
fix: don't suggest completions for param names in definition (#6620)
1 parent d03fa3e commit 48acd71

File tree

4 files changed

+42
-78
lines changed

4 files changed

+42
-78
lines changed

mtags/src/main/scala-3/scala/meta/internal/pc/completions/Completions.scala

+3
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ class Completions(
527527
case Literal(Constant(null)) :: tl =>
528528
advancedCompletions(tl, pos, completionPos)
529529

530+
// def foo(a@@)
531+
case ParamDefinitionCompletions(allowKeywords) =>
532+
(ParamDefinitionCompletions.contribute(allowKeywords, completionPos), true)
530533
case _ =>
531534
val args = NamedArgCompletions.contribute(
532535
pos,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package scala.meta.internal.pc.completions
2+
3+
import dotty.tools.dotc.ast.tpd.*
4+
import dotty.tools.dotc.core.Contexts.Context
5+
6+
object ParamDefinitionCompletions:
7+
private val possibleKeywords = List("using", "implicit")
8+
private def completion(keyword: String) = CompletionValue.keyword(keyword, keyword ++ " ")
9+
10+
def unapply(path: List[Tree])(using Context): Option[Boolean] =
11+
path match
12+
case (vd: ValDef) :: (d : DefDef) :: _ =>
13+
d.paramss.lastOption.map(_.indexWhere(_.span.contains(vd.span))).filter(_ >= 0)
14+
match
15+
case Some(ind) if ind == 0 => Some(true)
16+
case Some(_) => Some(false)
17+
case _ => None
18+
case _ => None
19+
20+
def contribute(allowKeywords: Boolean, pos: CompletionPos): List[CompletionValue] =
21+
if allowKeywords
22+
then possibleKeywords.filter(_.startsWith(pos.query)).map(completion)
23+
else Nil

tests/cross/src/test/scala/tests/pc/CompletionKeywordSuite.scala

+3-78
Original file line numberDiff line numberDiff line change
@@ -574,92 +574,17 @@ class CompletionKeywordSuite extends BaseCompletionSuite {
574574
| def hello(u@@)
575575
|}""".stripMargin,
576576
"""|using (commit: '')
577-
|unsafeExceptions scala (commit: '')
578-
|unchecked scala (commit: '')
579-
|unsafeNulls - scala.runtime.stdLibPatches.language (commit: '')
580-
|unshared(): unshared (commit: '')""".stripMargin,
577+
|""".stripMargin,
581578
includeCommitCharacter = true,
582-
compat = Map(
583-
"2" -> "",
584-
"3.3.0" -> """|using (commit: '')
585-
|unsafeExceptions scala (commit: '')
586-
|unchecked scala (commit: '')
587-
|unsafe - scala.caps (commit: '')
588-
|unsafeNulls - scala.runtime.stdLibPatches.language (commit: '')
589-
|""".stripMargin,
590-
"3.3.1" -> """|using (commit: '')
591-
|unsafeExceptions scala (commit: '')
592-
|unchecked scala (commit: '')
593-
|unsafe - scala.caps (commit: '')
594-
|unsafeNulls - scala.runtime.stdLibPatches.language (commit: '')
595-
|""".stripMargin,
596-
"3.3.3" -> """|using (commit: '')
597-
|unsafeExceptions scala (commit: '')
598-
|unchecked scala (commit: '')
599-
|unsafe - caps (commit: '')
600-
|unsafeNulls - scala.runtime.stdLibPatches.language (commit: '')
601-
|""".stripMargin,
602-
"3.4" -> """|using (commit: '')
603-
|unsafeExceptions scala (commit: '')
604-
|unchecked scala (commit: '')
605-
|unsafe - scala.caps (commit: '')
606-
|unsafeNulls - scala.runtime.stdLibPatches.language (commit: '')
607-
|""".stripMargin,
608-
">=3.4.1-RC1-bin-20240201-hash-NIGHTLY" ->
609-
"""|using (commit: '')
610-
|unsafe - scala.caps (commit: '')
611-
|unsafeNulls - scala.runtime.stdLibPatches.language (commit: '')
612-
|unused - scala.annotation (commit: '')
613-
|unshared - scala.annotation.internal (commit: '')
614-
|""".stripMargin,
615-
">=3.4.2-RC1-bin-20240301-hash-NIGHTLY" -> "using (commit: '')"
616-
),
617-
topLines = Some(5)
579+
compat = Map("2" -> "")
618580
)
619581

620582
check(
621583
"not-using",
622584
"""|object A{
623585
| def hello(a: String, u@@)
624586
|}""".stripMargin,
625-
"",
626-
compat = Map(
627-
"3" -> """|unsafeExceptions scala
628-
|unchecked scala
629-
|unsafeNulls - scala.runtime.stdLibPatches.language
630-
|unshared(): unshared
631-
|uncheckedStable(): uncheckedStable""".stripMargin,
632-
"3.3.0" -> """|unsafeExceptions scala
633-
|unchecked scala
634-
|unsafe - scala.caps
635-
|unsafeNulls - scala.runtime.stdLibPatches.language
636-
|unshared(): unshared""".stripMargin,
637-
"3.3.1" -> """|unsafeExceptions scala
638-
|unchecked scala
639-
|unsafe - scala.caps
640-
|unsafeNulls - scala.runtime.stdLibPatches.language
641-
|unshared(): unshared""".stripMargin,
642-
"3.3.3" -> """|unsafeExceptions scala
643-
|unchecked scala
644-
|unsafe - caps
645-
|unsafeNulls - scala.runtime.stdLibPatches.language
646-
|unshared(): unshared""".stripMargin,
647-
"3.4" -> """|unsafeExceptions scala
648-
|unchecked scala
649-
|unsafe - scala.caps
650-
|unsafeNulls - scala.runtime.stdLibPatches.language
651-
|unused - scala.annotation
652-
|""".stripMargin,
653-
">=3.4.1-RC1-bin-20240201-hash-NIGHTLY" ->
654-
"""|unsafe - scala.caps
655-
|unsafeNulls - scala.runtime.stdLibPatches.language
656-
|unused - scala.annotation
657-
|unshared - scala.annotation.internal
658-
|unspecialized - scala.annotation
659-
|""".stripMargin,
660-
">=3.4.2-RC1-bin-20240301-hash-NIGHTLY" -> ""
661-
),
662-
topLines = Some(5)
587+
""
663588
)
664589

665590
check(

tests/cross/src/test/scala/tests/pc/CompletionSuite.scala

+13
Original file line numberDiff line numberDiff line change
@@ -2368,4 +2368,17 @@ class CompletionSuite extends BaseCompletionSuite {
23682368
itemIndex = 1
23692369
)
23702370

2371+
check(
2372+
"def-arg",
2373+
"""|package a
2374+
|object W {
2375+
| val aaaaaa = 1
2376+
|}
2377+
|object O {
2378+
| def foo(aa@@)
2379+
|}
2380+
|""".stripMargin,
2381+
""
2382+
)
2383+
23712384
}

0 commit comments

Comments
 (0)