Skip to content

Commit

Permalink
Merge pull request #3862 from Hannah-Sten/package-updates-cache
Browse files Browse the repository at this point in the history
Fix package update cache
  • Loading branch information
PHPirates authored Jan 27, 2025
2 parents 5477d02 + d820a68 commit 937cd70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
level="WARNING" />
<localInspection language="Latex" implementationClass="nl.hannahsten.texifyidea.inspections.latex.probablebugs.packages.LatexPackageUpdateInspection"
groupPath="LaTeX" groupName="Probable bugs" displayName="Package has an update available"
enabledByDefault="true"
enabledByDefault="false"
level="WARNING" />
<localInspection language="Latex" implementationClass="nl.hannahsten.texifyidea.inspections.latex.probablebugs.packages.LatexPackageNameDoesNotMatchFileNameInspection"
groupPath="LaTeX" groupName="Probable bugs" displayName="Package name does not match file name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class LatexPackageUpdateInspection : TexifyInspectionBase() {

object Cache {
/** Map package name to old and new revision number */
var availablePackageUpdates = mapOf<String, Pair<String?, String?>>()
var availablePackageUpdates: Map<String, Pair<String?, String?>>? = null
}

override val inspectionGroup = InsightGroup.LATEX
Expand All @@ -46,9 +46,14 @@ class LatexPackageUpdateInspection : TexifyInspectionBase() {
override fun inspectFile(file: PsiFile, manager: InspectionManager, isOntheFly: Boolean): List<ProblemDescriptor> {
if (!LatexSdkUtil.isTlmgrAvailable(file.project) || !TexliveSdk.Cache.isAvailable) return emptyList()

if (Cache.availablePackageUpdates.isEmpty()) {
if (Cache.availablePackageUpdates == null) {
val tlmgrExecutable = LatexSdkUtil.getExecutableName("tlmgr", file.project)
val result = runCommand(tlmgrExecutable, "update", "--list") ?: return emptyList()
val result = runCommand(tlmgrExecutable, "update", "--list")
// Try to fill the cache only once
if (result == null) {
Cache.availablePackageUpdates = mapOf()
return emptyList()
}
Cache.availablePackageUpdates = """update:\s*(?<package>[^ ]+).*local:\s*(?<local>\d+), source:\s*(?<source>\d+)""".toRegex()
.findAll(result)
.mapNotNull { Pair(it.groups["package"]?.value ?: return@mapNotNull null, Pair(it.groups["local"]?.value, it.groups["source"]?.value)) }
Expand All @@ -57,10 +62,10 @@ class LatexPackageUpdateInspection : TexifyInspectionBase() {

return file.childrenOfType<LatexCommands>()
.filter { it.name in CommandMagic.packageInclusionCommands }
.filter { it.requiredParameter(0) in Cache.availablePackageUpdates.keys }
.filter { it.requiredParameter(0) in Cache.availablePackageUpdates!!.keys }
.mapNotNull {
val packageName = it.requiredParameter(0) ?: return@mapNotNull null
val packageVersions = Cache.availablePackageUpdates[packageName] ?: return@mapNotNull null
val packageVersions = Cache.availablePackageUpdates!![packageName] ?: return@mapNotNull null
manager.createProblemDescriptor(
it,
"Update available for package $packageName",
Expand Down

0 comments on commit 937cd70

Please sign in to comment.