Skip to content

Commit

Permalink
FormatOps: refactor skipInfixIndent
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jan 27, 2022
1 parent d24becf commit 7044913
Showing 1 changed file with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -567,26 +567,27 @@ class FormatOps(
}

private val skipInfixIndent: Boolean = {
val isTopLevel = {
@tailrec
def getLastPat(t: Pat): Tree =
t.parent match {
case Some(p: Pat) => getLastPat(p)
case _ => t
}
val child = fullInfix.all match {
case t: Pat => getLastPat(t)
case t => t
}
child.parent.collect {
case _: Term.Block | _: Term.If | _: Term.While | _: Source => true
case fun: Term.FunctionTerm if isBlockFunction(fun) => true
case t: Case => t.pat.eq(child) || t.body.eq(child)
@tailrec
def getLastPat(t: Pat): Tree =
t.parent match {
case Some(p: Pat) => getLastPat(p)
case _ => t
}
def getChild = fullInfix.all match {
case t: Pat => getLastPat(t)
case t => t
}
def isOldTopLevel(child: Tree) = child.parent.exists {
case _: Term.Block | _: Term.If | _: Term.While | _: Source => true
case fun: Term.FunctionTerm if isBlockFunction(fun) => true
case t: Case => t.pat.eq(child) || t.body.eq(child)
case _ => false
}
val allowNoIndent =
!style.indentOperator.topLevelOnly || isOldTopLevel(getChild)
def isInfixTopLevelMatch(op: String, noindent: Boolean): Boolean = {
noindent == style.indentOperator.noindent(op) &&
noindent == isTopLevel.getOrElse(!style.indentOperator.topLevelOnly)
noindent == allowNoIndent
}
if (style.verticalAlignMultilineOperators)
!InfixApp.isAssignment(ft.meta.left.text)
Expand Down

0 comments on commit 7044913

Please sign in to comment.