Skip to content

Commit c2a538d

Browse files
committed
IDE: fix signature help for Java and Scala 2 methods
Asking for the signature of a method not defined in sources or in Tasty used to throw an exception because the symbol passed to `defPath` must have a span. The call to `defPath` was only used to determine which parameters were implicit, but this can be done in an easier way by checking `isImplicitMethod`, so we can get rid of it at no loss.
1 parent 89a87d3 commit c2a538d

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

compiler/src/dotty/tools/dotc/util/Signatures.scala

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,27 +80,25 @@ object Signatures {
8080
val symbol = denot.symbol
8181
val docComment = ParsedComment.docOf(symbol)
8282
val classTree = symbol.topLevelClass.asClass.rootTree
83-
val isImplicit: TermName => Boolean = tpd.defPath(symbol, classTree).lastOption match {
84-
case Some(DefDef(_, _, paramss, _, _)) =>
85-
val flatParams = paramss.flatten
86-
name => flatParams.find(_.name == name).map(_.symbol.is(Implicit)).getOrElse(false)
87-
case _ =>
88-
_ => false
83+
84+
def toParamss(tp: MethodType)(implicit ctx: Context): List[List[Param]] = {
85+
val rest = tp.resType match {
86+
case res: MethodType =>
87+
toParamss(res)
88+
case _ =>
89+
Nil
90+
}
91+
tp.paramNames.zip(tp.paramInfos).map { case (name, info) =>
92+
Signatures.Param(name.show,
93+
info.widenTermRefExpr.show,
94+
docComment.flatMap(_.paramDoc(name)),
95+
isImplicit = tp.isImplicitMethod)
96+
} :: rest
8997
}
9098

9199
denot.info.stripPoly match {
92100
case tpe: MethodType =>
93-
val infos = {
94-
tpe.paramInfoss.zip(tpe.paramNamess).map { case (infos, names) =>
95-
infos.zip(names).map { case (info, name) =>
96-
Signatures.Param(name.show,
97-
info.widenTermRefExpr.show,
98-
docComment.flatMap(_.paramDoc(name)),
99-
isImplicit = isImplicit(name))
100-
}
101-
}
102-
}
103-
101+
val paramss = toParamss(tpe)
104102
val typeParams = denot.info match {
105103
case poly: PolyType =>
106104
poly.paramNames.zip(poly.paramInfos).map { case (x, y) => x.show + y.show }
@@ -115,7 +113,7 @@ object Signatures {
115113
val signature =
116114
Signatures.Signature(name,
117115
typeParams,
118-
infos,
116+
paramss,
119117
returnType,
120118
docComment.map(_.mainDoc))
121119

language-server/test/dotty/tools/languageserver/SignatureHelpTest.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@ import dotty.tools.dotc.util.Signatures.{Param => P, Signature => S}
88

99
class SignatureHelpTest {
1010

11+
@Test def javaParam: Unit = {
12+
val signature =
13+
S("codePointAt", Nil, List(List(P("x$0", "Int"))), Some("Int"))
14+
code"""object O {
15+
"hello".codePointAt($m1)
16+
}""".withSource
17+
.signatureHelp(m1, List(signature), Some(0), 0)
18+
}
19+
20+
@Test def scala2Param: Unit = {
21+
val signature =
22+
S("apply[A]", Nil, List(List(P("xs", "A*"))), Some("List[A]"))
23+
code"""object O {
24+
List($m1)
25+
}""".withSource
26+
.signatureHelp(m1, List(signature), Some(0), 0)
27+
}
28+
1129
@Test def singleParam: Unit = {
1230
val signature =
1331
S("foo", Nil, List(List(P("param0", "Int"))), Some("Int"))

0 commit comments

Comments
 (0)