Skip to content

Commit

Permalink
Rewrite: expect a method to convert to Input
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Feb 9, 2022
1 parent ce02954 commit 663ebff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ object Scalafmt {
if (code.matches("\\s*")) Try("\n")
else {
val runner = style.runner
val parsed = runner.parse(Rewrite(Input.VirtualFile(file, code), style))
def codeToInput(srcCode: String) = Input.VirtualFile(file, srcCode)
val parsed = runner.parse(Rewrite(codeToInput(code), style, codeToInput))
parsed.fold(
_.details match {
case ed: ParseException =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ object Rewrite {

val default: Seq[Rewrite] = name2rewrite.values.toSeq

def apply(input: VirtualFile, style: ScalafmtConfig): VirtualFile = {
def apply(
input: VirtualFile,
style: ScalafmtConfig,
toInput: String => Input
): Input = {
val rewrites = style.rewrite.rewriteFactoryRules
if (rewrites.isEmpty) {
input
Expand All @@ -157,7 +161,7 @@ object Rewrite {
}
}
traverser(ast)
input.copy(value = ctx.applyPatches)
toInput(ctx.applyPatches)
case _ => input
}
}
Expand Down

0 comments on commit 663ebff

Please sign in to comment.