Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't suggest completions for param names in definition #6620

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@ class Completions(
case Literal(Constant(null)) :: tl =>
advancedCompletions(tl, pos, completionPos)

// def foo(a@@)
case ParamDefinitionCompletions(allowKeywords) =>
(ParamDefinitionCompletions.contribute(allowKeywords, completionPos), true)
case _ =>
val args = NamedArgCompletions.contribute(
pos,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package scala.meta.internal.pc.completions

import dotty.tools.dotc.ast.tpd.*
import dotty.tools.dotc.core.Contexts.Context

object ParamDefinitionCompletions:
private val possibleKeywords = List("using", "implicit")
private def completion(keyword: String) = CompletionValue.keyword(keyword, keyword ++ " ")

def unapply(path: List[Tree])(using Context): Option[Boolean] =
path match
case (vd: ValDef) :: (d : DefDef) :: _ =>
d.paramss.lastOption.map(_.indexWhere(_.span.contains(vd.span))).filter(_ >= 0)
match
case Some(ind) if ind == 0 => Some(true)
case Some(_) => Some(false)
case _ => None
case _ => None

def contribute(allowKeywords: Boolean, pos: CompletionPos): List[CompletionValue] =
if allowKeywords
then possibleKeywords.filter(_.startsWith(pos.query)).map(completion)
else Nil
81 changes: 3 additions & 78 deletions tests/cross/src/test/scala/tests/pc/CompletionKeywordSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -574,92 +574,17 @@ class CompletionKeywordSuite extends BaseCompletionSuite {
| def hello(u@@)
|}""".stripMargin,
"""|using (commit: '')
|unsafeExceptions scala (commit: '')
|unchecked scala (commit: '')
|unsafeNulls - scala.runtime.stdLibPatches.language (commit: '')
|unshared(): unshared (commit: '')""".stripMargin,
|""".stripMargin,
includeCommitCharacter = true,
compat = Map(
"2" -> "",
"3.3.0" -> """|using (commit: '')
|unsafeExceptions scala (commit: '')
|unchecked scala (commit: '')
|unsafe - scala.caps (commit: '')
|unsafeNulls - scala.runtime.stdLibPatches.language (commit: '')
|""".stripMargin,
"3.3.1" -> """|using (commit: '')
|unsafeExceptions scala (commit: '')
|unchecked scala (commit: '')
|unsafe - scala.caps (commit: '')
|unsafeNulls - scala.runtime.stdLibPatches.language (commit: '')
|""".stripMargin,
"3.3.3" -> """|using (commit: '')
|unsafeExceptions scala (commit: '')
|unchecked scala (commit: '')
|unsafe - caps (commit: '')
|unsafeNulls - scala.runtime.stdLibPatches.language (commit: '')
|""".stripMargin,
"3.4" -> """|using (commit: '')
|unsafeExceptions scala (commit: '')
|unchecked scala (commit: '')
|unsafe - scala.caps (commit: '')
|unsafeNulls - scala.runtime.stdLibPatches.language (commit: '')
|""".stripMargin,
">=3.4.1-RC1-bin-20240201-hash-NIGHTLY" ->
"""|using (commit: '')
|unsafe - scala.caps (commit: '')
|unsafeNulls - scala.runtime.stdLibPatches.language (commit: '')
|unused - scala.annotation (commit: '')
|unshared - scala.annotation.internal (commit: '')
|""".stripMargin,
">=3.4.2-RC1-bin-20240301-hash-NIGHTLY" -> "using (commit: '')"
),
topLines = Some(5)
compat = Map("2" -> "")
)

check(
"not-using",
"""|object A{
| def hello(a: String, u@@)
|}""".stripMargin,
"",
compat = Map(
"3" -> """|unsafeExceptions scala
|unchecked scala
|unsafeNulls - scala.runtime.stdLibPatches.language
|unshared(): unshared
|uncheckedStable(): uncheckedStable""".stripMargin,
"3.3.0" -> """|unsafeExceptions scala
|unchecked scala
|unsafe - scala.caps
|unsafeNulls - scala.runtime.stdLibPatches.language
|unshared(): unshared""".stripMargin,
"3.3.1" -> """|unsafeExceptions scala
|unchecked scala
|unsafe - scala.caps
|unsafeNulls - scala.runtime.stdLibPatches.language
|unshared(): unshared""".stripMargin,
"3.3.3" -> """|unsafeExceptions scala
|unchecked scala
|unsafe - caps
|unsafeNulls - scala.runtime.stdLibPatches.language
|unshared(): unshared""".stripMargin,
"3.4" -> """|unsafeExceptions scala
|unchecked scala
|unsafe - scala.caps
|unsafeNulls - scala.runtime.stdLibPatches.language
|unused - scala.annotation
|""".stripMargin,
">=3.4.1-RC1-bin-20240201-hash-NIGHTLY" ->
"""|unsafe - scala.caps
|unsafeNulls - scala.runtime.stdLibPatches.language
|unused - scala.annotation
|unshared - scala.annotation.internal
|unspecialized - scala.annotation
|""".stripMargin,
">=3.4.2-RC1-bin-20240301-hash-NIGHTLY" -> ""
),
topLines = Some(5)
""
)

check(
Expand Down
13 changes: 13 additions & 0 deletions tests/cross/src/test/scala/tests/pc/CompletionSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2368,4 +2368,17 @@ class CompletionSuite extends BaseCompletionSuite {
itemIndex = 1
)

check(
"def-arg",
"""|package a
|object W {
| val aaaaaa = 1
|}
|object O {
| def foo(aa@@)
|}
|""".stripMargin,
""
)

}
Loading