Skip to content

Commit c1cc74e

Browse files
tgodzikdos65
authored andcommitted
scala3: signature help changes api
See: scala/scala3#15278 `Signatures.callInfo` was deprecated and we should use `Signatures.signatureHelp`
1 parent 471c3db commit c1cc74e

File tree

8 files changed

+189
-39
lines changed

8 files changed

+189
-39
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package scala.meta.internal.pc
2+
3+
import dotty.tools.dotc.ast.tpd
4+
import dotty.tools.dotc.util.SourcePosition
5+
import dotty.tools.dotc.core.Contexts.*
6+
import dotty.tools.dotc.util.Signatures
7+
import dotty.tools.dotc.util.Signatures.Signature
8+
import scala.meta.internal.mtags.MtagsEnrichments.*
9+
import scala.meta.pc.SymbolSearch
10+
import dotty.tools.dotc.core.Flags
11+
import dotty.tools.dotc.core.Denotations.*
12+
13+
object MetalsSignatures:
14+
15+
def signatures(
16+
search: SymbolSearch,
17+
path: List[tpd.Tree],
18+
pos: SourcePosition
19+
)(using Context): (Int, Int, List[(Signature, Denotation)]) =
20+
val (paramN, callableN, alternatives) =
21+
Signatures.callInfo(path, pos.span)
22+
val infos = alternatives.flatMap { denot =>
23+
val updatedDenot =
24+
path.headOption
25+
.map { t =>
26+
val pre = t.qual
27+
denot.asSeenFrom(pre.tpe.widenTermRefExpr)
28+
}
29+
.getOrElse(denot)
30+
Signatures.toSignature(updatedDenot).map {
31+
(_, updatedDenot)
32+
}
33+
}
34+
(paramN, callableN, infos)
35+
end signatures
36+
end MetalsSignatures
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package scala.meta.internal.pc
2+
3+
import scala.meta.internal.mtags.MtagsEnrichments.*
4+
import scala.meta.pc.SymbolSearch
5+
6+
import dotty.tools.dotc.ast.tpd
7+
import dotty.tools.dotc.core.Contexts.*
8+
import dotty.tools.dotc.core.Denotations.*
9+
import dotty.tools.dotc.core.Flags
10+
import dotty.tools.dotc.util.Signatures
11+
import dotty.tools.dotc.util.Signatures.Signature
12+
import dotty.tools.dotc.util.SourcePosition
13+
14+
object MetalsSignatures:
15+
16+
def signatures(
17+
search: SymbolSearch,
18+
path: List[tpd.Tree],
19+
pos: SourcePosition
20+
)(using Context): (Int, Int, List[(Signature, Denotation)]) =
21+
val (paramN, callableN, alternatives) =
22+
Signatures.callInfo(path, pos.span)
23+
val infos = alternatives.flatMap { denot =>
24+
val updatedDenot =
25+
path.headOption
26+
.map { t =>
27+
val pre = t.qual
28+
denot.asSeenFrom(pre.tpe.widenTermRefExpr)
29+
}
30+
.getOrElse(denot)
31+
Signatures.toSignature(updatedDenot).map {
32+
(_, updatedDenot)
33+
}
34+
}
35+
(paramN, callableN, infos)
36+
end signatures
37+
end MetalsSignatures
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package scala.meta.internal.pc
2+
3+
import dotty.tools.dotc.ast.tpd
4+
import dotty.tools.dotc.util.SourcePosition
5+
import dotty.tools.dotc.core.Contexts.*
6+
import dotty.tools.dotc.util.Signatures
7+
import dotty.tools.dotc.util.Signatures.Signature
8+
import scala.meta.internal.mtags.MtagsEnrichments.*
9+
import scala.meta.pc.SymbolSearch
10+
import dotty.tools.dotc.core.Flags
11+
import dotty.tools.dotc.core.Denotations.*
12+
13+
object MetalsSignatures:
14+
15+
def signatures(
16+
search: SymbolSearch,
17+
path: List[tpd.Tree],
18+
pos: SourcePosition
19+
)(using ctx: Context): (Int, Int, List[(Signature, Denotation)]) =
20+
val (paramN, callableN, alternatives) =
21+
Signatures.signatureHelp(path, pos.span)
22+
val infos = alternatives.flatMap { signature =>
23+
signature.denot.map {
24+
(signature, _)
25+
}
26+
}
27+
28+
(paramN, callableN, infos)
29+
end signatures
30+
end MetalsSignatures

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

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,33 @@ object SignatureHelpProvider:
3232
val sourceFile = CompilerInterfaces.toSource(params.uri, params.text)
3333
driver.run(uri, sourceFile)
3434

35-
given Context = driver.currentCtx
35+
given ctx: Context = driver.currentCtx
3636

3737
val pos = driver.sourcePosition(params)
3838
val trees = driver.openedTrees(uri)
3939

4040
val path =
4141
Interactive.pathTo(trees, pos).dropWhile(t => notCurrentApply(t, pos))
4242

43-
val (paramN, callableN, alternatives) =
44-
Signatures.callInfo(path, pos.span)
45-
46-
val signatureInfos =
47-
alternatives.flatMap { denot =>
48-
val updatedDenot =
49-
path.headOption
50-
.map { t =>
51-
val pre = t.qual
52-
denot.asSeenFrom(pre.tpe.widenTermRefExpr)
53-
}
54-
.getOrElse(denot)
55-
val doc = search.symbolDocumentation(denot.symbol)
56-
(doc, Signatures.toSignature(updatedDenot)) match
57-
case (Some(info), Some(signature)) =>
58-
withDocumentation(
59-
info,
60-
signature,
61-
denot.symbol.is(Flags.JavaDefined)
62-
)
63-
case (_, sig) => sig
43+
val (paramN, callableN, alternativeSignatures) =
44+
MetalsSignatures.signatures(
45+
search,
46+
path,
47+
pos
48+
)
49+
50+
val signatureInfos = alternativeSignatures.map { case (signature, denot) =>
51+
search.symbolDocumentation(denot.symbol) match
52+
case Some(doc) =>
53+
withDocumentation(
54+
doc,
55+
signature,
56+
denot.symbol.is(Flags.JavaDefined)
57+
).getOrElse(signature)
58+
case _ => signature
59+
60+
}
6461

65-
}
6662
new l.SignatureHelp(
6763
signatureInfos.map(signatureToSignatureInformation).asJava,
6864
callableN,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class CompletionBacktickSuite extends BaseCompletionSuite {
1616
filterText = "type",
1717
compat = Map(
1818
"3" -> "type: Int",
19-
">=3.2.0" -> "`type`: Int"
19+
">=3.2.0" -> "`type`: Int",
20+
">=3.2.1-RC1-bin-20220616-140693d-NIGHTLY" -> "type: Int"
2021
)
2122
)
2223

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,22 @@ class SignatureHelpDocSuite extends BaseSignatureHelpSuite {
308308
| @param x (Int, Int, Int) the value
309309
|""".stripMargin,
310310
compat = Map(
311-
// potentially correct, discussed in https://github.com/lampepfl/dotty/issues/15244
312311
"3" ->
313312
"""|apply[T1, T2, T3](_1: T1, _2: T2, _3: T3): (T1, T2, T3)
314313
| ^^^^^^
314+
|""".stripMargin,
315+
">=3.2.0-RC1-bin-20220610-30f83f7-NIGHTLY" ->
316+
"""|An Option factory which creates Some(x) if the argument is not null,
317+
| and None if it is null.
318+
|
319+
|
320+
|**Parameters**
321+
|- `x`: the value
322+
|
323+
|**Returns:** Some(value) if value != null, None if value == null
324+
|apply[A](x: A): Option[A]
325+
| ^^^^
326+
| @param x the value
315327
|""".stripMargin
316328
)
317329
)

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,14 @@ class SignatureHelpPatternSuite extends BaseSignatureHelpSuite {
215215
| ^^^^^^^
216216
|""".stripMargin,
217217
compat = Map(
218-
"3" -> """|(String)
219-
| ^^^^^^
218+
"3.0" -> """|(String)
219+
| ^^^^^^
220+
|""".stripMargin,
221+
"3.1" -> """|(String)
222+
| ^^^^^^
223+
|""".stripMargin,
224+
"3" -> """|(List[String])
225+
| ^^^^^^^^^^^^
220226
|""".stripMargin
221227
)
222228
)
@@ -260,7 +266,15 @@ class SignatureHelpPatternSuite extends BaseSignatureHelpSuite {
260266
// generated code. Feel free to update this test to have the same expected output as
261267
// `pat3` without regressing signature help in othere cases like partial functions that
262268
// generate qualifiers with offset positions.
263-
""
269+
"",
270+
compat = Map(
271+
"3.0" -> "",
272+
"3.1" -> "",
273+
"3" ->
274+
"""|(String, String)
275+
| ^^^^^^
276+
|""".stripMargin
277+
)
264278
)
265279

266280
check(
@@ -303,8 +317,7 @@ class SignatureHelpPatternSuite extends BaseSignatureHelpSuite {
303317
)
304318

305319
check(
306-
// https://github.com/lampepfl/dotty/issues/15248
307-
"pat-negative".tag(IgnoreScala3),
320+
"pat-negative",
308321
"""
309322
|object And {
310323
| def unapply[A](a: A): Some[(A, A)] = Some((a, a))

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

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite {
300300
)
301301

302302
check(
303-
// https://github.com/lampepfl/dotty/issues/15249
304303
"tparam3".tag(IgnoreScala3),
305304
"""
306305
|object a {
@@ -311,8 +310,8 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite {
311310
| ^
312311
|""".stripMargin
313312
)
313+
314314
check(
315-
// https://github.com/lampepfl/dotty/issues/15249
316315
"tparam4".tag(IgnoreScala3),
317316
"""
318317
|object a {
@@ -364,7 +363,13 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite {
364363
| }
365364
|}
366365
""".stripMargin,
367-
""
366+
"",
367+
compat = Map(
368+
"3" ->
369+
"""|apply[K, V](elems: (K, V)*): Map[K, V]
370+
| ^^^^^^^^^^^^^^
371+
|""".stripMargin
372+
)
368373
)
369374
check(
370375
"for",
@@ -464,7 +469,15 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite {
464469
| }
465470
|}
466471
""".stripMargin,
467-
""
472+
"",
473+
compat = Map(
474+
"3.0" -> "",
475+
"3.1" -> "",
476+
"3" ->
477+
"""|apply[K, V](elems: (K, V)*): Map[K, V]
478+
| ^^^^^^^^^^^^^^
479+
|""".stripMargin
480+
)
468481
)
469482

470483
check(
@@ -681,7 +694,6 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite {
681694
)
682695

683696
check(
684-
// https://github.com/lampepfl/dotty/issues/15249
685697
"evidence".tag(IgnoreScala3),
686698
"""
687699
|object a {
@@ -717,7 +729,6 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite {
717729
)
718730

719731
check(
720-
// https://github.com/lampepfl/dotty/issues/15249
721732
"type".tag(IgnoreScala3),
722733
"""
723734
|object a {
@@ -743,14 +754,20 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite {
743754

744755
check(
745756
"off-by-one".tag(
746-
IgnoreScalaVersion.for3LessThan("3.2.0-RC1-bin-20220519-ee9cc8f-NIGHTLY")
757+
IgnoreScalaVersion.for3LessThan("3.2.0-RC1")
747758
),
748759
"""
749760
|object a {
750761
| identity(42)@@
751762
|}
752763
|""".stripMargin,
753-
""
764+
"",
765+
compat = Map(
766+
"3" ->
767+
"""|identity[A](x: A): A
768+
| ^^^^
769+
|""".stripMargin
770+
)
754771
)
755772

756773
check(
@@ -774,7 +791,15 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite {
774791
| Option(1).fold(2)@@(_ + 1)
775792
|}
776793
|""".stripMargin,
777-
""
794+
"",
795+
compat = Map(
796+
"3.0" -> "",
797+
"3.1" -> "",
798+
"3" ->
799+
"""|fold[B](ifEmpty: => B)(f: Int => B): B
800+
| ^^^^^^^^^^^^^
801+
|""".stripMargin
802+
)
778803
)
779804

780805
check(

0 commit comments

Comments
 (0)