Skip to content

Commit

Permalink
Merge pull request #405 from xuwei-k/reduce-memory
Browse files Browse the repository at this point in the history
  • Loading branch information
bjaglin committed Mar 23, 2024
2 parents a6e655e + 13ab8b7 commit aba1063
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Expand Up @@ -14,7 +14,8 @@ class ScalafixCompletions(
// depend on settings, while local rules classpath must be looked up via tasks
loadedRules: () => Seq[ScalafixRule],
terminalWidth: Option[Int],
allowedTargetFilesPrefixes: Seq[Path] // Nil means all values are valid
allowedTargetFilesPrefixes: Seq[Path], // Nil means all values are valid
jgitCompletion: JGitCompletion
) {

private type P = Parser[String]
Expand Down Expand Up @@ -116,7 +117,6 @@ class ScalafixCompletions(
private val namedRule2: Parser[ShellArgs.Rule] =
namedRule.map(s => ShellArgs.Rule(s))
private lazy val gitDiffParser: P = {
val jgitCompletion = new JGitCompletion(workingDirectory)
token(
NotQuoted,
TokenCompletions.fixed((seen, _) => {
Expand Down
16 changes: 13 additions & 3 deletions src/main/scala/scalafix/sbt/ScalafixPlugin.scala
Expand Up @@ -118,6 +118,13 @@ object ScalafixPlugin extends AutoPlugin {

import autoImport._

private val scalafixJGitCompletion: SettingKey[JGitCompletion] =
SettingKey(
"scalafixJGitCompletion",
"Implementation detail - do not use",
Invisible
)

private val scalafixDummyTask: TaskKey[Unit] =
TaskKey(
"scalafixDummyTask",
Expand Down Expand Up @@ -233,7 +240,8 @@ object ScalafixPlugin extends AutoPlugin {

override def buildSettings: Seq[Def.Setting[_]] =
Seq(
scalafixScalaBinaryVersion := "2.12"
scalafixScalaBinaryVersion := "2.12",
scalafixJGitCompletion := new JGitCompletion(baseDirectory.value.toPath)
)

lazy val stdoutLogger = ConsoleLogger(System.out)
Expand Down Expand Up @@ -299,7 +307,8 @@ object ScalafixPlugin extends AutoPlugin {
workingDirectory = (ThisBuild / baseDirectory).value.toPath,
loadedRules = () => scalafixInterfaceProvider.value().availableRules(),
terminalWidth = Some(JLineAccess.terminalWidth),
allowedTargetFilesPrefixes = Nil
allowedTargetFilesPrefixes = Nil,
jgitCompletion = scalafixJGitCompletion.value
)
)(_.parser)
// workaround https://github.com/sbt/sbt/issues/3572 by invoking directly what Def.inputTaskDyn would via macro
Expand Down Expand Up @@ -352,7 +361,8 @@ object ScalafixPlugin extends AutoPlugin {
loadedRules = () => scalafixInterfaceProvider.value().availableRules(),
terminalWidth = Some(JLineAccess.terminalWidth),
allowedTargetFilesPrefixes =
(scalafix / unmanagedSourceDirectories).value.map(_.toPath)
(scalafix / unmanagedSourceDirectories).value.map(_.toPath),
jgitCompletion = scalafixJGitCompletion.value
)
)(_.parser)

Expand Down
Expand Up @@ -47,7 +47,8 @@ class SbtCompletionsSuite extends AnyFunSuite {
workingDirectory = fs.workingDirectory.toAbsolutePath,
loadedRules = () => loadedRules,
terminalWidth = None,
allowedTargetFilesPrefixes = Seq(fs.workingDirectory.resolve("foo"))
allowedTargetFilesPrefixes = Seq(fs.workingDirectory.resolve("foo")),
jgitCompletion = new JGitCompletion(fs.workingDirectory.toAbsolutePath)
).parser

def checkCompletion(name: String, testTags: Tag*)(
Expand Down Expand Up @@ -268,7 +269,8 @@ class SbtCompletionsSuite extends AnyFunSuite {
workingDirectory = fs.workingDirectory.toAbsolutePath,
loadedRules = () => Nil,
terminalWidth = None,
allowedTargetFilesPrefixes = Nil
allowedTargetFilesPrefixes = Nil,
jgitCompletion = new JGitCompletion(fs.workingDirectory.toAbsolutePath)
).parser
)("--test --files=foo", SkipWindows) { args =>
assert(args == Left("""--files=foo
Expand Down

0 comments on commit aba1063

Please sign in to comment.