Skip to content

Commit

Permalink
FormatOps: use getLastTokenOpt, add getHeadToken
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jul 6, 2023
1 parent 39249ab commit a06d22c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ class FormatOps(
) {
forces += hash(open)
args.foreach { arg =>
clearQueues += hash(tokens.getHead(arg).left)
clearQueues += hash(getHeadToken(arg))
}
}
tokens.foreach {
Expand Down Expand Up @@ -1521,7 +1521,7 @@ class FormatOps(
def checkParent = thisTree.parent match {
case `nextSelect` => style.includeNoParensInSelectChains
case Some(p: Term.Apply)
if tokens.getHead(p.argClause).left.is[T.LeftBrace] =>
if getHeadToken(p.argClause).is[T.LeftBrace] =>
style.includeCurlyBraceInSelectChains &&
!nextSelect.contains(lastApply) // exclude short curly
case Some(p: Member.Apply) => p.fun eq thisTree
Expand Down Expand Up @@ -2512,7 +2512,7 @@ class FormatOps(
@tailrec
private def isElsePWithOptionalBraces(tree: Term.If): Boolean = {
val elsep = tree.elsep
!tokens.getHead(elsep).left.is[T.LeftBrace] && (elsep match {
!getHeadToken(elsep).is[T.LeftBrace] && (elsep match {
case t: Term.If =>
isThenPWithOptionalBraces(t) ||
!ifWithoutElse(t) && isElsePWithOptionalBraces(t)
Expand Down Expand Up @@ -2545,7 +2545,7 @@ class FormatOps(
}

@inline private def treeLast(tree: Tree): Option[T] =
tokens.getLastOpt(tree).map(_.left)
getLastTokenOpt(tree)
@inline private def blockLast(tree: Tree): Option[T] =
if (isTreeMultiStatBlock(tree)) treeLast(tree) else None
@inline private def blockLast(tree: Term.Block): Option[T] =
Expand Down Expand Up @@ -2753,6 +2753,9 @@ class FormatOps(
case _ => other
}

def getHeadToken(tree: Tree): T =
tokens.getHead(tree).left

def getLastToken(tree: Tree): T =
tokens.getLast(tree).left

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ class Router(formatOps: FormatOps) {
)
}
val argsOpt = if (isAlignFirstParen) lastSyntaxClause else None
argsOpt.flatMap(tokens.getLastOpt).map(_.left).fold(splits) { x =>
argsOpt.flatMap(getLastTokenOpt).fold(splits) { x =>
val noSplitIndents = Seq(
Indent(StateColumn, x, ExpiresOn.Before),
Indent(-indentLen, x, ExpiresOn.Before)
Expand Down

0 comments on commit a06d22c

Please sign in to comment.