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

add scalafixJGitCompletion key. reduce memory usage #405

Merged
merged 2 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
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 @@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading