diff --git a/CHANGELOG.md b/CHANGELOG.md index 866e8dd62..254e55d43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Support label references to user defined listings environment * Add option to disable automatic compilation in power save mode * Convert automatic compilation settings to a combobox +* Add experimental support for the addtoluatexpath package * Add checkboxes to graphic insertion wizard for relative width or height ### Fixed diff --git a/src/nl/hannahsten/texifyidea/index/file/LatexIndexableSetContributor.kt b/src/nl/hannahsten/texifyidea/index/file/LatexIndexableSetContributor.kt index 70aef3cd7..56be336e5 100644 --- a/src/nl/hannahsten/texifyidea/index/file/LatexIndexableSetContributor.kt +++ b/src/nl/hannahsten/texifyidea/index/file/LatexIndexableSetContributor.kt @@ -14,6 +14,7 @@ import nl.hannahsten.texifyidea.index.LatexIncludesIndex import nl.hannahsten.texifyidea.settings.TexifySettings import nl.hannahsten.texifyidea.settings.sdk.LatexSdkUtil import nl.hannahsten.texifyidea.util.Log +import nl.hannahsten.texifyidea.util.files.addToLuatexPathSearchDirectories import nl.hannahsten.texifyidea.util.getTexinputsPaths import nl.hannahsten.texifyidea.util.isTestProject import nl.hannahsten.texifyidea.util.magic.CommandMagic @@ -76,8 +77,8 @@ class LatexIndexableSetContributor : IndexableSetContributor() { // 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 && !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 + runInBackground(project, "Searching for inclusions by absolute path...") { + // Bibliography and direct input commands 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)) @@ -93,6 +94,12 @@ class LatexIndexableSetContributor : IndexableSetContributor() { } runReadAction { file?.parent } } + .toMutableList() + + // addtoluatexpath package + val luatexPathDirectories = addToLuatexPathSearchDirectories(project) + externalFiles.addAll(luatexPathDirectories) + Cache.externalDirectFileInclusions = externalFiles.toSet() } } diff --git a/src/nl/hannahsten/texifyidea/lang/LatexPackage.kt b/src/nl/hannahsten/texifyidea/lang/LatexPackage.kt index bc42d7481..9bd6f315c 100644 --- a/src/nl/hannahsten/texifyidea/lang/LatexPackage.kt +++ b/src/nl/hannahsten/texifyidea/lang/LatexPackage.kt @@ -27,6 +27,7 @@ open class LatexPackage @JvmOverloads constructor( // Predefined packages. val DEFAULT = LatexPackage("") + val ADDTOLUATEXPATH = LatexPackage("addtoluatexpath") val ALGORITHM2E = LatexPackage("algorithm2e") val ALGORITHMICX = LatexPackage("algorithmicx") val ALGPSEUDOCODE = LatexPackage("algpseudocode") diff --git a/src/nl/hannahsten/texifyidea/lang/commands/LatexGenericRegularCommand.kt b/src/nl/hannahsten/texifyidea/lang/commands/LatexGenericRegularCommand.kt index ae9658d81..559a0d3f1 100644 --- a/src/nl/hannahsten/texifyidea/lang/commands/LatexGenericRegularCommand.kt +++ b/src/nl/hannahsten/texifyidea/lang/commands/LatexGenericRegularCommand.kt @@ -32,6 +32,7 @@ enum class LatexGenericRegularCommand( ) : LatexCommand { ADDTOCOUNTER("addtocounter", "countername".asRequired(), "value".asRequired()), + ADDTOLUATEXPATH("addtoluatexpath", RequiredFolderArgument("paths")), A_RING("aa", display = "å"), CAPITAL_A_RING("AA", display = "Å"), ADDBIBRESOURCE("addbibresource", RequiredFileArgument("bibliographyfile", true, false, "bib"), dependency = BIBLATEX), diff --git a/src/nl/hannahsten/texifyidea/reference/InputFileReference.kt b/src/nl/hannahsten/texifyidea/reference/InputFileReference.kt index 55d1b802d..529f0a471 100644 --- a/src/nl/hannahsten/texifyidea/reference/InputFileReference.kt +++ b/src/nl/hannahsten/texifyidea/reference/InputFileReference.kt @@ -202,6 +202,14 @@ class InputFileReference( targetFile = findAnywhereInProject(processedKey) } + // addtoluatexpath package + if (targetFile == null) { + for (path in addToLuatexPathSearchDirectories(element.project)) { + targetFile = path.findFile(processedKey, extensions, supportsAnyExtension) + if (targetFile != null) break + } + } + if (targetFile == null) return null // Return a reference to the target file. diff --git a/src/nl/hannahsten/texifyidea/util/files/FileSet.kt b/src/nl/hannahsten/texifyidea/util/files/FileSet.kt index 23a97dc98..0260bfd02 100644 --- a/src/nl/hannahsten/texifyidea/util/files/FileSet.kt +++ b/src/nl/hannahsten/texifyidea/util/files/FileSet.kt @@ -1,13 +1,22 @@ package nl.hannahsten.texifyidea.util.files import com.intellij.openapi.application.runReadAction +import com.intellij.openapi.project.Project +import com.intellij.openapi.vfs.LocalFileSystem +import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.PsiFile +import com.intellij.psi.search.GlobalSearchScope import nl.hannahsten.texifyidea.index.BibtexEntryIndex import nl.hannahsten.texifyidea.index.LatexCommandsIndex import nl.hannahsten.texifyidea.index.LatexDefinitionIndex import nl.hannahsten.texifyidea.index.LatexIncludesIndex +import nl.hannahsten.texifyidea.lang.LatexPackage +import nl.hannahsten.texifyidea.lang.commands.LatexGenericRegularCommand import nl.hannahsten.texifyidea.psi.LatexCommands +import nl.hannahsten.texifyidea.util.magic.CommandMagic +import nl.hannahsten.texifyidea.util.magic.cmd import nl.hannahsten.texifyidea.util.parser.isDefinition +import nl.hannahsten.texifyidea.util.parser.requiredParameter /** * Finds all the files in the project that are somehow related using includes. @@ -95,3 +104,30 @@ fun PsiFile.definitionsInFileSet(): Collection { fun PsiFile.definitionsAndRedefinitionsInFileSet(): Collection { return LatexDefinitionIndex.Util.getItemsInFileSet(this) } + +/** + * The addtoluatexpath package supports adding to \input@path in different ways + */ +fun addToLuatexPathSearchDirectories(project: Project): List { + val direct = runReadAction { LatexCommandsIndex.Util.getCommandsByNames(setOf(LatexGenericRegularCommand.ADDTOLUATEXPATH.cmd), project, GlobalSearchScope.projectScope(project)) } + .mapNotNull { command -> runReadAction { command.requiredParameter(0) } } + .flatMap { it.split(",") } + val viaUsepackage = runReadAction { LatexIncludesIndex.Util.getCommandsByNames(CommandMagic.packageInclusionCommands, project, GlobalSearchScope.projectScope(project)) } + .filter { runReadAction { it.requiredParameter(0) } == LatexPackage.ADDTOLUATEXPATH.name } + .flatMap { runReadAction { it.getOptionalParameterMap().keys } } + .flatMap { it.text.split(",") } + + val luatexPathDirectories = (direct + viaUsepackage).flatMap { + val basePath = LocalFileSystem.getInstance().findFileByPath(it.trimEnd('/', '*')) ?: return@flatMap emptyList() + if (it.endsWith("/**")) { + basePath.allChildDirectories() + } + else if (it.endsWith("/*")) { + basePath.children.filter { it.isDirectory } + } + else { + listOf(basePath) + } + } + return luatexPathDirectories +}