Skip to content

Commit 5d54616

Browse files
authored
Merge pull request #4107 from Hannah-Sten/exceptions
Avoid a possible UI freeze when finding files to index for native TeX Live installations
2 parents 90620c6 + 86a2c3e commit 5d54616

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919

2020
### Fixed
2121

22+
* Avoid a possible UI freeze when finding files to index for native TeX Live installations
2223
* Fix a bug where the documentation popup would not update correctly
2324
* Fix a few bugs related to the root files cache
2425
* Fix an issue with the file set cache when opening multiple projects
2526
* Fix auto compilation not rerunning correctly, by @Ezrnest
2627
* Fix SumatraPDF forward search not using the correct file, by @Ezrnest
2728
* Fix extra whitespace when inserting commands in math mode, by @Ezrnest
28-
* Fix exceptions #4035, #4044, #4058, #4072
29+
* Fix exceptions #4035, #4044, #4058, #4072, #4074, #4079, #4085, #4086, #4092, #4098
2930
* Create run configuration process in background
3031

3132
## [0.10.3] - 2025-05-16

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pluginVersion = 0.10.4-alpha.9
1+
pluginVersion = 0.10.4-alpha.10
22

33
# Info about build ranges: https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html
44
# Note that an xyz branch corresponds to version 20xy.z and a since build of xyz.*

src/nl/hannahsten/texifyidea/settings/sdk/NativeTexliveSdk.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package nl.hannahsten.texifyidea.settings.sdk
33
import com.intellij.openapi.projectRoots.Sdk
44
import com.intellij.openapi.vfs.LocalFileSystem
55
import com.intellij.openapi.vfs.VirtualFile
6+
import nl.hannahsten.texifyidea.util.TexifyCoroutine
67
import nl.hannahsten.texifyidea.util.containsAny
78
import nl.hannahsten.texifyidea.util.runCommand
9+
import nl.hannahsten.texifyidea.util.runCommandNonBlocking
810

911
/**
1012
* TeX Live, as installed natively by the OS's package manager.
@@ -23,6 +25,8 @@ class NativeTexliveSdk : TexliveSdk("Native TeX Live SDK") {
2325
val texmfDistPath: String by lazy {
2426
"kpsewhich article.sty".runCommand()?.substringBefore("texmf-dist") + "texmf-dist"
2527
}
28+
29+
var defaultStyleFilesPath: String? = null
2630
}
2731

2832
override fun suggestHomePath(): String {
@@ -62,8 +66,17 @@ class NativeTexliveSdk : TexliveSdk("Native TeX Live SDK") {
6266
}
6367

6468
override fun getDefaultStyleFilesPath(homePath: String): VirtualFile? {
65-
val articlePath = runCommand("$homePath/kpsewhich", "article.sty") ?: return null
66-
if (articlePath.isBlank()) return null
69+
// We cannot call system commands in a blocking way because it may cause freezes (#4102)
70+
if (Cache.defaultStyleFilesPath == null) {
71+
TexifyCoroutine.runInBackground {
72+
// Make sure to not leave it null to avoid unnecessary cache refreshes
73+
Cache.defaultStyleFilesPath = runCommandNonBlocking("$homePath/kpsewhich", "article.sty").output ?: ""
74+
}
75+
}
76+
77+
val articlePath = Cache.defaultStyleFilesPath
78+
if (articlePath.isNullOrBlank()) return null
79+
6780
// Assume article.sty is in tex/latex/base/article.sty
6881
return LocalFileSystem.getInstance().findFileByPath(articlePath)?.parent?.parent
6982
}

src/nl/hannahsten/texifyidea/util/files/LatexPackageLocationCache.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ object LatexPackageLocationCache {
4646
val searchPaths = texPaths + File.pathSeparator + (runCommandNonBlocking(executableName, "-show-path=bib").standardOutput ?: ".")
4747

4848
cache = runCommandNonBlocking(executableName, "-expand-path", searchPaths, timeout = 10).standardOutput?.split(File.pathSeparator)
49-
?.flatMap { LocalFileSystem.getInstance().findFileByPath(it)?.children?.toList() ?: emptyList() }
49+
?.flatMap {
50+
val file = LocalFileSystem.getInstance().findFileByPath(it)
51+
(if (file?.isValid == true) file.children?.toList() else null) ?: emptyList()
52+
}
5053
?.filter { !it.isDirectory }
5154
?.toSet()
5255
?.associate { it.name to it.path }

0 commit comments

Comments
 (0)