From 8786cdd17ead12907d4b6b6ca2f04e73319d2702 Mon Sep 17 00:00:00 2001 From: Jaden Peterson Date: Fri, 18 Oct 2024 18:35:59 -0400 Subject: [PATCH] Adjust SemanticDB target root paths using a regex Matching on string interpolation is terribly slow. --- .../rules_scala/workers/common/CommonArguments.scala | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/scala/higherkindness/rules_scala/workers/common/CommonArguments.scala b/src/main/scala/higherkindness/rules_scala/workers/common/CommonArguments.scala index a4c6f5c7..bc52a046 100644 --- a/src/main/scala/higherkindness/rules_scala/workers/common/CommonArguments.scala +++ b/src/main/scala/higherkindness/rules_scala/workers/common/CommonArguments.scala @@ -49,14 +49,18 @@ object Analysis { } object CommonArguments { + private val scala2SemanticDbTargetRootRegex = """-P:semanticdb:targetroot:(.*)""".r + private val scala3SemanticDbTargetRootRegex = """-semanticdb-target:(.*)""".r + private def adjustCompilerOptions(workDir: Path, options: List[String]) = { - def adjustStringPath(path: String) = SandboxUtil.getSandboxPath(workDir, Paths.get(path)).toString + def adjustStringPath(path: String) = + SandboxUtil.getSandboxPath(workDir, Paths.get(path)).toString options.flatMap { - case s"-P:semanticdb:targetroot:$path" => + case scala2SemanticDbTargetRootRegex(path) => List(s"-P:semanticdb:sourceroot:${workDir.toString}", s"-P:semanticdb:targetroot:${adjustStringPath(path)}") - case s"-semanticdb-target:$path" => + case scala3SemanticDbTargetRootRegex(path) => List(s"-semanticdb-target:${adjustStringPath(path)}", s"-sourceroot:${workDir.toString}") case option => List(option)