Skip to content

Commit

Permalink
bugfix: Don't calculate digest every time build tool is used
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Jul 8, 2024
1 parent 4f6101b commit 314b01f
Showing 1 changed file with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -828,19 +828,28 @@ class ProjectMetalsLspService(
for {
name <- tables.buildTool.selectedBuildTool()
buildTool <- buildTools.current().find(_.executableName == name)
found <- isCompatibleVersion(buildTool) match {
case BuildTool.Found(bt, _) => Some(bt)
case _ => None
}
} yield found
if isCompatibleVersion(buildTool)
} yield buildTool

private def isCompatibleVersion(buildTool: BuildTool): Boolean = {
buildTool match {
case buildTool: VersionRecommendation =>
SemVer.isCompatibleVersion(
buildTool.minimumVersion,
buildTool.version,
)
case _ => true
}
}

def isCompatibleVersion(buildTool: BuildTool): BuildTool.Verified = {
/**
* Checks if the version of the build tool is compatible with the version that
* metals expects and returns the current digest of the build tool.
*/
private def verifyBuildTool(buildTool: BuildTool): BuildTool.Verified = {
buildTool match {
case buildTool: VersionRecommendation
if !SemVer.isCompatibleVersion(
buildTool.minimumVersion,
buildTool.version,
) =>
if !isCompatibleVersion(buildTool) =>
BuildTool.IncompatibleVersion(buildTool)
case _ =>
buildTool.digestWithRetry(folder) match {
Expand All @@ -866,7 +875,7 @@ class ProjectMetalsLspService(
)
} yield {
buildTool.flatMap { bt =>
isCompatibleVersion(bt) match {
verifyBuildTool(bt) match {
case found: BuildTool.Found => Some(found)
case warn @ BuildTool.IncompatibleVersion(buildTool) =>
scribe.warn(warn.message)
Expand Down

0 comments on commit 314b01f

Please sign in to comment.