Skip to content

Commit 15c8d09

Browse files
authored
Merge pull request #3827 from Hannah-Sten/addtoluatexpath
Add experimental support for the addtoluatexpath package
2 parents 63bed79 + 87b2587 commit 15c8d09

File tree

6 files changed

+64
-2
lines changed

6 files changed

+64
-2
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66
* Support label references to user defined listings environment
77
* Add option to disable automatic compilation in power save mode
88
* Convert automatic compilation settings to a combobox
9+
10+
* Add experimental support for the addtoluatexpath package
11+
12+
13+
14+
915
* Add inspection to check for LaTeX package updates
16+
17+
18+
1019
* Add checkboxes to graphic insertion wizard for relative width or height
1120

1221
### Fixed

src/nl/hannahsten/texifyidea/index/file/LatexIndexableSetContributor.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import nl.hannahsten.texifyidea.index.LatexIncludesIndex
1414
import nl.hannahsten.texifyidea.settings.TexifySettings
1515
import nl.hannahsten.texifyidea.settings.sdk.LatexSdkUtil
1616
import nl.hannahsten.texifyidea.util.Log
17+
import nl.hannahsten.texifyidea.util.files.addToLuatexPathSearchDirectories
1718
import nl.hannahsten.texifyidea.util.getTexinputsPaths
1819
import nl.hannahsten.texifyidea.util.isTestProject
1920
import nl.hannahsten.texifyidea.util.magic.CommandMagic
@@ -76,8 +77,8 @@ class LatexIndexableSetContributor : IndexableSetContributor() {
7677

7778
// Using the index while building it may be problematic, cache the result and hope it doesn't create too much trouble
7879
if (Cache.externalDirectFileInclusions == null && !DumbService.isDumb(project)) {
79-
runInBackground(project, "Searching for external bib files...") {
80-
// For now, just do this for bibliography and direct input commands, as there this is most common
80+
runInBackground(project, "Searching for inclusions by absolute path...") {
81+
// Bibliography and direct input commands
8182
val commandNames = CommandMagic.includeOnlyExtensions.entries.filter { it.value.contains("bib") || it.value.contains("tex") }.map { it.key }.toSet()
8283
val externalFiles = runReadAction {
8384
LatexIncludesIndex.Util.getCommandsByNames(commandNames, project, GlobalSearchScope.projectScope(project))
@@ -93,6 +94,12 @@ class LatexIndexableSetContributor : IndexableSetContributor() {
9394
}
9495
runReadAction { file?.parent }
9596
}
97+
.toMutableList()
98+
99+
// addtoluatexpath package
100+
val luatexPathDirectories = addToLuatexPathSearchDirectories(project)
101+
externalFiles.addAll(luatexPathDirectories)
102+
96103
Cache.externalDirectFileInclusions = externalFiles.toSet()
97104
}
98105
}

src/nl/hannahsten/texifyidea/lang/LatexPackage.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ open class LatexPackage @JvmOverloads constructor(
2727
// Predefined packages.
2828
val DEFAULT = LatexPackage("")
2929

30+
val ADDTOLUATEXPATH = LatexPackage("addtoluatexpath")
3031
val ALGORITHM2E = LatexPackage("algorithm2e")
3132
val ALGORITHMICX = LatexPackage("algorithmicx")
3233
val ALGPSEUDOCODE = LatexPackage("algpseudocode")

src/nl/hannahsten/texifyidea/lang/commands/LatexGenericRegularCommand.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ enum class LatexGenericRegularCommand(
3232
) : LatexCommand {
3333

3434
ADDTOCOUNTER("addtocounter", "countername".asRequired(), "value".asRequired()),
35+
ADDTOLUATEXPATH("addtoluatexpath", RequiredFolderArgument("paths")),
3536
A_RING("aa", display = "å"),
3637
CAPITAL_A_RING("AA", display = "Å"),
3738
ADDBIBRESOURCE("addbibresource", RequiredFileArgument("bibliographyfile", true, false, "bib"), dependency = BIBLATEX),

src/nl/hannahsten/texifyidea/reference/InputFileReference.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,14 @@ class InputFileReference(
202202
targetFile = findAnywhereInProject(processedKey)
203203
}
204204

205+
// addtoluatexpath package
206+
if (targetFile == null) {
207+
for (path in addToLuatexPathSearchDirectories(element.project)) {
208+
targetFile = path.findFile(processedKey, extensions, supportsAnyExtension)
209+
if (targetFile != null) break
210+
}
211+
}
212+
205213
if (targetFile == null) return null
206214

207215
// Return a reference to the target file.

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
package nl.hannahsten.texifyidea.util.files
22

33
import com.intellij.openapi.application.runReadAction
4+
import com.intellij.openapi.project.Project
5+
import com.intellij.openapi.vfs.LocalFileSystem
6+
import com.intellij.openapi.vfs.VirtualFile
47
import com.intellij.psi.PsiFile
8+
import com.intellij.psi.search.GlobalSearchScope
59
import nl.hannahsten.texifyidea.index.BibtexEntryIndex
610
import nl.hannahsten.texifyidea.index.LatexCommandsIndex
711
import nl.hannahsten.texifyidea.index.LatexDefinitionIndex
812
import nl.hannahsten.texifyidea.index.LatexIncludesIndex
13+
import nl.hannahsten.texifyidea.lang.LatexPackage
14+
import nl.hannahsten.texifyidea.lang.commands.LatexGenericRegularCommand
915
import nl.hannahsten.texifyidea.psi.LatexCommands
16+
import nl.hannahsten.texifyidea.util.magic.CommandMagic
17+
import nl.hannahsten.texifyidea.util.magic.cmd
1018
import nl.hannahsten.texifyidea.util.parser.isDefinition
19+
import nl.hannahsten.texifyidea.util.parser.requiredParameter
1120

1221
/**
1322
* Finds all the files in the project that are somehow related using includes.
@@ -95,3 +104,30 @@ fun PsiFile.definitionsInFileSet(): Collection<LatexCommands> {
95104
fun PsiFile.definitionsAndRedefinitionsInFileSet(): Collection<LatexCommands> {
96105
return LatexDefinitionIndex.Util.getItemsInFileSet(this)
97106
}
107+
108+
/**
109+
* The addtoluatexpath package supports adding to \input@path in different ways
110+
*/
111+
fun addToLuatexPathSearchDirectories(project: Project): List<VirtualFile> {
112+
val direct = runReadAction { LatexCommandsIndex.Util.getCommandsByNames(setOf(LatexGenericRegularCommand.ADDTOLUATEXPATH.cmd), project, GlobalSearchScope.projectScope(project)) }
113+
.mapNotNull { command -> runReadAction { command.requiredParameter(0) } }
114+
.flatMap { it.split(",") }
115+
val viaUsepackage = runReadAction { LatexIncludesIndex.Util.getCommandsByNames(CommandMagic.packageInclusionCommands, project, GlobalSearchScope.projectScope(project)) }
116+
.filter { runReadAction { it.requiredParameter(0) } == LatexPackage.ADDTOLUATEXPATH.name }
117+
.flatMap { runReadAction { it.getOptionalParameterMap().keys } }
118+
.flatMap { it.text.split(",") }
119+
120+
val luatexPathDirectories = (direct + viaUsepackage).flatMap {
121+
val basePath = LocalFileSystem.getInstance().findFileByPath(it.trimEnd('/', '*')) ?: return@flatMap emptyList()
122+
if (it.endsWith("/**")) {
123+
basePath.allChildDirectories()
124+
}
125+
else if (it.endsWith("/*")) {
126+
basePath.children.filter { it.isDirectory }
127+
}
128+
else {
129+
listOf(basePath)
130+
}
131+
}
132+
return luatexPathDirectories
133+
}

0 commit comments

Comments
 (0)