From 0437a14443f9356aceab85721fef4bd455b30155 Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Mon, 4 Mar 2024 15:27:08 +0100 Subject: [PATCH] tests: add tests for pc `info` --- .../ScalaPresentationCompiler.scala | 6 ++ .../src/test/scala/tests/pc/InfoSuite.scala | 62 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/cross/src/test/scala/tests/pc/InfoSuite.scala diff --git a/mtags/src/main/scala-3-wrapper/ScalaPresentationCompiler.scala b/mtags/src/main/scala-3-wrapper/ScalaPresentationCompiler.scala index 51eac872a8b..afd6dead724 100644 --- a/mtags/src/main/scala-3-wrapper/ScalaPresentationCompiler.scala +++ b/mtags/src/main/scala-3-wrapper/ScalaPresentationCompiler.scala @@ -18,6 +18,7 @@ import scala.meta.pc.HoverSignature import scala.meta.pc.InlayHintsParams import scala.meta.pc.Node import scala.meta.pc.OffsetParams +import scala.meta.pc.PcSymbolInformation import scala.meta.pc.PresentationCompiler import scala.meta.pc.PresentationCompilerConfig import scala.meta.pc.RangeParams @@ -110,6 +111,11 @@ case class ScalaPresentationCompiler( ): CompletableFuture[ju.Optional[HoverSignature]] = underlying.hover(params) + override def info( + symbol: String + ): CompletableFuture[ju.Optional[PcSymbolInformation]] = + underlying.info(symbol) + override def convertToNamedArguments( params: OffsetParams, argIndices: ju.List[Integer], diff --git a/tests/cross/src/test/scala/tests/pc/InfoSuite.scala b/tests/cross/src/test/scala/tests/pc/InfoSuite.scala new file mode 100644 index 00000000000..633cdbcaa9f --- /dev/null +++ b/tests/cross/src/test/scala/tests/pc/InfoSuite.scala @@ -0,0 +1,62 @@ +package tests.pc + +import scala.meta.internal.jdk.CollectionConverters._ +import scala.meta.pc.PcSymbolInformation +import scala.meta.pc.PcSymbolKind +import scala.meta.pc.PcSymbolProperty + +import tests.BasePCSuite + +class InfoSuite extends BasePCSuite { + + def getInfo(symbol: String): PcSymbolInformation = { + val result = presentationCompiler.info(symbol).get() + assert(result.isPresent(), s"no info returned for symbol $symbol") + assertNoDiff(result.get().symbol(), symbol) + result.get() + } + + test("list") { + val info = getInfo("scala/collection/immutable/List#") + assert(info.properties().contains(PcSymbolProperty.ABSTRACT)) + assert(info.parents().contains("scala/collection/immutable/LinearSeq#")) + } + + test("empty-list-constructor") { + val info = getInfo("scala/collection/immutable/List.empty().") + assertNoDiff(info.classOwner(), "scala/collection/immutable/List.") + assertEquals(info.kind(), PcSymbolKind.METHOD) + } + + test("assert") { + val info = getInfo("scala/Predef.assert().") + assertEquals(info.kind(), PcSymbolKind.METHOD) + assertNoDiff(info.classOwner(), "scala/Predef.") + assertEquals( + info.alternativeSymbols().asScala.mkString("\n"), + "scala/Predef.assert(+1)." + ) + } + + test("flatMap") { + val info = getInfo("scala/collection/immutable/List#flatMap().") + assertEquals(info.kind(), PcSymbolKind.METHOD) + assertNoDiff(info.classOwner(), "scala/collection/immutable/List#") + val correctOverridden = + if (scalaVersion.startsWith("2.12") || scalaVersion.startsWith("2.11")) { + """|scala/collection/TraversableLike#flatMap(). + |scala/collection/GenTraversableLike#flatMap(). + |scala/collection/generic/FilterMonadic#flatMap(). + |""".stripMargin + } else { + """|scala/collection/StrictOptimizedIterableOps#flatMap(). + |scala/collection/IterableOps#flatMap(). + |scala/collection/IterableOnceOps#flatMap(). + |""".stripMargin + } + assertNoDiff( + info.overriddenSymbols().asScala.mkString("\n"), + correctOverridden + ) + } +}