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

State: getColumns compute first line length once #3096

Merged
merged 1 commit into from
Feb 1, 2022
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 @@ -337,31 +337,32 @@ object State {
} else syntax.length
val firstLineLength = column + syntaxLen
(firstLineLength, firstLineLength)
} else
} else {
val firstLength = column + firstNL
ft.right match {
case _: Token.Constant.String =>
val margin: Int => Int = if (style.assumeStandardLibraryStripMargin) {
// 3 for '|' + 2 spaces
val adjusted = 3 + (if (style.align.stripMargin) column else indent)
_ => adjusted
} else identity
getColumnsWithStripMargin(syntax, firstNL, margin, column)
getColumnsWithStripMargin(syntax, firstNL, margin, firstLength)
case _ =>
val lastNewline = syntax.length - syntax.lastIndexOf('\n') - 1
(column + firstNL, lastNewline)
(firstLength, lastNewline)
}
}
}

private def getColumnsWithStripMargin(
syntax: String,
firstNL: Int,
adjustMargin: Int => Int,
column: Int
firstLength: Int
): (Int, Int) = {
val matcher = stripMarginPattern.matcher(syntax)
matcher.region(firstNL, syntax.length)
val firstLineLength = column + firstNL
if (!matcher.find()) (firstLineLength, firstLineLength)
if (!matcher.find()) (firstLength, firstLength)
else {
def getMatcherLength() = {
val margin = matcher.end(1) - matcher.start(1)
Expand All @@ -375,7 +376,7 @@ object State {
val maxLength = math.max(prevMaxLength, length)
if (matcher.find()) iter(maxLength) else (maxLength, length)
}
iter(firstLineLength)
iter(firstLength)
}
}

Expand Down