-
Notifications
You must be signed in to change notification settings - Fork 333
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
fix: show zero extent references when using pc #6583
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package tests.pc | ||
|
||
import java.net.URI | ||
|
||
import scala.meta.internal.jdk.CollectionConverters._ | ||
import scala.meta.internal.metals.CompilerVirtualFileParams | ||
import scala.meta.internal.metals.EmptyCancelToken | ||
import scala.meta.internal.pc.PcReferencesRequest | ||
|
||
import munit.Location | ||
import munit.TestOptions | ||
import org.eclipse.lsp4j.jsonrpc.messages.{Either => JEither} | ||
import tests.BasePCSuite | ||
import tests.RangeReplace | ||
|
||
class PcReferencesSuite extends BasePCSuite with RangeReplace { | ||
def check( | ||
name: TestOptions, | ||
original: String, | ||
compat: Map[String, String] = Map.empty | ||
)(implicit location: Location): Unit = | ||
test(name) { | ||
val edit = original.replaceAll("(<<|>>)", "") | ||
val expected = original.replaceAll("@@", "") | ||
val base = original.replaceAll("(<<|>>|@@)", "") | ||
|
||
val (code, offset) = params(edit, "Highlight.scala") | ||
val ranges = presentationCompiler | ||
.references( | ||
PcReferencesRequest( | ||
CompilerVirtualFileParams( | ||
URI.create("file:/Highlight.scala"), | ||
code, | ||
EmptyCancelToken | ||
), | ||
includeDefinition = false, | ||
offsetOrSymbol = JEither.forLeft(offset) | ||
) | ||
) | ||
.get() | ||
.asScala | ||
.flatMap(_.locations().asScala.map(_.getRange())) | ||
.toList | ||
|
||
assertEquals( | ||
renderRangesAsString(base, ranges), | ||
getExpected(expected, compat, scalaVersion) | ||
) | ||
} | ||
|
||
check( | ||
"implicit-args", | ||
"""|package example | ||
| | ||
|class Bar(i: Int) | ||
| | ||
|object Hello { | ||
| def m(i: Int)(implicit b: Bar) = ??? | ||
| val foo = { | ||
| implicit val b@@arr: Bar = new Bar(1) | ||
| m<<>>(3) | ||
| } | ||
|} | ||
|""".stripMargin, | ||
compat = Map("3" -> """|package example | ||
| | ||
|class Bar(i: Int) | ||
| | ||
|object Hello { | ||
| def m(i: Int)(implicit b: Bar) = ??? | ||
| val foo = { | ||
| implicit val barr: Bar = new Bar(1) | ||
| m(3)<<>> | ||
| } | ||
|} | ||
|""".stripMargin) | ||
) | ||
|
||
check( | ||
"implicit-args-2", | ||
"""|package example | ||
| | ||
|class Bar(i: Int) | ||
|class Foo(implicit b: Bar) | ||
| | ||
|object Hello { | ||
| implicit val b@@arr: Bar = new Bar(1) | ||
| val foo = <<>>new Foo | ||
|} | ||
|""".stripMargin, | ||
compat = Map( | ||
"3" -> """|package example | ||
| | ||
|class Bar(i: Int) | ||
|class Foo(implicit b: Bar) | ||
| | ||
|object Hello { | ||
| implicit val barr: Bar = new Bar(1) | ||
| val foo = new Foo<<>> | ||
|} | ||
|""".stripMargin | ||
) | ||
) | ||
|
||
// for Scala 3 the symbol in bar reference is missing (<none>) | ||
check( | ||
"implicit-args-3".tag(IgnoreScala3), | ||
"""|package example | ||
| | ||
|class Bar(i: Int) | ||
|class Foo(implicit b: Bar) | ||
| | ||
|object Hello { | ||
| implicit val b@@arr = new Bar(1) | ||
| for { | ||
| _ <- Some(1) | ||
| foo = <<>>new Foo() | ||
| } yield () | ||
|} | ||
|""".stripMargin | ||
) | ||
|
||
check( | ||
"case-class", | ||
"""|case class Ma@@in(i: Int) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why add these two tests with no usages? Is this on puspose? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initially I added all zero-extent symbols, not only implicits, so it showed some additional refs in those tests, that shouldn't be there. |
||
|""".stripMargin | ||
) | ||
|
||
check( | ||
"case-class-with-implicit", | ||
""""|case class A()(implicit val fo@@o: Int) | ||
|""".stripMargin | ||
) | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we reprort an issue upstrem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't compile for Scala 3. I think I confused myself by a combination of VirtusLab/scala-cli#2638 and VirtusLab/scala-cli#2226 (or something similar) 😂