Skip to content

Commit 8862903

Browse files
authored
Merge pull request #3395 from Hannah-Sten/miktex-extraction
Improve extraction of MiKTeX package source files
2 parents 9e92696 + c59a595 commit 8862903

File tree

3 files changed

+51
-18
lines changed

3 files changed

+51
-18
lines changed

CHANGELOG.md

+22-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@
66

77
### Fixed
88

9+
## [0.9.3-alpha.5] - 2024-01-14
10+
11+
### Added
12+
13+
* Improve MiKTeX package source files extraction
14+
* Add optidev environments as math environments, by @leandrolerena
15+
* Improve autocompletion performance after starting IDE
16+
* Improve plugin loading performance
17+
18+
### Fixed
19+
20+
* Improve user feedback for equation preview when Inkscape is not installed
21+
* Fix incorrectly inserted \items in enumeration environments, by @jojo2357
22+
* Fix false positives for equation gathering inspection, by @jojo2357
23+
* Don't attempt to use mthelp when it is not available, by @jojo2357
24+
* Fix #3361: false positive on duplicate identifier on @string entries in bib files
25+
* Replace code deprecated in 2023.3
26+
* Avoid creating output directories recursively and improve the cleanup process
27+
928
## [0.9.3-alpha.4] - 2024-01-12
1029

1130
### Added
@@ -284,9 +303,10 @@ Thanks to @jojo2357 and @MisterDeenis for contributing to this release!
284303
* Fix some intention previews. ([#2796](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2796))
285304
* Other small bug fixes and improvements. ([#2776](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2776), [#2774](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2774), [#2765](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2765)-[#2773](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2773))
286305

287-
[Unreleased]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.3-alpha.4...HEAD
288-
[0.9.3-alpha.3]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.2...v0.9.3-alpha.3
306+
[Unreleased]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.3-alpha.5...HEAD
289307
[0.9.3-alpha.4]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.3-alpha.3...v0.9.3-alpha.4
308+
[0.9.3-alpha.3]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.2...v0.9.3-alpha.3
309+
[0.9.3-alpha.5]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.3-alpha.4...v0.9.3-alpha.5
290310
[0.9.2]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.1...v0.9.2
291311
[0.9.1]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.0...v0.9.1
292312
[0.9.0]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.7.33...v0.9.0

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pluginVersion = 0.9.3-alpha.4
1+
pluginVersion = 0.9.3-alpha.5
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/index/file/LatexIndexableSetContributor.kt

+28-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package nl.hannahsten.texifyidea.index.file
22

3+
import com.intellij.openapi.progress.ProgressIndicator
4+
import com.intellij.openapi.progress.ProgressManager
5+
import com.intellij.openapi.progress.Task.Backgroundable
36
import com.intellij.openapi.project.Project
47
import com.intellij.openapi.vfs.VirtualFile
58
import com.intellij.util.indexing.IndexableSetContributor
@@ -19,8 +22,6 @@ import java.nio.file.Path
1922
*/
2023
class LatexIndexableSetContributor : IndexableSetContributor() {
2124

22-
private var extractedFiles = false
23-
2425
override fun getAdditionalProjectRootsToIndex(project: Project): MutableSet<VirtualFile> {
2526
// Avoid indexing in tests
2627
if (project.isTestProject()) {
@@ -31,16 +32,24 @@ class LatexIndexableSetContributor : IndexableSetContributor() {
3132

3233
// Add source files
3334
val roots = LatexSdkUtil.getSdkSourceRoots(project) { sdk, homePath -> sdk.getDefaultSourcesPath(homePath) }.toMutableSet()
34-
// Check if we possibly need to extract files first
35-
for (root in roots) {
36-
if (root.path.contains("MiKTeX", ignoreCase = true) && !extractedFiles) {
37-
try {
38-
if (!extractMiktexFiles(root)) return mutableSetOf()
39-
}
40-
catch (e: ArchiverException) {
41-
// Ignore permission errors, nothing we can do about that
42-
Log.debug("Exception when trying to extract MiKTeX source files: ${e.message}")
43-
return mutableSetOf()
35+
// Check if we possibly need to extract files first, but don't try more than once
36+
if (!extractedFiles) {
37+
extractedFiles = true
38+
for (root in roots) {
39+
if (root.path.contains("MiKTeX", ignoreCase = true)) {
40+
// Run in the background with progress, we cannot wait for completion because that would block this thread,
41+
// so in the worst case the files will only be indexed the next time indexing is triggered
42+
ProgressManager.getInstance().run(object : Backgroundable(project, "Extracting MiKTeX package source files", true) {
43+
override fun run(indicator: ProgressIndicator) {
44+
try {
45+
extractMiktexFiles(root, indicator)
46+
}
47+
catch (e: ArchiverException) {
48+
// Ignore permission errors, nothing we can do about that
49+
Log.debug("Exception when trying to extract MiKTeX source files: ${e.stackTraceToString()}")
50+
}
51+
}
52+
})
4453
}
4554
}
4655
}
@@ -61,9 +70,11 @@ class LatexIndexableSetContributor : IndexableSetContributor() {
6170
*
6271
* @return If succeeded.
6372
*/
64-
private fun extractMiktexFiles(root: VirtualFile): Boolean {
73+
private fun extractMiktexFiles(root: VirtualFile, indicator: ProgressIndicator): Boolean {
6574
val txArchiver = TarXZUnArchiver()
66-
File(root.path).list { _, name -> name.endsWith("tar.xz") }?.forEach { zipName ->
75+
val zips = File(root.path).list { _, name -> name.endsWith("tar.xz") } ?: return false
76+
for ((index, zipName) in zips.withIndex()) {
77+
indicator.fraction = index.toDouble() / zips.size
6778
txArchiver.sourceFile = File(root.path, zipName)
6879
// Note that by keeping the target path the same for everything, some packages will install in source/latex and some in source/latex/latex depending on how they were zipped
6980
val destination = File(root.path, "latex")
@@ -97,4 +108,6 @@ class LatexIndexableSetContributor : IndexableSetContributor() {
97108
}
98109

99110
override fun getAdditionalRootsToIndex() = mutableSetOf<VirtualFile>()
100-
}
111+
}
112+
113+
private var extractedFiles = false

0 commit comments

Comments
 (0)