Skip to content

Commit

Permalink
review fixes + add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Mar 8, 2024
1 parent f6e9690 commit 2837297
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,13 @@ import dotty.tools.dotc.core.StdNames.nme
import dotty.tools.dotc.core.Symbols.*
import dotty.tools.pc.utils.MtagsEnrichments.metalsDealias
import dotty.tools.pc.SemanticdbSymbols
import dotty.tools.pc.utils.MtagsEnrichments.allSymbols

class SymbolInformationProvider(using Context):
private def toSymbols(
pkg: String,
parts: List[(String, Boolean)],
): List[Symbol] =
def collectSymbols(denotation: Denotation): List[Symbol] =
denotation match
case MultiDenotation(denot1, denot2) =>
collectSymbols(denot1) ++ collectSymbols(denot2)
case denot => List(denot.symbol)

def loop(
owners: List[Symbol],
parts: List[(String, Boolean)],
Expand All @@ -37,7 +32,7 @@ class SymbolInformationProvider(using Context):
val next =
if isClass then owner.info.member(typeName(head))
else owner.info.member(termName(head))
collectSymbols(next).filter(_.exists)
next.allSymbols
}
if foundSymbols.nonEmpty then loop(foundSymbols, tl)
else Nil
Expand Down Expand Up @@ -70,9 +65,8 @@ class SymbolInformationProvider(using Context):
catch case NonFatal(e) => Nil

val (searchedSymbol, alternativeSymbols) =
foundSymbols.partition(compilerSymbol =>
foundSymbols.partition: compilerSymbol =>
SemanticdbSymbols.symbolName(compilerSymbol) == symbol
)

searchedSymbol match
case Nil => None
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package dotty.tools.pc.tests.info

import scala.meta.internal.jdk.CollectionConverters._
import scala.meta.pc.PcSymbolKind
import scala.meta.pc.PcSymbolProperty

import scala.meta.pc.PcSymbolInformation
import dotty.tools.pc.base.BasePCSuite
import scala.language.unsafeNulls
import org.junit.Test

class InfoSuite extends BasePCSuite {

def getInfo(symbol: String): PcSymbolInformation = {
val result = presentationCompiler.info(symbol).get()
assertEquals(true, result.isPresent(), s"no info returned for symbol $symbol")
assertNoDiff(result.get().symbol(), symbol)
result.get()
}

@Test def `list` =
val info = getInfo("scala/collection/immutable/List#")
assertEquals(true, info.properties().contains(PcSymbolProperty.ABSTRACT), s"class List should be abstract")
assertEquals(
true,
info.parents().contains("scala/collection/immutable/LinearSeq#"),
"class List should extend LinearSeq"
)

@Test def `empty-list-constructor` =
val info = getInfo("scala/collection/immutable/List.empty().")
assertNoDiff(info.classOwner(), "scala/collection/immutable/List.")
assertEquals(info.kind(), PcSymbolKind.METHOD, "List.empty() should be a method")

@Test def `assert` =
val info = getInfo("scala/Predef.assert().")
assertEquals(info.kind(), PcSymbolKind.METHOD, "assert() should be a method")
assertNoDiff(info.classOwner(), "scala/Predef.")
assertEquals(
info.alternativeSymbols().asScala.mkString("\n"),
"scala/Predef.assert(+1).",
"there should be a single alternative symbol to assert()"
)

@Test def `flatMap` =
val info = getInfo("scala/collection/immutable/List#flatMap().")
assertEquals(info.kind(), PcSymbolKind.METHOD, "List.flatMap() should be a method")
assertNoDiff(info.classOwner(), "scala/collection/immutable/List#")
assertNoDiff(
info.overriddenSymbols().asScala.mkString("\n"),
"""|scala/collection/StrictOptimizedIterableOps#flatMap().
|scala/collection/IterableOps#flatMap().
|scala/collection/IterableOnceOps#flatMap().
|""".stripMargin
)
}

0 comments on commit 2837297

Please sign in to comment.