Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weekly metals backport #19921

Merged
merged 3 commits into from Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -83,7 +83,7 @@ class PcInlayHintsProvider(
if params.implicitParameters() =>
val labelParts = symbols.map(s => List(labelPart(s, s.decodedName)))
val label =
if allImplicit then labelParts.separated("(", ", ", ")")
if allImplicit then labelParts.separated("(using ", ", ", ")")
else labelParts.separated(", ")
inlayHints.add(
adjustPos(pos).toLsp,
Expand Down Expand Up @@ -218,7 +218,10 @@ object ImplicitParameters:
case Apply(fun, args)
if args.exists(isSyntheticArg) && !tree.sourcePos.span.isZeroExtent =>
val (implicitArgs, providedArgs) = args.partition(isSyntheticArg)
val allImplicit = providedArgs.isEmpty
val allImplicit = providedArgs.isEmpty || providedArgs.forall {
case Ident(name) => name == nme.MISSING
case _ => false
}
val pos = implicitArgs.head.sourcePos
Some(implicitArgs.map(_.symbol), pos, allImplicit)
case _ => None
Expand Down
Expand Up @@ -66,7 +66,8 @@ class ShortenedTypePrinter(

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

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

def getUsedRenamesInfo(using Context): List[String] =
foundRenames.map { (from, to) =>
Expand Down
Expand Up @@ -637,3 +637,19 @@ class HoverTermSuite extends BaseHoverSuite:
|def test(d: S[Int], f: S[Char]): AB[Int, String]
|```""".stripMargin,
)

@Test def `import-no-rename` =
check(
"""
|import scala.collection
|
|object O {
| <<val ab@@c = collection.Map(1 -> 2)>>
|}
|""".stripMargin,
"""
|```scala
|val abc: scala.collection.Map[Int, Int]
|```
|""".stripMargin
)
Expand Up @@ -19,7 +19,7 @@ class InlayHintsSuite extends BaseInlayHintsSuite {
| def foo()/*: Unit<<scala/Unit#>>*/ = {
| implicit val imp: Int = 2
| def addOne(x: Int)(implicit one: Int)/*: Int<<scala/Int#>>*/ = x + one
| val x/*: Int<<scala/Int#>>*/ = addOne(1)/*(imp<<(3:17)>>)*/
| val x/*: Int<<scala/Int#>>*/ = addOne(1)/*(using imp<<(3:17)>>)*/
| }
|}
|""".stripMargin
Expand Down Expand Up @@ -66,7 +66,7 @@ class InlayHintsSuite extends BaseInlayHintsSuite {
|object Main {
| implicit val imp: Int = 2
| def addOne(x: Int)(implicit one: Int)/*: Int<<scala/Int#>>*/ = x + one
| val x/*: Int<<scala/Int#>>*/ = addOne(1)/*(imp<<(3:15)>>)*/
| val x/*: Int<<scala/Int#>>*/ = addOne(1)/*(using imp<<(3:15)>>)*/
|}
|""".stripMargin
)
Expand Down Expand Up @@ -100,7 +100,7 @@ class InlayHintsSuite extends BaseInlayHintsSuite {
|object Main {
| implicit val imp: Int = 2
| def addOne(x: Int)(using one: Int)/*: Int<<scala/Int#>>*/ = x + one
| val x/*: Int<<scala/Int#>>*/ = addOne(1)/*(imp<<(3:15)>>)*/
| val x/*: Int<<scala/Int#>>*/ = addOne(1)/*(using imp<<(3:15)>>)*/
|}
|""".stripMargin
)
Expand Down Expand Up @@ -502,7 +502,7 @@ class InlayHintsSuite extends BaseInlayHintsSuite {
|}
|""".stripMargin,
"""|object Main {
| val ordered/*: String<<scala/Predef.String#>>*/ = /*augmentString<<scala/Predef.augmentString().>>(*/"acb"/*)*/.sorted/*[Char<<scala/Char#>>]*//*(Char<<scala/math/Ordering.Char.>>)*/
| val ordered/*: String<<scala/Predef.String#>>*/ = /*augmentString<<scala/Predef.augmentString().>>(*/"acb"/*)*/.sorted/*[Char<<scala/Char#>>]*//*(using Char<<scala/math/Ordering.Char.>>)*/
|}
|""".stripMargin
)
Expand Down Expand Up @@ -608,18 +608,18 @@ class InlayHintsSuite extends BaseInlayHintsSuite {
|
| /*StringTestOps<<(6:17)>>(*/"foo"/*)*/ should {
| /*StringTestOps<<(6:17)>>(*/"checkThing1"/*)*/ in {
| checkThing1[String]/*(instancesString<<(10:15)>>)*/
| }/*(here<<(5:15)>>)*/
| checkThing1[String]/*(using instancesString<<(10:15)>>)*/
| }/*(using here<<(5:15)>>)*/
| /*StringTestOps<<(6:17)>>(*/"checkThing2"/*)*/ in {
| checkThing2[String]/*(instancesString<<(10:15)>>, instancesString<<(10:15)>>)*/
| }/*(here<<(5:15)>>)*/
| }/*(subjectRegistrationFunction<<(3:15)>>)*/
| checkThing2[String]/*(using instancesString<<(10:15)>>, instancesString<<(10:15)>>)*/
| }/*(using here<<(5:15)>>)*/
| }/*(using subjectRegistrationFunction<<(3:15)>>)*/
|
| /*StringTestOps<<(6:17)>>(*/"bar"/*)*/ should {
| /*StringTestOps<<(6:17)>>(*/"checkThing1"/*)*/ in {
| checkThing1[String]/*(instancesString<<(10:15)>>)*/
| }/*(here<<(5:15)>>)*/
| }/*(subjectRegistrationFunction<<(3:15)>>)*/
| checkThing1[String]/*(using instancesString<<(10:15)>>)*/
| }/*(using here<<(5:15)>>)*/
| }/*(using subjectRegistrationFunction<<(3:15)>>)*/
|
| def checkThing1[A](implicit ev: Eq[A])/*: Nothing<<scala/Nothing#>>*/ = ???
| def checkThing2[A](implicit ev: Eq[A], sem: Semigroup[A])/*: Nothing<<scala/Nothing#>>*/ = ???
Expand Down Expand Up @@ -664,4 +664,105 @@ class InlayHintsSuite extends BaseInlayHintsSuite {
|case class ErrorMessage(error)
|""".stripMargin
)
}

@Test def `anonymous-given` =
check(
"""|package example
|
|trait Ord[T]:
| def compare(x: T, y: T): Int
|
|given intOrd: Ord[Int] with
| def compare(x: Int, y: Int) =
| if x < y then -1 else if x > y then +1 else 0
|
|given Ord[String] with
| def compare(x: String, y: String) =
| x.compare(y)
|
|""".stripMargin,
"""|package example
|
|trait Ord[T]:
| def compare(x: T, y: T): Int
|
|given intOrd: Ord[Int] with
| def compare(x: Int, y: Int)/*: Int<<scala/Int#>>*/ =
| if x < y then -1 else if x > y then +1 else 0
|
|given Ord[String] with
| def compare(x: String, y: String)/*: Int<<scala/Int#>>*/ =
| /*augmentString<<scala/Predef.augmentString().>>(*/x/*)*/.compare(y)
|
|""".stripMargin
)

// TODO: Add a separate option for hints for context bounds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that from original PR? We should remove it here and have na issue for it then

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I just copied it. I'm not even sure what it means. @jkciesluk will you create an issue?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've discussed with @rochala if decorations for evidence parameters are useful and we decided to add a separate option for them. The PR is almost ready, I will create an issue for it too.

@Test def `context-bounds1` =
check(
"""|package example
|object O {
| given Int = 1
| def test[T: Ordering](x: T)(using Int) = ???
| test(1)
|}
|""".stripMargin,
"""|package example
|object O {
| given Int = 1
| def test[T: Ordering](x: T)(using Int)/*: Nothing<<scala/Nothing#>>*/ = ???
| test/*[Int<<scala/Int#>>]*/(1)/*(using Int<<scala/math/Ordering.Int.>>, given_Int<<(2:8)>>)*/
|}
|""".stripMargin
)

@Test def `context-bounds2` =
check(
"""|package example
|object O {
| def test[T: Ordering](x: T) = ???
| test(1)
|}
|""".stripMargin,
"""|package example
|object O {
| def test[T: Ordering](x: T)/*: Nothing<<scala/Nothing#>>*/ = ???
| test/*[Int<<scala/Int#>>]*/(1)/*(using Int<<scala/math/Ordering.Int.>>)*/
|}
|""".stripMargin
)

@Test def `context-bounds3` =
check(
"""|package example
|object O {
| def test[T: Ordering](x: T)(using Int) = ???
| test(1)
|}
|""".stripMargin,
"""|package example
|object O {
| def test[T: Ordering](x: T)(using Int)/*: Nothing<<scala/Nothing#>>*/ = ???
| test/*[Int<<scala/Int#>>]*/(1)/*(using Int<<scala/math/Ordering.Int.>>)*/
|}
|""".stripMargin
)

@Test def `context-bounds4` =
check(
"""|package example
|object O {
| implicit val i: Int = 123
| def test[T: Ordering](x: T)(implicit v: Int) = ???
| test(1)
|}
|""".stripMargin,
"""|package example
|object O {
| implicit val i: Int = 123
| def test[T: Ordering](x: T)(implicit v: Int)/*: Nothing<<scala/Nothing#>>*/ = ???
| test/*[Int<<scala/Int#>>]*/(1)/*(using Int<<scala/math/Ordering.Int.>>, i<<(2:15)>>)*/
|}
|""".stripMargin
)
}