Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormatOps: support ContextArrow in getFuncArrow #4599

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1241,19 +1241,19 @@ class FormatOps(
// look for arrow before body, if any, else after params
def getFuncArrow(term: Term.FunctionTerm): Option[FT] = tokens
.tokenBeforeOpt(term.body)
.orElse(tokenAfterOpt(term.paramClause).map(getArrowAfter))
.orElse(tokenAfterOpt(term.paramClause).map(getArrowAfter[T.FunctionArrow]))

// look for arrow before body, if any, else after cond/pat
def getCaseArrow(term: Case): FT = tokenBeforeOpt(term.body)
.getOrElse(getArrowAfter(tokenAfter(term.cond.getOrElse(term.pat))))
def getCaseArrow(term: Case): FT = tokenBeforeOpt(term.body).getOrElse {
getArrowAfter[T.RightArrow](tokenAfter(term.cond.getOrElse(term.pat)))
}

// look for arrow before body, if any, else after cond/pat
def getCaseArrow(term: TypeCase): FT = next(tokenAfter(term.pat))

private def getArrowAfter(ft: FT): FT = {
private def getArrowAfter[A](ft: FT)(implicit f: Classifier[T, A]): FT = {
val maybeArrow = next(ft)
if (maybeArrow.left.is[T.RightArrow]) maybeArrow
else nextAfterNonComment(maybeArrow)
if (f(maybeArrow.left)) maybeArrow else nextAfterNonComment(maybeArrow)
}

@tailrec
Expand Down