Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search for external bib files in background #3809

Merged
merged 2 commits into from
Dec 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package nl.hannahsten.texifyidea.index.file

import com.intellij.openapi.application.runReadAction
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.Task.Backgroundable
Expand All @@ -17,6 +18,7 @@ import nl.hannahsten.texifyidea.util.getTexinputsPaths
import nl.hannahsten.texifyidea.util.isTestProject
import nl.hannahsten.texifyidea.util.magic.CommandMagic
import nl.hannahsten.texifyidea.util.parser.requiredParameter
import nl.hannahsten.texifyidea.util.runInBackground
import org.codehaus.plexus.archiver.ArchiverException
import org.codehaus.plexus.archiver.tar.TarBZip2UnArchiver
import org.codehaus.plexus.archiver.tar.TarXZUnArchiver
Expand Down Expand Up @@ -73,31 +75,25 @@ class LatexIndexableSetContributor : IndexableSetContributor() {
roots.addAll(getTexinputsPaths(project, rootFiles = listOf(), expandPaths = false).mapNotNull { LocalFileSystem.getInstance().findFileByPath(it) })

// Using the index while building it may be problematic, cache the result and hope it doesn't create too much trouble
if (Cache.externalDirectFileInclusions == null) {
if (!DumbService.isDumb(project)) {
try {
// For now, just do this for bibliography and direct input commands, as there this is most common
val externalFiles = LatexIncludesIndex.Util.getCommandsByNames(CommandMagic.includeOnlyExtensions.entries.filter { it.value.contains("bib") || it.value.contains("tex") }.map { it.key }.toSet(), project, GlobalSearchScope.projectScope(project))
// We can't add single files, so take the parent
.mapNotNull {
val path = it.requiredParameter(0) ?: return@mapNotNull null
if (File(path).isAbsolute) {
LocalFileSystem.getInstance().findFileByPath(path)?.parent
}
else {
it.containingFile.parent?.virtualFile?.findFileByRelativePath(path)?.parent
}
if (Cache.externalDirectFileInclusions == null && !DumbService.isDumb(project)) {
runInBackground(project, "Searching for external bib files...") {
// For now, just do this for bibliography and direct input commands, as there this is most common
val commandNames = CommandMagic.includeOnlyExtensions.entries.filter { it.value.contains("bib") || it.value.contains("tex") }.map { it.key }.toSet()
val externalFiles = runReadAction {
LatexIncludesIndex.Util.getCommandsByNames(commandNames, project, GlobalSearchScope.projectScope(project))
}
// We can't add single files, so take the parent
.mapNotNull {
val path = runReadAction { it.requiredParameter(0) } ?: return@mapNotNull null
val file = if (File(path).isAbsolute) {
LocalFileSystem.getInstance().findFileByPath(path)
}
Cache.externalDirectFileInclusions = externalFiles.toSet()
} catch (e: Throwable) {
// This is very rare, but it can happen, in which case we will ignore and try again later
if (e.message?.contains("Indexing process should not rely on non-indexed file data") == true) {
Log.warn("Ignored index not ready: " + e.message)
}
else {
throw e
else {
runReadAction { it.containingFile.parent }?.virtualFile?.findFileByRelativePath(path)
}
runReadAction { file?.parent }
}
}
Cache.externalDirectFileInclusions = externalFiles.toSet()
}
}
roots.addAll(Cache.externalDirectFileInclusions?.filter { it.exists() } ?: emptyList())
Expand Down
Loading