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 active param index for empty param lists #20142

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
change index of param when empty param list
  • Loading branch information
github-lucas-nou authored and iusildra committed Apr 9, 2024
commit e5dd6807ed511e546f3a55ea15146f91eec40396
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 @@ -70,7 +70,7 @@ object SignatureHelpProvider:
new l.SignatureHelp(
signatureInfos.map(signatureToSignatureInformation).asJava,
callableN,
paramN
if signatureInfos.isEmpty then null else paramN
rochala marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

@rochala rochala Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I see why it worked with null on my setup.
This method will never return null if there is at least a single signature present.
I can now confirm that null indeed is not working, and the solution is -1 so
you should change this back to just paramN

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, will push the true fix this evening ^^

)
case _ => new l.SignatureHelp()
end signatureHelp
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
)
Loading