Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Sep 15, 2023
1 parent d37abbf commit 7b716d1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,11 @@ final class ImplementationProvider(
overriddenInfo: List[
(AbsolutePath, List[(String, List[OverriddenSymbol])])
]
): Unit = {
overriddenInfo.foreach { case (path, list) =>
list.foreach { case (overridesSymbol, overridden) =>
overridden.foreach(addTypeHierarchyElement(path, overridesSymbol, _))
}
}
}
): Unit = for {
(path, list) <- overriddenInfo
(overridesSymbol, overriddenSymbols) <- list
overridden <- overriddenSymbols
} addTypeHierarchyElement(path, overridesSymbol, overridden)

def addTypeHierarchyElements(
elements: List[(AbsolutePath, String, OverriddenSymbol)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class GlobalInheritanceContext(
symbol: String
)(implicit ec: ExecutionContext): Future[Set[ClassLocation]] = {
val workspaceImplementations = getWorkspaceLocations(symbol)
// for enum class we resolve all cases as implementations while indexing
val enumCasesImplementations =
implementationsInDependencySources.getOrElse(symbol, Set.empty)
val shortName = symbol.desc.name.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ class ScalaToplevelMtags(
nextExpectTemplate
)
case EXTENDS =>
val (overridden, maybeNewIdent) = findOverridden(List.empty)
val (overridden, maybeNewIndent) = findOverridden(List.empty)
expectTemplate.map(tmpl =>
withOwner(tmpl.owner) {
addOverridden(
Expand All @@ -428,8 +428,8 @@ class ScalaToplevelMtags(
}
)
loop(
maybeNewIdent.getOrElse(indent),
isAfterNewline = maybeNewIdent.isDefined,
maybeNewIndent.getOrElse(indent),
isAfterNewline = maybeNewIndent.isDefined,
currRegion,
expectTemplate
)
Expand Down Expand Up @@ -515,15 +515,15 @@ class ScalaToplevelMtags(

@tailrec
private def acceptAllAfterOverriddenIdentifier(): Option[Int] = {
val maybeNewIdent = acceptTrivia()
val maybeNewIndent = acceptTrivia()
scanner.curr.token match {
case LPAREN =>
acceptBalancedDelimeters(LPAREN, RPAREN)
acceptAllAfterOverriddenIdentifier()
case LBRACKET =>
acceptBalancedDelimeters(LBRACKET, RBRACKET)
acceptAllAfterOverriddenIdentifier()
case _ => maybeNewIdent
case _ => maybeNewIndent
}

}
Expand All @@ -532,34 +532,35 @@ class ScalaToplevelMtags(
private def findOverridden(
acc0: List[Identifier]
): (List[Identifier], Option[Int]) = {
val maybeNewIdent0 = acceptTrivia()
val maybeNewIndent0 = acceptTrivia()
scanner.curr.token match {
case IDENTIFIER =>
@tailrec
def getIdentifier(): (Option[Identifier], Option[Int]) = {
val currentIdentifier = newIdentifier
val maybeNewIdent = acceptAllAfterOverriddenIdentifier()
val maybeNewIndent = acceptAllAfterOverriddenIdentifier()
scanner.curr.token match {
case DOT =>
scanner.nextToken()
getIdentifier()
case _ => (currentIdentifier, maybeNewIdent)
case _ => (currentIdentifier, maybeNewIndent)
}
}
val (identifier, maybeNewIdent) = getIdentifier()
val (identifier, maybeNewIndent) = getIdentifier()
val acc = identifier.toList ++ acc0
scanner.curr.token match {
case WITH => findOverridden(acc)
case _ => (acc, maybeNewIdent)
case COMMA => findOverridden(acc)
case _ => (acc, maybeNewIndent)
}
case LBRACE =>
acceptBalancedDelimeters(LBRACE, RBRACE)
val maybeNewIdent = acceptTrivia()
val maybeNewIndent = acceptTrivia()
scanner.curr.token match {
case WITH => findOverridden(acc0)
case _ => (acc0, maybeNewIdent)
case _ => (acc0, maybeNewIndent)
}
case _ => (acc0, maybeNewIdent0)
case _ => (acc0, maybeNewIndent0)
}
}

Expand Down Expand Up @@ -754,7 +755,7 @@ class ScalaToplevelMtags(

private def acceptTrivia(): Option[Int] = {
var includedNewline = false
var ident = 0
var indent = 0
scanner.nextToken()
while (
!isDone &&
Expand All @@ -765,13 +766,13 @@ class ScalaToplevelMtags(
) {
if (isNewline) {
includedNewline = true
ident = 0
indent = 0
} else if (scanner.curr.token == WHITESPACE) {
ident += 1
indent += 1
}
scanner.nextToken()
}
if (includedNewline) Some(ident) else None
if (includedNewline) Some(indent) else None
}

private def nextIsNL(): Boolean = {
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/src/test/scala/tests/ScalaToplevelSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,15 @@ class ScalaToplevelSuite extends BaseSuite {
mode = All,
)

check(
"overridden3",
"""|package a
|class A extends B, C
|""".stripMargin,
List("a/", "a/A# -> B, C"),
mode = All,
)

def check(
options: TestOptions,
code: String,
Expand Down

0 comments on commit 7b716d1

Please sign in to comment.