Skip to content

Commit 90205c3

Browse files
committed
bugfix: [Scala 3] Adjust changes for the most recent compiler version
To account for scala/scala3#15517
1 parent 5bd656f commit 90205c3

File tree

4 files changed

+108
-39
lines changed

4 files changed

+108
-39
lines changed

mtags/src/main/scala-3/scala/meta/internal/pc/SignatureHelpProvider.scala

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ import dotty.tools.dotc.util.Signatures
2020
import dotty.tools.dotc.util.Signatures.Signature
2121
import dotty.tools.dotc.util.SourcePosition
2222
import org.eclipse.{lsp4j as l}
23+
import dotty.tools.dotc.ast.Trees.AppliedTypeTree
24+
import dotty.tools.dotc.ast.Trees.TypeApply
2325

2426
object SignatureHelpProvider:
2527

28+
private val versionSupportsTypeParams =
29+
SemVer.isCompatibleVersion(
30+
"3.2.1-RC1-bin-20220628-65a86ae-NIGHTLY",
31+
BuildInfo.scalaCompilerVersion
32+
)
33+
2634
def signatureHelp(
2735
driver: InteractiveDriver,
2836
params: OffsetParams,
@@ -59,23 +67,38 @@ object SignatureHelpProvider:
5967

6068
}
6169

70+
/* Versions prior to 3.2.1 did not support type parameters
71+
* so we need to skip them.
72+
*/
73+
val adjustedParamN =
74+
if versionSupportsTypeParams then paramN
75+
else
76+
val adjusted =
77+
signatureInfos.lift(callableN).map(_.tparams.size).getOrElse(0)
78+
paramN + adjusted
6279
new l.SignatureHelp(
6380
signatureInfos.map(signatureToSignatureInformation).asJava,
6481
callableN,
65-
paramN
82+
adjustedParamN
6683
)
6784
end signatureHelp
6885

69-
private def isTuple(tree: tpd.Tree)(using Context): Boolean =
70-
ctx.definitions.isTupleClass(tree.symbol.owner.companionClass)
86+
private def isValid(tree: tpd.Tree)(using Context): Boolean =
87+
ctx.definitions.isTupleNType(tree.tpe) || ctx.definitions.isFunctionType(
88+
tree.tpe
89+
)
7190

7291
private def notCurrentApply(
7392
tree: tpd.Tree,
7493
pos: SourcePosition
7594
)(using Context): Boolean =
7695
tree match
7796
case unapply: tpd.UnApply =>
78-
unapply.fun.span.contains(pos.span) || isTuple(unapply)
97+
unapply.fun.span.contains(pos.span) || isValid(unapply)
98+
case typeTree @ AppliedTypeTree(fun, _) =>
99+
fun.span.contains(pos.span) || isValid(typeTree)
100+
case typeApply @ TypeApply(fun, _) =>
101+
fun.span.contains(pos.span) || isValid(typeApply)
79102
case appl: tpd.GenericApply =>
80103
/* find first apply that the cursor is located in arguments and not at function name
81104
* for example in:
@@ -128,23 +151,27 @@ object SignatureHelpProvider:
128151
private def signatureToSignatureInformation(
129152
signature: Signatures.Signature
130153
): l.SignatureInformation =
154+
val tparams = signature.tparams.map(Signatures.Param("", _))
131155
val paramInfoss =
132-
signature.paramss.map(_.map(paramToParameterInformation))
133-
val paramLists = signature.paramss
134-
.map { paramList =>
135-
val labels = paramList.map(_.show)
136-
val prefix = if paramList.exists(_.isImplicit) then "using " else ""
137-
labels.mkString(prefix, ", ", "")
138-
}
139-
.mkString("(", ")(", ")")
156+
(tparams ::: signature.paramss.flatten).map(paramToParameterInformation)
157+
val paramLists =
158+
if signature.paramss.forall(_.isEmpty) && tparams.nonEmpty then ""
159+
else
160+
signature.paramss
161+
.map { paramList =>
162+
val labels = paramList.map(_.show)
163+
val prefix = if paramList.exists(_.isImplicit) then "using " else ""
164+
labels.mkString(prefix, ", ", "")
165+
}
166+
.mkString("(", ")(", ")")
140167
val tparamsLabel =
141168
if signature.tparams.isEmpty then ""
142169
else signature.tparams.mkString("[", ", ", "]")
143170
val returnTypeLabel = signature.returnType.map(t => s": $t").getOrElse("")
144171
val label = s"${signature.name}$tparamsLabel$paramLists$returnTypeLabel"
145172
val documentation = signature.doc.map(markupContent)
146173
val sig = new l.SignatureInformation(label)
147-
sig.setParameters(paramInfoss.flatten.asJava)
174+
sig.setParameters(paramInfoss.asJava)
148175
documentation.foreach(sig.setDocumentation(_))
149176
sig
150177
end signatureToSignatureInformation

tests/cross/src/test/scala/tests/pc/SignatureHelpDocSuite.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ class SignatureHelpDocSuite extends BaseSignatureHelpSuite {
226226
)
227227

228228
checkDoc(
229-
// https://github.com/lampepfl/dotty/issues/15244
230-
"curry4".tag(IgnoreScala3),
229+
"curry4".tag(IgnoreScalaVersion.for3LessThan("3.2.0-RC1")),
231230
"""
232231
|object a {
233232
| def curry(a: Int, b: Int)(c: Int) = a

tests/cross/src/test/scala/tests/pc/SignatureHelpPatternSuite.scala

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ class SignatureHelpPatternSuite extends BaseSignatureHelpSuite {
4141
)
4242

4343
check(
44-
// https://github.com/lampepfl/dotty/issues/15248
45-
"generic2".tag(IgnoreScala3),
44+
"generic2".tag(IgnoreScalaVersion.for3LessThan("3.2.0-RC1")),
4645
"""
4746
|case class Two[T](a: T, b: T)
4847
|object Main {
@@ -53,12 +52,17 @@ class SignatureHelpPatternSuite extends BaseSignatureHelpSuite {
5352
|""".stripMargin,
5453
"""|(Any, Any)
5554
| ^^^
56-
|""".stripMargin
55+
|""".stripMargin,
56+
compat = Map(
57+
"3" ->
58+
"""|(a: T, b: T)
59+
| ^^^^
60+
|""".stripMargin
61+
)
5762
)
5863

5964
check(
60-
// https://github.com/lampepfl/dotty/issues/15248
61-
"generic3".tag(IgnoreScala3),
65+
"generic3".tag(IgnoreScalaVersion.for3LessThan("3.2.0-RC1")),
6266
"""
6367
|case class HKT[C[_], T](a: C[T])
6468
|object Main {
@@ -69,7 +73,13 @@ class SignatureHelpPatternSuite extends BaseSignatureHelpSuite {
6973
|""".stripMargin,
7074
"""|(Any)
7175
| ^^^
72-
|""".stripMargin
76+
|""".stripMargin,
77+
compat = Map(
78+
"3" ->
79+
"""|(a: C[T])
80+
| ^^^^^^^
81+
|""".stripMargin
82+
)
7383
)
7484

7585
check(
@@ -298,8 +308,7 @@ class SignatureHelpPatternSuite extends BaseSignatureHelpSuite {
298308
)
299309

300310
check(
301-
// https://github.com/lampepfl/dotty/issues/15248
302-
"pat6".tag(IgnoreScala3),
311+
"pat6".tag(IgnoreScalaVersion.for3LessThan("3.2.0-RC1")),
303312
"""
304313
|object OpenBrowserCommand {
305314
| def unapply(command: String): Option[Option[Int]] = {
@@ -313,7 +322,13 @@ class SignatureHelpPatternSuite extends BaseSignatureHelpSuite {
313322
""".stripMargin,
314323
"""|(Option[A])
315324
| ^^^^^^^^^
316-
|""".stripMargin
325+
|""".stripMargin,
326+
compat = Map(
327+
"3" ->
328+
"""|(Option[Int])
329+
| ^^^^^^^^^^^
330+
|""".stripMargin
331+
)
317332
)
318333

319334
check(

tests/cross/src/test/scala/tests/pc/SignatureHelpSuite.scala

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,10 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite {
255255
)
256256
check(
257257
// https://github.com/lampepfl/dotty/issues/15244
258-
"vararg".tag(
259-
IgnoreScalaVersion.forLaterThan("3.2.0-RC1-bin-20220519-ee9cc8f-NIGHTLY")
260-
),
258+
"vararg",
259+
// .tag(
260+
// IgnoreScalaVersion.forLaterThan("3.2.0-RC1-bin-20220519-ee9cc8f-NIGHTLY")
261+
// ),
261262
"""
262263
|object a {
263264
| List(1, 2@@
@@ -274,8 +275,9 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite {
274275
)
275276

276277
check(
277-
// https://github.com/lampepfl/dotty/issues/15249
278-
"tparam".tag(IgnoreScala3),
278+
"tparam".tag(
279+
IgnoreScalaVersion.for3LessThan("3.2.1-RC1-bin-20220628-65a86ae-NIGHTLY")
280+
),
279281
"""
280282
|object a {
281283
| identity[I@@]
@@ -287,8 +289,9 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite {
287289
)
288290

289291
check(
290-
// https://github.com/lampepfl/dotty/issues/15249
291-
"tparam2".tag(IgnoreScala3),
292+
"tparam2".tag(
293+
IgnoreScalaVersion.for3LessThan("3.2.1-RC1-bin-20220628-65a86ae-NIGHTLY")
294+
),
292295
"""
293296
|object a {
294297
| Option.empty[I@@]
@@ -300,7 +303,9 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite {
300303
)
301304

302305
check(
303-
"tparam3".tag(IgnoreScala3),
306+
"tparam3".tag(
307+
IgnoreScalaVersion.for3LessThan("3.2.1-RC1-bin-20220628-65a86ae-NIGHTLY")
308+
),
304309
"""
305310
|object a {
306311
| Option[I@@]
@@ -312,7 +317,9 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite {
312317
)
313318

314319
check(
315-
"tparam4".tag(IgnoreScala3),
320+
"tparam4".tag(
321+
IgnoreScalaVersion.for3LessThan("3.2.1-RC1-bin-20220628-65a86ae-NIGHTLY")
322+
),
316323
"""
317324
|object a {
318325
| Map.empty[I@@]
@@ -325,7 +332,10 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite {
325332
"2.11" ->
326333
"""|empty[A, B]: Map[A,B]
327334
| ^
328-
|""".stripMargin
335+
|""".stripMargin,
336+
"3" -> """|empty[K, V]: Map[K, V]
337+
| ^
338+
|""".stripMargin
329339
)
330340
)
331341

@@ -694,7 +704,9 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite {
694704
)
695705

696706
check(
697-
"evidence".tag(IgnoreScala3),
707+
"evidence".tag(
708+
IgnoreScalaVersion.for3LessThan("3.2.1-RC1-bin-20220628-65a86ae-NIGHTLY")
709+
),
698710
"""
699711
|object a {
700712
| Array.empty[@@]
@@ -729,27 +741,43 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite {
729741
)
730742

731743
check(
732-
"type".tag(IgnoreScala3),
744+
"type".tag(
745+
IgnoreScalaVersion.for3LessThan("3.2.1-RC1-bin-20220628-65a86ae-NIGHTLY")
746+
),
733747
"""
734748
|object a {
735749
| val x: Map[Int, Stri@@ng]
736750
|}
737751
""".stripMargin,
738752
"""|Map[A, B]: Map
739753
| ^
740-
| """.stripMargin
754+
| """.stripMargin,
755+
compat = Map(
756+
"3" ->
757+
"""|Map[K, V]: Map
758+
| ^
759+
| """.stripMargin
760+
)
741761
)
742762

743763
check(
744-
"type1".tag(IgnoreScala3),
764+
"type1".tag(
765+
IgnoreScalaVersion.for3LessThan("3.2.1-RC1-bin-20220628-65a86ae-NIGHTLY")
766+
),
745767
"""
746768
|object a {
747769
| val x: Map[Int, Stri@@]
748770
|}
749771
""".stripMargin,
750772
"""|Map[A, B]: Map
751773
| ^
752-
| """.stripMargin
774+
| """.stripMargin,
775+
compat = Map(
776+
"3" ->
777+
"""|Map[K, V]: Map
778+
| ^
779+
| """.stripMargin
780+
)
753781
)
754782

755783
check(

0 commit comments

Comments
 (0)