From e5dd6807ed511e546f3a55ea15146f91eec40396 Mon Sep 17 00:00:00 2001 From: Lucas Nouguier Date: Tue, 9 Apr 2024 18:46:24 +0200 Subject: [PATCH 1/2] change index of param when empty param list --- .../dotty/tools/dotc/util/Signatures.scala | 7 ++++-- .../tools/pc/SignatureHelpProvider.scala | 2 +- .../pc/base/BaseSignatureHelpSuite.scala | 2 +- .../signaturehelp/SignatureHelpSuite.scala | 25 +++++++++++++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/util/Signatures.scala b/compiler/src/dotty/tools/dotc/util/Signatures.scala index 736633e0f6a7..3f7d7dd39531 100644 --- a/compiler/src/dotty/tools/dotc/util/Signatures.scala +++ b/compiler/src/dotty/tools/dotc/util/Signatures.scala @@ -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) @@ -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) diff --git a/presentation-compiler/src/main/dotty/tools/pc/SignatureHelpProvider.scala b/presentation-compiler/src/main/dotty/tools/pc/SignatureHelpProvider.scala index f7797efbfb27..86956c23e86b 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/SignatureHelpProvider.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/SignatureHelpProvider.scala @@ -70,7 +70,7 @@ object SignatureHelpProvider: new l.SignatureHelp( signatureInfos.map(signatureToSignatureInformation).asJava, callableN, - paramN + if signatureInfos.isEmpty then null else paramN ) case _ => new l.SignatureHelp() end signatureHelp diff --git a/presentation-compiler/test/dotty/tools/pc/base/BaseSignatureHelpSuite.scala b/presentation-compiler/test/dotty/tools/pc/base/BaseSignatureHelpSuite.scala index ca647502fabf..5f73b108e4de 100644 --- a/presentation-compiler/test/dotty/tools/pc/base/BaseSignatureHelpSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/base/BaseSignatureHelpSuite.scala @@ -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 diff --git a/presentation-compiler/test/dotty/tools/pc/tests/signaturehelp/SignatureHelpSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/signaturehelp/SignatureHelpSuite.scala index 9e223cb094e3..2b458ced9683 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/signaturehelp/SignatureHelpSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/signaturehelp/SignatureHelpSuite.scala @@ -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 + ) From 244799e11eb93f681db8e958fd2288bd7eebadbe Mon Sep 17 00:00:00 2001 From: Lucas Nouguier Date: Tue, 9 Apr 2024 22:13:33 +0200 Subject: [PATCH 2/2] fix: applied review --- .../src/main/dotty/tools/pc/SignatureHelpProvider.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/presentation-compiler/src/main/dotty/tools/pc/SignatureHelpProvider.scala b/presentation-compiler/src/main/dotty/tools/pc/SignatureHelpProvider.scala index 86956c23e86b..f7797efbfb27 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/SignatureHelpProvider.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/SignatureHelpProvider.scala @@ -70,7 +70,7 @@ object SignatureHelpProvider: new l.SignatureHelp( signatureInfos.map(signatureToSignatureInformation).asJava, callableN, - if signatureInfos.isEmpty then null else paramN + paramN ) case _ => new l.SignatureHelp() end signatureHelp