Skip to content

Commit 3694d95

Browse files
authored
1 parent f663a8b commit 3694d95

File tree

4 files changed

+136
-16
lines changed

4 files changed

+136
-16
lines changed

presentation-compiler/src/main/dotty/tools/pc/PcInlayHintsProvider.scala

+5-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class PcInlayHintsProvider(
8383
if params.implicitParameters() =>
8484
val labelParts = symbols.map(s => List(labelPart(s, s.decodedName)))
8585
val label =
86-
if allImplicit then labelParts.separated("(", ", ", ")")
86+
if allImplicit then labelParts.separated("(using ", ", ", ")")
8787
else labelParts.separated(", ")
8888
inlayHints.add(
8989
adjustPos(pos).toLsp,
@@ -218,7 +218,10 @@ object ImplicitParameters:
218218
case Apply(fun, args)
219219
if args.exists(isSyntheticArg) && !tree.sourcePos.span.isZeroExtent =>
220220
val (implicitArgs, providedArgs) = args.partition(isSyntheticArg)
221-
val allImplicit = providedArgs.isEmpty
221+
val allImplicit = providedArgs.isEmpty || providedArgs.forall {
222+
case Ident(name) => name == nme.MISSING
223+
case _ => false
224+
}
222225
val pos = implicitArgs.head.sourcePos
223226
Some(implicitArgs.map(_.symbol), pos, allImplicit)
224227
case _ => None

presentation-compiler/src/main/dotty/tools/pc/printer/ShortenedTypePrinter.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class ShortenedTypePrinter(
6666

6767
private val foundRenames = collection.mutable.LinkedHashMap.empty[Symbol, String]
6868

69-
def getUsedRenames: Map[Symbol, String] = foundRenames.toMap
69+
def getUsedRenames: Map[Symbol, String] =
70+
foundRenames.toMap.filter { case (k, v) => k.showName != v }
7071

7172
def getUsedRenamesInfo(using Context): List[String] =
7273
foundRenames.map { (from, to) =>

presentation-compiler/test/dotty/tools/pc/tests/hover/HoverTermSuite.scala

+16
Original file line numberDiff line numberDiff line change
@@ -637,3 +637,19 @@ class HoverTermSuite extends BaseHoverSuite:
637637
|def test(d: S[Int], f: S[Char]): AB[Int, String]
638638
|```""".stripMargin,
639639
)
640+
641+
@Test def `import-no-rename` =
642+
check(
643+
"""
644+
|import scala.collection
645+
|
646+
|object O {
647+
| <<val ab@@c = collection.Map(1 -> 2)>>
648+
|}
649+
|""".stripMargin,
650+
"""
651+
|```scala
652+
|val abc: scala.collection.Map[Int, Int]
653+
|```
654+
|""".stripMargin
655+
)
+113-13
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class InlayHintsSuite extends BaseInlayHintsSuite {
1919
| def foo()/*: Unit<<scala/Unit#>>*/ = {
2020
| implicit val imp: Int = 2
2121
| def addOne(x: Int)(implicit one: Int)/*: Int<<scala/Int#>>*/ = x + one
22-
| val x/*: Int<<scala/Int#>>*/ = addOne(1)/*(imp<<(3:17)>>)*/
22+
| val x/*: Int<<scala/Int#>>*/ = addOne(1)/*(using imp<<(3:17)>>)*/
2323
| }
2424
|}
2525
|""".stripMargin
@@ -66,7 +66,7 @@ class InlayHintsSuite extends BaseInlayHintsSuite {
6666
|object Main {
6767
| implicit val imp: Int = 2
6868
| def addOne(x: Int)(implicit one: Int)/*: Int<<scala/Int#>>*/ = x + one
69-
| val x/*: Int<<scala/Int#>>*/ = addOne(1)/*(imp<<(3:15)>>)*/
69+
| val x/*: Int<<scala/Int#>>*/ = addOne(1)/*(using imp<<(3:15)>>)*/
7070
|}
7171
|""".stripMargin
7272
)
@@ -100,7 +100,7 @@ class InlayHintsSuite extends BaseInlayHintsSuite {
100100
|object Main {
101101
| implicit val imp: Int = 2
102102
| def addOne(x: Int)(using one: Int)/*: Int<<scala/Int#>>*/ = x + one
103-
| val x/*: Int<<scala/Int#>>*/ = addOne(1)/*(imp<<(3:15)>>)*/
103+
| val x/*: Int<<scala/Int#>>*/ = addOne(1)/*(using imp<<(3:15)>>)*/
104104
|}
105105
|""".stripMargin
106106
)
@@ -502,7 +502,7 @@ class InlayHintsSuite extends BaseInlayHintsSuite {
502502
|}
503503
|""".stripMargin,
504504
"""|object Main {
505-
| val ordered/*: String<<scala/Predef.String#>>*/ = /*augmentString<<scala/Predef.augmentString().>>(*/"acb"/*)*/.sorted/*[Char<<scala/Char#>>]*//*(Char<<scala/math/Ordering.Char.>>)*/
505+
| val ordered/*: String<<scala/Predef.String#>>*/ = /*augmentString<<scala/Predef.augmentString().>>(*/"acb"/*)*/.sorted/*[Char<<scala/Char#>>]*//*(using Char<<scala/math/Ordering.Char.>>)*/
506506
|}
507507
|""".stripMargin
508508
)
@@ -608,18 +608,18 @@ class InlayHintsSuite extends BaseInlayHintsSuite {
608608
|
609609
| /*StringTestOps<<(6:17)>>(*/"foo"/*)*/ should {
610610
| /*StringTestOps<<(6:17)>>(*/"checkThing1"/*)*/ in {
611-
| checkThing1[String]/*(instancesString<<(10:15)>>)*/
612-
| }/*(here<<(5:15)>>)*/
611+
| checkThing1[String]/*(using instancesString<<(10:15)>>)*/
612+
| }/*(using here<<(5:15)>>)*/
613613
| /*StringTestOps<<(6:17)>>(*/"checkThing2"/*)*/ in {
614-
| checkThing2[String]/*(instancesString<<(10:15)>>, instancesString<<(10:15)>>)*/
615-
| }/*(here<<(5:15)>>)*/
616-
| }/*(subjectRegistrationFunction<<(3:15)>>)*/
614+
| checkThing2[String]/*(using instancesString<<(10:15)>>, instancesString<<(10:15)>>)*/
615+
| }/*(using here<<(5:15)>>)*/
616+
| }/*(using subjectRegistrationFunction<<(3:15)>>)*/
617617
|
618618
| /*StringTestOps<<(6:17)>>(*/"bar"/*)*/ should {
619619
| /*StringTestOps<<(6:17)>>(*/"checkThing1"/*)*/ in {
620-
| checkThing1[String]/*(instancesString<<(10:15)>>)*/
621-
| }/*(here<<(5:15)>>)*/
622-
| }/*(subjectRegistrationFunction<<(3:15)>>)*/
620+
| checkThing1[String]/*(using instancesString<<(10:15)>>)*/
621+
| }/*(using here<<(5:15)>>)*/
622+
| }/*(using subjectRegistrationFunction<<(3:15)>>)*/
623623
|
624624
| def checkThing1[A](implicit ev: Eq[A])/*: Nothing<<scala/Nothing#>>*/ = ???
625625
| def checkThing2[A](implicit ev: Eq[A], sem: Semigroup[A])/*: Nothing<<scala/Nothing#>>*/ = ???
@@ -664,4 +664,104 @@ class InlayHintsSuite extends BaseInlayHintsSuite {
664664
|case class ErrorMessage(error)
665665
|""".stripMargin
666666
)
667-
}
667+
668+
@Test def `anonymous-given` =
669+
check(
670+
"""|package example
671+
|
672+
|trait Ord[T]:
673+
| def compare(x: T, y: T): Int
674+
|
675+
|given intOrd: Ord[Int] with
676+
| def compare(x: Int, y: Int) =
677+
| if x < y then -1 else if x > y then +1 else 0
678+
|
679+
|given Ord[String] with
680+
| def compare(x: String, y: String) =
681+
| x.compare(y)
682+
|
683+
|""".stripMargin,
684+
"""|package example
685+
|
686+
|trait Ord[T]:
687+
| def compare(x: T, y: T): Int
688+
|
689+
|given intOrd: Ord[Int] with
690+
| def compare(x: Int, y: Int)/*: Int<<scala/Int#>>*/ =
691+
| if x < y then -1 else if x > y then +1 else 0
692+
|
693+
|given Ord[String] with
694+
| def compare(x: String, y: String)/*: Int<<scala/Int#>>*/ =
695+
| /*augmentString<<scala/Predef.augmentString().>>(*/x/*)*/.compare(y)
696+
|
697+
|""".stripMargin
698+
)
699+
700+
@Test def `context-bounds1` =
701+
check(
702+
"""|package example
703+
|object O {
704+
| given Int = 1
705+
| def test[T: Ordering](x: T)(using Int) = ???
706+
| test(1)
707+
|}
708+
|""".stripMargin,
709+
"""|package example
710+
|object O {
711+
| given Int = 1
712+
| def test[T: Ordering](x: T)(using Int)/*: Nothing<<scala/Nothing#>>*/ = ???
713+
| test/*[Int<<scala/Int#>>]*/(1)/*(using Int<<scala/math/Ordering.Int.>>, given_Int<<(2:8)>>)*/
714+
|}
715+
|""".stripMargin
716+
)
717+
718+
@Test def `context-bounds2` =
719+
check(
720+
"""|package example
721+
|object O {
722+
| def test[T: Ordering](x: T) = ???
723+
| test(1)
724+
|}
725+
|""".stripMargin,
726+
"""|package example
727+
|object O {
728+
| def test[T: Ordering](x: T)/*: Nothing<<scala/Nothing#>>*/ = ???
729+
| test/*[Int<<scala/Int#>>]*/(1)/*(using Int<<scala/math/Ordering.Int.>>)*/
730+
|}
731+
|""".stripMargin
732+
)
733+
734+
@Test def `context-bounds3` =
735+
check(
736+
"""|package example
737+
|object O {
738+
| def test[T: Ordering](x: T)(using Int) = ???
739+
| test(1)
740+
|}
741+
|""".stripMargin,
742+
"""|package example
743+
|object O {
744+
| def test[T: Ordering](x: T)(using Int)/*: Nothing<<scala/Nothing#>>*/ = ???
745+
| test/*[Int<<scala/Int#>>]*/(1)/*(using Int<<scala/math/Ordering.Int.>>)*/
746+
|}
747+
|""".stripMargin
748+
)
749+
750+
@Test def `context-bounds4` =
751+
check(
752+
"""|package example
753+
|object O {
754+
| implicit val i: Int = 123
755+
| def test[T: Ordering](x: T)(implicit v: Int) = ???
756+
| test(1)
757+
|}
758+
|""".stripMargin,
759+
"""|package example
760+
|object O {
761+
| implicit val i: Int = 123
762+
| def test[T: Ordering](x: T)(implicit v: Int)/*: Nothing<<scala/Nothing#>>*/ = ???
763+
| test/*[Int<<scala/Int#>>]*/(1)/*(using Int<<scala/math/Ordering.Int.>>, i<<(2:15)>>)*/
764+
|}
765+
|""".stripMargin
766+
)
767+
}

0 commit comments

Comments
 (0)