Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Jan 16, 2024
1 parent 1d86b8e commit 688e897
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ final class ImplementationProvider(
trees: Trees,
scalaVersionSelector: ScalaVersionSelector,
compilers: Compilers,
buildTargets: BuildTargets
buildTargets: BuildTargets,
)(implicit ec: ExecutionContext, rc: ReportContext)
extends SemanticdbFeatureProvider {
import ImplementationProvider._
Expand Down Expand Up @@ -259,13 +259,13 @@ final class ImplementationProvider(
locationsByFile: Map[Path, Set[ClassLocation]],
parentSymbol: PcSymbolInformation,
classSymbol: String,
buildTarget: BuildTargetIdentifier
buildTarget: BuildTargetIdentifier,
) = Future.sequence({
for {
file <- files
locations = locationsByFile(file)
implPath = AbsolutePath(file)
if(buildTargets.belongsToBuildTarget(buildTarget, implPath))
if (buildTargets.belongsToBuildTarget(buildTarget, implPath))
implDocument <- findSemanticdb(implPath).toList
} yield {
for {
Expand Down Expand Up @@ -333,7 +333,7 @@ final class ImplementationProvider(
locationsByFile,
symbolInfo,
symbolClass,
target
target,
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ class InheritanceContext(inheritance: Map[String, Set[ClassLocation]]) {
def toGlobal(
compilers: Compilers,
implementationsInDependencySources: Map[String, Set[ClassLocation]],
source: AbsolutePath
source: AbsolutePath,
) = new GlobalInheritanceContext(
compilers,
implementationsInDependencySources,
inheritance,
source
source,
)
}

class GlobalInheritanceContext(
compilers: Compilers,
implementationsInDependencySources: Map[String, Set[ClassLocation]],
localInheritance: Map[String, Set[ClassLocation]],
source: AbsolutePath
source: AbsolutePath,
) extends InheritanceContext(localInheritance) {
override def getLocations(
symbol: String
Expand All @@ -52,9 +52,11 @@ class GlobalInheritanceContext(
implementationsInDependencySources
.getOrElse(shortName, Set.empty)
.collect { case loc @ ClassLocation(sym, _) =>
compilers.info(source, sym).map {
compilers.info(source, sym).map {
case Some(symInfo) if symInfo.parents.contains(symbol) => Some(loc)
case Some(symInfo) if symInfo.dealisedSymbol == symbol && symInfo.symbol != symbol => Some(loc)
case Some(symInfo)
if symInfo.dealisedSymbol == symbol && symInfo.symbol != symbol =>
Some(loc)
case _ => None
}
}
Expand All @@ -68,7 +70,9 @@ class GlobalInheritanceContext(

object InheritanceContext {

def fromDefinitions(localDefinitions: Map[Path, Map[String, Set[ClassLocation]]]): InheritanceContext = {
def fromDefinitions(
localDefinitions: Map[Path, Map[String, Set[ClassLocation]]]
): InheritanceContext = {
val inheritance = mutable.Map
.empty[String, Set[ClassLocation]]
for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,11 @@ final class BuildTargets private (
}

def belongsToBuildTarget(
target: BuildTargetIdentifier,
path: AbsolutePath
target: BuildTargetIdentifier,
path: AbsolutePath,
): Boolean = {
val possibleBuildTargets = target :: buildTargetTransitiveDependencies(target).toList
val possibleBuildTargets =
target :: buildTargetTransitiveDependencies(target).toList
inverseSourcesAll(path).exists(possibleBuildTargets.contains)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,14 +790,18 @@ class Compilers(
symbol: String,
): Future[Seq[PcSymbolInformation]] = {
loadCompiler(path)
.map(_.info(symbol).asScala.map(_.asScala.toSeq.map(PcSymbolInformation.from)))
.map(
_.info(symbol).asScala
.map(_.asScala.toSeq.map(PcSymbolInformation.from))
)
.getOrElse(Future(Nil))
}

def info(
path: AbsolutePath,
symbol: String,
): Future[Option[PcSymbolInformation]] = infoAll(path, symbol).map(_.find(_.symbol == symbol))
): Future[Option[PcSymbolInformation]] =
infoAll(path, symbol).map(_.find(_.symbol == symbol))

private def definition(
params: TextDocumentPositionParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ class MetalsLspService(
trees,
scalaVersionSelector,
compilers,
buildTargets
buildTargets,
)

private val symbolHierarchyOps: SymbolHierarchyOps =
Expand All @@ -666,7 +666,7 @@ class MetalsLspService(
definitionIndex,
scalaVersionSelector,
buffers,
trees
trees,
)

private val supermethods: Supermethods = new Supermethods(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class SymbolHierarchyOps(
parentDoc,
symbol,
source,
scalaVersionSelector
scalaVersionSelector,
)
range <- implOccurrence.range
distance = buffer.tokenEditDistance(
Expand Down Expand Up @@ -210,7 +210,7 @@ object SymbolHierarchyOps {
semanticDb: TextDocument,
symbol: String,
source: AbsolutePath,
scalaVersionSelector: ScalaVersionSelector
scalaVersionSelector: ScalaVersionSelector,
): Option[SymbolOccurrence] = {
def isDefinitionOccurrence(occ: SymbolOccurrence) =
occ.role.isDefinition && occ.symbol == symbol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ class StdReporter(

optDuplicate.orElse {
Try {
path.createDirectories()
path.writeText(sanitize(report.fullText(withIdAndSummary = true)))
path
path.createDirectories()
path.writeText(sanitize(report.fullText(withIdAndSummary = true)))
path
}.toOption
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ case class PcSymbolInformation(
}

object PcSymbolInformation {
def from(info: IPcSymbolInformation): PcSymbolInformation =
def from(info: IPcSymbolInformation): PcSymbolInformation =
PcSymbolInformation(
info.symbol(),
Try(PcSymbolKind.withName(info.kindString())).getOrElse(PcSymbolKind.UNKNOWN_KIND),
Try(PcSymbolKind.withName(info.kindString()))
.getOrElse(PcSymbolKind.UNKNOWN_KIND),
info.parentsList().asScala.toList,
info.dealisedSymbol(),
if(info.classOwnerString().nonEmpty) Some(info.classOwnerString()) else None,
if (info.classOwnerString().nonEmpty) Some(info.classOwnerString())
else None,
info.overriddenList().asScala.toList,
info.propertiesList().asScala.toList.flatMap(name => Try(PcSymbolProperty.withName(name)).toOption)
info
.propertiesList()
.asScala
.toList
.flatMap(name => Try(PcSymbolProperty.withName(name)).toOption)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ trait WorkspaceSymbolSearch { this: MetalsGlobal =>
val rest = symbol.drop(newSymbol.size)
loop(rest.drop(1), (newSymbol, rest.headOption.exists(_ == '#')) :: acc)
}

val names =
loop(symbol.drop(index + 1).takeWhile(_ != '('), List.empty)
val compilerSymbols = names.foldLeft(List(pkg)) { case (owners, (name, isClass)) =>
owners.flatMap{ owner =>
val compilerSymbols = names.foldLeft(List(pkg)) {
case (owners, (name, isClass)) =>
owners.flatMap { owner =>
val foundChild =
if (isClass) owner.info.member(TypeName(name))
else owner.info.member(TermName(name))
Expand All @@ -48,16 +49,21 @@ trait WorkspaceSymbolSearch { this: MetalsGlobal =>
kind = getSymbolKind(compilerSymbol),
parents = compilerSymbol.parentSymbols.map(semanticdbSymbol),
dealisedSymbol = semanticdbSymbol(compilerSymbol.dealiased),
classOwner = compilerSymbol.ownerChain.find(c => c.isClass || c.isModule).map(semanticdbSymbol),
classOwner = compilerSymbol.ownerChain
.find(c => c.isClass || c.isModule)
.map(semanticdbSymbol),
overridden = compilerSymbol.overrides.map(semanticdbSymbol),
properties = if(compilerSymbol.isAbstractClass || compilerSymbol.isAbstractType) List(PcSymbolProperty.ABSTRACT) else Nil
properties =
if (compilerSymbol.isAbstractClass || compilerSymbol.isAbstractType)
List(PcSymbolProperty.ABSTRACT)
else Nil
)
)
}

private def getSymbolKind(sym: Symbol): PcSymbolKind.PcSymbolKind =
if(sym.isJavaInterface) PcSymbolKind.INTERFACE
else if(sym.isTrait) PcSymbolKind.TRAIT
if (sym.isJavaInterface) PcSymbolKind.INTERFACE
else if (sym.isTrait) PcSymbolKind.TRAIT
else if (sym.isConstructor) PcSymbolKind.CONSTRUCTOR
else if (sym.isPackageObject) PcSymbolKind.PACKAGE_OBJECT
else if (sym.isClass) PcSymbolKind.CLASS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ trait Completions { this: MetalsGlobal =>

val packageSymbols: mutable.Map[String, Option[Symbol]] =
mutable.Map.empty[String, Option[Symbol]]
def packageSymbolFromString(symbol: String): Option[Symbol] =
if(symbol == "_empty_/") Some(rootMirror.EmptyPackage)
def packageSymbolFromString(symbol: String): Option[Symbol] =
if (symbol == "_empty_/") Some(rootMirror.EmptyPackage)
else {
packageSymbols.getOrElseUpdate(
symbol, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import scala.meta.internal.mtags.BuildInfo
import scala.meta.internal.pc.completions.CompletionProvider
import scala.meta.internal.pc.completions.OverrideCompletions
import scala.meta.pc.*
import scala.meta.pc.{PcSymbolInformation => IPcSymbolInformation}
import scala.meta.pc.{PcSymbolInformation as IPcSymbolInformation}

import dotty.tools.dotc.reporting.StoreReporter
import org.eclipse.lsp4j.DocumentHighlight
Expand Down Expand Up @@ -181,11 +181,15 @@ case class ScalaPresentationCompiler(
override def info(
symbol: String
): CompletableFuture[ju.List[IPcSymbolInformation]] =
compilerAccess.withNonInterruptableCompiler[ju.List[IPcSymbolInformation]](None)(
compilerAccess.withNonInterruptableCompiler[ju.List[IPcSymbolInformation]](
None
)(
Nil.asJava,
EmptyCancelToken
EmptyCancelToken,
) { access =>
SymbolInformationProvider(using access.compiler().currentCtx).info(symbol).asJava
SymbolInformationProvider(using access.compiler().currentCtx)
.info(symbol)
.asJava
}

def semanticdbTextDocument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ class SymbolInformationProvider(using Context):
): List[Symbol] =
def collectSymbols(denotation: Denotation): List[Symbol] =
denotation match
case MultiDenotation(denot1, denot2) => collectSymbols(denot1) ++ collectSymbols(denot2)
case MultiDenotation(denot1, denot2) =>
collectSymbols(denot1) ++ collectSymbols(denot2)
case denot => List(denot.symbol)

def loop(owners: List[Symbol], parts: List[(String, Boolean)]): List[Symbol] =

def loop(
owners: List[Symbol],
parts: List[(String, Boolean)],
): List[Symbol] =
parts match
case (head, isClass) :: tl =>
val foundSymbols =
val foundSymbols =
owners.flatMap { owner =>
val next =
if isClass then owner.info.member(typeName(head))
Expand Down Expand Up @@ -60,21 +64,22 @@ class SymbolInformationProvider(using Context):

val foundSymbols =
try toSymbols(pkg, names)
catch case NonFatal(e) =>
pprint.log(e)
Nil
catch
case NonFatal(e) =>
pprint.log(e)
Nil

for
sym <- foundSymbols
yield {
for sym <- foundSymbols
yield
val classSym = if sym.isClass then sym else sym.moduleClass
val parents =
if(classSym.isClass)
if classSym.isClass
then classSym.asClass.parentSyms.map(SemanticdbSymbols.symbolName)
else Nil
val dealisedSymbol =
if(sym.isAliasType) sym.info.metalsDealias.typeSymbol else sym
val classOwner = sym.ownersIterator.drop(1).find(s => s.isClass || s.is(Flags.Module))
val dealisedSymbol =
if sym.isAliasType then sym.info.metalsDealias.typeSymbol else sym
val classOwner =
sym.ownersIterator.drop(1).find(s => s.isClass || s.is(Flags.Module))
val overridden = sym.denot.allOverriddenSymbols.toList

PcSymbolInformation(
Expand All @@ -84,9 +89,11 @@ class SymbolInformationProvider(using Context):
dealisedSymbol = SemanticdbSymbols.symbolName(dealisedSymbol),
classOwner = classOwner.map(SemanticdbSymbols.symbolName),
overridden = overridden.map(SemanticdbSymbols.symbolName),
properties = if sym.is(Flags.Abstract) then List(PcSymbolProperty.ABSTRACT) else Nil
properties =
if sym.is(Flags.Abstract) then List(PcSymbolProperty.ABSTRACT)
else Nil,
)
}
end for
end info

private def getSymbolKind(sym: Symbol): PcSymbolKind.PcSymbolKind =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,10 @@ class ScalaToplevelMtags(
}
nextIsNL()
@tailrec
def loop(name: Option[String], isAfterEq: Boolean = false): Option[String] = {
def loop(
name: Option[String],
isAfterEq: Boolean = false
): Option[String] = {
scanner.curr.token match {
case SEMI => name
case _ if isNewline | isDone => name
Expand All @@ -690,7 +693,8 @@ class ScalaToplevelMtags(
acceptBalancedDelimeters(LBRACE, RBRACE)
scanner.nextToken()
loop(name, isAfterEq)
case IDENTIFIER if isAfterEq && scanner.curr.name != "|" && scanner.curr.name != "&" =>
case IDENTIFIER
if isAfterEq && scanner.curr.name != "|" && scanner.curr.name != "&" =>
val optName = selectName()
loop(optName, isAfterEq)
case _ if isAfterEq => None
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/src/main/scala/tests/BaseRangesSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import scala.concurrent.Future
import munit.Location
import munit.TestOptions


abstract class BaseRangesSuite(name: String) extends BaseLspSuite(name) {

protected def libraryDependencies: List[String] = Nil
Expand All @@ -22,7 +21,7 @@ abstract class BaseRangesSuite(name: String) extends BaseLspSuite(name) {
input: String,
scalaVersion: Option[String] = None,
additionalLibraryDependencies: List[String] = Nil,
scalacOptions: List[String] = Nil
scalacOptions: List[String] = Nil,
)(implicit
loc: Location
): Unit = {
Expand Down
Loading

0 comments on commit 688e897

Please sign in to comment.