Skip to content

Commit

Permalink
Fix active param index for empty param lists (#20142)
Browse files Browse the repository at this point in the history
Fixes #19969 with @mbovel @rochala

---------

Co-authored-by: Lucas Nouguier <[email protected]>
  • Loading branch information
iusildra and github-lucas-nou authored Apr 10, 2024
1 parent 2148c8d commit adf089b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/util/Signatures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ object Signatures {
fun: tpd.Tree,
isTypeApply: Boolean = false
)(using Context): (Int, Int, List[Signature]) =
def treeQualifier(tree: tpd.Tree): tpd.Tree = tree match
def treeQualifier(tree: tpd.Tree): tpd.Tree =
tree match
case Apply(qual, _) => treeQualifier(qual)
case TypeApply(qual, _) => treeQualifier(qual)
case AppliedTypeTree(qual, _) => treeQualifier(qual)
Expand Down Expand Up @@ -247,7 +248,9 @@ object Signatures {
val alternativeSignatures = alternativesWithTypes
.flatMap(toApplySignature(_, findOutermostCurriedApply(untpdPath), safeParamssListIndex))

val finalParamIndex = currentParamsIndex + previousArgs
val finalParamIndex =
if currentParamsIndex == -1 then -1
else previousArgs + currentParamsIndex
(finalParamIndex, alternativeIndex, alternativeSignatures)
else
(0, 0, Nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ abstract class BaseSignatureHelpSuite extends BasePCSuite:
out
.append(signature.getLabel)
.append("\n")
if (result.getActiveSignature == i && result.getActiveParameter != null && signature.getParameters.size() > 0) {
if (result.getActiveSignature == i && result.getActiveParameter != null && result.getActiveParameter() >= 0 && signature.getParameters.size() > 0) {
val param = signature.getParameters.get(result.getActiveParameter)
val label = param.getLabel.getLeft()
/* We need to find the label of the active parameter and show ^ at that spot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1533,3 +1533,28 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite:
|foo(i: Boolean, s: String)(b: Int): Unit
|""".stripMargin
)

@Test def `proper-param-empty-list` =
check(
"""
|object x {
| def foo[K, V](): Unit = ???
| foo(@@)
|}
|""".stripMargin,
"foo[K, V](): Unit"
)

@Test def `proper-param-list-after-param-empty-list` =
check(
"""
|object x {
| def foo[K, V]()(x: Int): Unit = ???
| foo()(@@)
|}
|""".stripMargin,
"""
|foo[K, V]()(x: Int): Unit
| ^^^^^^
""".stripMargin
)

0 comments on commit adf089b

Please sign in to comment.