Skip to content

Commit

Permalink
Merge pull request #144 from bjaglin/scalafixAll-duplicated
Browse files Browse the repository at this point in the history
scalafixAll tweaks
  • Loading branch information
github-brice-jaglin authored Jul 8, 2020
2 parents 053b0c6 + 15566a2 commit 3800f16
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/main/scala/scalafix/sbt/ScalafixPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -253,21 +253,41 @@ object ScalafixPlugin extends AutoPlugin {
// workaround https://github.com/sbt/sbt/issues/3572 by invoking directly what Def.inputTaskDyn would via macro
InputTask
.createDyn(InputTask.initParserAsInput(scalafixCompletions(_.parser)))(
Def.task(shellArgs => scalafixAllTask(shellArgs, thisProject.value))
Def.task(shellArgs =>
scalafixAllTask(shellArgs, thisProject.value, resolvedScoped.value)
)
)

private def scalafixAllTask(
shellArgs: ShellArgs,
project: ResolvedProject
project: ResolvedProject,
scopedKey: ScopedKey[_]
): Def.Initialize[Task[Unit]] =
Def.taskDyn {
val configsWithScalafixInputKey = project.settings
.map(_.key)
.filter(_.key == scalafix.key)
.flatMap(_.scope.config.toOption)
.distinct

// To avoid seeing 2 concurrent scalafixAll tasks for a given project in supershell, this renames them
// to match the underlying configuration-scoped scalafix tasks
def updateName[T](task: Task[T], config: ConfigKey): Task[T] =
task.named(
Scope.display(
scopedKey.scope.copy(config = Select(config)),
scalafix.key.label,
{
case ProjectRef(_, id) => s"$id /"
case ref => s"${ref.toString} /"
}
)
)

configsWithScalafixInputKey
.map(config => scalafixTask(shellArgs, config))
.map { config =>
scalafixTask(shellArgs, config)(task => updateName(task, config))
}
.joinWith(_.join.map(_ => ()))
}

Expand Down

0 comments on commit 3800f16

Please sign in to comment.