Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Feb 4, 2025
1 parent 35f4cc3 commit 69293ee
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import ch.epfl.scala.{bsp4j => b}
final class Compilations(
buildTargets: BuildTargets,
classes: BuildTargetClasses,
workspace: () => AbsolutePath,
languageClient: MetalsLanguageClient,
refreshTestSuites: () => Unit,
afterSuccessfulCompilation: () => Unit,
Expand Down Expand Up @@ -89,9 +88,11 @@ final class Compilations(
source: AbsolutePath,
compileInverseDependencies: Boolean,
): Future[Unit] =
expand(source).flatMap(targets =>
compilationFinished(targets.toSeq, compileInverseDependencies)
)
fileChanges
.expand(source)
.flatMap(targets =>
compilationFinished(targets.toSeq, compileInverseDependencies)
)

def compileTarget(
target: b.BuildTargetIdentifier
Expand Down Expand Up @@ -196,28 +197,8 @@ final class Compilations(
.ignoreValue
}

private def expand(
path: AbsolutePath
): Future[Option[b.BuildTargetIdentifier]] = {
val isCompilable =
(path.isScalaOrJava || path.isSbt) &&
!path.isDependencySource(workspace()) &&
!path.isInTmpDirectory(workspace())

if (isCompilable) {
val targetOpt = buildTargets.inverseSourcesBsp(path)
targetOpt.foreach {
case tgts if tgts.isEmpty => scribe.warn(s"no build target for: $path")
case _ =>
}

targetOpt
} else
Future.successful(None)
}

def expand(paths: Seq[AbsolutePath]): Future[Seq[b.BuildTargetIdentifier]] = {
val expansions = paths.map(expand)
val expansions = paths.map(fileChanges.expand)
Future.sequence(expansions).map(_.flatten)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class FileChanges(buildTargets: BuildTargets, workspace: () => AbsolutePath)(
allToCompile
}

/**
* The `assumeDidNotChange` should be set when we want to assume that the file did not change
* if it is not present in the `previousSignatures` (opened for the first time),
* we set it to `true` for operations such as `didFocus` or `didOpen`.
*/
def buildTargetToCompile(
path: AbsolutePath,
fingerprint: Option[Fingerprint],
Expand Down Expand Up @@ -78,7 +83,7 @@ class FileChanges(buildTargets: BuildTargets, workspace: () => AbsolutePath)(
)
}

private def expand(
def expand(
path: AbsolutePath
): Future[Option[BuildTargetIdentifier]] = {
val isCompilable =
Expand Down Expand Up @@ -121,7 +126,7 @@ class FileChanges(buildTargets: BuildTargets, workspace: () => AbsolutePath)(
fingerprint
.map { fingerprint =>
synchronized {
if (previousSignatures.getOrElse(path, null) == fingerprint.md5)
if (previousSignatures.getOrElse(path, "") == fingerprint.md5)
false
else {
previousSignatures.put(path, fingerprint.md5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ abstract class MetalsLspService(
val compilations: Compilations = new Compilations(
buildTargets,
buildTargetClasses,
() => folder,
languageClient,
() => testProvider.refreshTestSuites.apply(()),
() => {
Expand Down Expand Up @@ -923,7 +922,7 @@ abstract class MetalsLspService(
Future
.sequence(
List(
compilations.compileFiles(List((path, null))),
compilations.compileFiles(List((path, Fingerprint.empty))),
Future {
diagnostics.didDelete(path)
testProvider.onFileDelete(path)
Expand Down Expand Up @@ -1192,9 +1191,7 @@ abstract class MetalsLspService(
thresholdMillis = 1.second.toMillis,
) {
val path = params.getTextDocument.getUri.toAbsolutePath
codeLensProvider.findLenses(path).map(_.toList.asJava).map { found =>
found
}
codeLensProvider.findLenses(path).map(_.toList.asJava)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,9 @@ final class MutableMd5Fingerprints extends Md5Fingerprints {
override def toString: String = s"Md5FingerprintProvider($fingerprints)"
}

case class Fingerprint(text: String, md5: String)
case class Fingerprint(text: String, md5: String) {
def isEmpty: Boolean = md5.isEmpty()
}
object Fingerprint {
def empty: Fingerprint = Fingerprint("", "")
}

0 comments on commit 69293ee

Please sign in to comment.