From 55ebf005cf8b6682d0ff13770363e6850c3b4924 Mon Sep 17 00:00:00 2001 From: Thomas Schouten Date: Sat, 28 Dec 2024 15:27:12 +0100 Subject: [PATCH 1/6] Improve performance of file set cache --- CHANGELOG.md | 1 + .../texifyidea/util/files/FileSet.kt | 33 ++++--------------- .../util/files/ReferencedFileSetCache.kt | 19 ++++++----- 3 files changed, 19 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 866e8dd62..c3dc477d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased] ### Added +* Improve performance of file set cache used by inspections * 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 diff --git a/src/nl/hannahsten/texifyidea/util/files/FileSet.kt b/src/nl/hannahsten/texifyidea/util/files/FileSet.kt index 23a97dc98..48f883daa 100644 --- a/src/nl/hannahsten/texifyidea/util/files/FileSet.kt +++ b/src/nl/hannahsten/texifyidea/util/files/FileSet.kt @@ -1,6 +1,7 @@ package nl.hannahsten.texifyidea.util.files import com.intellij.openapi.application.runReadAction +import com.intellij.openapi.project.Project import com.intellij.psi.PsiFile import nl.hannahsten.texifyidea.index.BibtexEntryIndex import nl.hannahsten.texifyidea.index.LatexCommandsIndex @@ -21,38 +22,18 @@ import nl.hannahsten.texifyidea.util.parser.isDefinition * @return All the LaTeX and BibTeX files that are cross referenced between each other. */ // Internal because only ReferencedFileSetCache should call this -internal fun PsiFile.findReferencedFileSetWithoutCache(): Set { - // Setup. - val project = this.project - val includes = LatexIncludesIndex.Util.getItems(project) - +internal fun Project.findReferencedFileSetWithoutCache(): Map> { // Find all root files. - val roots = includes.asSequence() + return LatexIncludesIndex.Util.getItems(this) + .asSequence() .map { it.containingFile } .distinct() .filter { it.isRoot() } .toSet() - - // Map root to all directly referenced files. - val sets = HashMap>() - for (root in roots) { - val referenced = runReadAction { root.referencedFiles(root.virtualFile) } + root - - if (referenced.contains(this)) { - return referenced + this + .associateWith { root -> + // Map root to all directly referenced files. + runReadAction { root.referencedFiles(root.virtualFile) } + root } - - sets[root] = referenced - } - - // Look for matching root. - for (referenced in sets.values) { - if (referenced.contains(this)) { - return referenced + this - } - } - - return setOf(this) } /** diff --git a/src/nl/hannahsten/texifyidea/util/files/ReferencedFileSetCache.kt b/src/nl/hannahsten/texifyidea/util/files/ReferencedFileSetCache.kt index 4c61fdd2d..dad42e5e5 100644 --- a/src/nl/hannahsten/texifyidea/util/files/ReferencedFileSetCache.kt +++ b/src/nl/hannahsten/texifyidea/util/files/ReferencedFileSetCache.kt @@ -83,14 +83,16 @@ class ReferencedFileSetCache { * once and then fill both caches with all the information we have. */ private fun updateCachesFor(requestedFile: PsiFile) { - val fileset = requestedFile.findReferencedFileSetWithoutCache() - for (file in fileset) { - fileSetCache[file.virtualFile] = fileset.map { it.createSmartPointer() }.toSet() - } + val filesets = requestedFile.project.findReferencedFileSetWithoutCache() + for (fileset in filesets.values) { + for (file in fileset) { + fileSetCache[file.virtualFile] = fileset.map { it.createSmartPointer() }.toSet() + } - val rootfiles = requestedFile.findRootFilesWithoutCache(fileset) - for (file in fileset) { - rootFilesCache[file.virtualFile] = rootfiles.map { it.createSmartPointer() }.toSet() + val rootfiles = requestedFile.findRootFilesWithoutCache(fileset) + for (file in fileset) { + rootFilesCache[file.virtualFile] = rootfiles.map { it.createSmartPointer() }.toSet() + } } } @@ -117,7 +119,8 @@ class ReferencedFileSetCache { false } - if (!cache.containsKey(file.virtualFile) || numberOfIncludesChanged) { + // The cache should be complete once filled, any files not in there are assumed to not be part of a file set that has a valid root file + if (numberOfIncludesChanged) { updateCachesFor(file) } } From a5a66782c77523ab9a5e9d3c0d99b4ef81d78f23 Mon Sep 17 00:00:00 2001 From: Thomas Schouten Date: Sat, 28 Dec 2024 20:17:54 +0100 Subject: [PATCH 2/6] Add basic support for multiple inputs in Tectonic.toml in file set construction --- CHANGELOG.md | 1 + build.gradle.kts | 1 + .../texifyidea/util/files/FileSet.kt | 38 ++++++++++++++++++- .../util/files/ReferencedFileSetCache.kt | 13 ++++++- 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3dc477d9..edfd91527 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased] ### Added +* Add basic support for multiple inputs in Tectonic.toml * Improve performance of file set cache used by inspections * Support label references to user defined listings environment * Add option to disable automatic compilation in power save mode diff --git a/build.gradle.kts b/build.gradle.kts index 7412250e6..d6e910f03 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -140,6 +140,7 @@ dependencies { // Parsing xml implementation("com.fasterxml.jackson.core:jackson-core:2.18.2") implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.18.2") + implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-toml:2.18.2") implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.18.2") // Http requests diff --git a/src/nl/hannahsten/texifyidea/util/files/FileSet.kt b/src/nl/hannahsten/texifyidea/util/files/FileSet.kt index 48f883daa..26c5e12a4 100644 --- a/src/nl/hannahsten/texifyidea/util/files/FileSet.kt +++ b/src/nl/hannahsten/texifyidea/util/files/FileSet.kt @@ -1,7 +1,11 @@ package nl.hannahsten.texifyidea.util.files +import com.fasterxml.jackson.dataformat.toml.TomlMapper import com.intellij.openapi.application.runReadAction import com.intellij.openapi.project.Project +import com.intellij.openapi.roots.ProjectFileIndex +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.openapi.vfs.findFile import com.intellij.psi.PsiFile import nl.hannahsten.texifyidea.index.BibtexEntryIndex import nl.hannahsten.texifyidea.index.LatexCommandsIndex @@ -9,17 +13,18 @@ import nl.hannahsten.texifyidea.index.LatexDefinitionIndex import nl.hannahsten.texifyidea.index.LatexIncludesIndex import nl.hannahsten.texifyidea.psi.LatexCommands import nl.hannahsten.texifyidea.util.parser.isDefinition +import java.io.File /** * Finds all the files in the project that are somehow related using includes. * * When A includes B and B includes C then A, B & C will all return a set containing A, B & C. + * There can be multiple root files in one file set. * * Be careful when using this function directly over something like [ReferencedFileSetService] where the result * values are cached. * - * @receiver The file to find the reference set of. - * @return All the LaTeX and BibTeX files that are cross referenced between each other. + * @return Map all root files which include any other file, to the file set containing that root file. */ // Internal because only ReferencedFileSetCache should call this internal fun Project.findReferencedFileSetWithoutCache(): Map> { @@ -36,6 +41,35 @@ internal fun Project.findReferencedFileSetWithoutCache(): Map> { + // Actually, according to https://tectonic-typesetting.github.io/book/latest/v2cli/build.html?highlight=tectonic.toml#remarks Tectonic.toml files can appear in any parent directory, but we only search in the project for now + val tomlFiles = findTectonicTomlFiles(project) + val filesets = tomlFiles.mapNotNull { tomlFile -> + val data = TomlMapper().readValue(File(tomlFile.path), Map::class.java) + val outputList = data.getOrDefault("output", null) as? List<*> ?: return@mapNotNull null + val inputs = (outputList.firstOrNull() as? Map<*, *>)?.getOrDefault("inputs", null) as? List<*> ?: return@mapNotNull null + // Inputs can be either a map "inline" -> String or file name + // Actually it can also be just a single file name, but then we don't need all this gymnastics + inputs.filterIsInstance().mapNotNull { + tomlFile.parent.findFile("src/$it")?.psiFile(project) + }.toSet() + } + + return filesets +} + +private fun findTectonicTomlFiles(project: Project): MutableSet { + val tomlFiles = mutableSetOf() + ProjectFileIndex.getInstance(project).iterateContent({ tomlFiles.add(it) }, { it.name == "Tectonic.toml" }) + return tomlFiles +} + /** * Finds all the files in the project that are somehow related using includes. * diff --git a/src/nl/hannahsten/texifyidea/util/files/ReferencedFileSetCache.kt b/src/nl/hannahsten/texifyidea/util/files/ReferencedFileSetCache.kt index dad42e5e5..98eea4cfb 100644 --- a/src/nl/hannahsten/texifyidea/util/files/ReferencedFileSetCache.kt +++ b/src/nl/hannahsten/texifyidea/util/files/ReferencedFileSetCache.kt @@ -83,7 +83,18 @@ class ReferencedFileSetCache { * once and then fill both caches with all the information we have. */ private fun updateCachesFor(requestedFile: PsiFile) { - val filesets = requestedFile.project.findReferencedFileSetWithoutCache() + val filesets = requestedFile.project.findReferencedFileSetWithoutCache().toMutableMap() + val tectonicInclusions = findTectonicTomlInclusions(requestedFile.project) + + // Now we join all the file sets that are in the same file set according to the Tectonic.toml file + for (inclusionsSet in tectonicInclusions) { + val mappings = filesets.filter { it.value.intersect(inclusionsSet).isNotEmpty() } + val newFileSet = mappings.values.flatten().toSet() + inclusionsSet + mappings.forEach { + filesets[it.key] = newFileSet + } + } + for (fileset in filesets.values) { for (file in fileset) { fileSetCache[file.virtualFile] = fileset.map { it.createSmartPointer() }.toSet() From 5d6beb2fc1ef06ef6022892e52db59d3a14f3506 Mon Sep 17 00:00:00 2001 From: Thomas Schouten Date: Sat, 28 Dec 2024 20:54:18 +0100 Subject: [PATCH 3/6] Support Tectonic V2 CLI in run configuration --- CHANGELOG.md | 1 + .../topics/Run-configuration-settings.md | 3 ++- .../texifyidea/run/compiler/LatexCompiler.kt | 20 +++++++++++++------ .../run/latex/LatexCommandLineState.kt | 5 ++++- .../texifyidea/util/files/FileSet.kt | 20 +++++++++++++++++++ 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edfd91527..e10ded651 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased] ### Added +* Support Tectonic V2 CLI in run configuration * Add basic support for multiple inputs in Tectonic.toml * Improve performance of file set cache used by inspections * Support label references to user defined listings environment diff --git a/Writerside/topics/Run-configuration-settings.md b/Writerside/topics/Run-configuration-settings.md index 779eaff00..cb6759bad 100644 --- a/Writerside/topics/Run-configuration-settings.md +++ b/Writerside/topics/Run-configuration-settings.md @@ -92,9 +92,10 @@ _Since b0.6.6_ See [https://tectonic-typesetting.github.io/en-US/](https://tectonic-typesetting.github.io/en-US/) for installation and more info. Tectonic has the advantage that it downloads packages automatically, compiles just as much times as needed and handles BibTeX, but it often only works for not too complicated LaTeX documents. - It also has automatic compilation using `tectonic -X watch`. +There is some basic support for a `Tectonic.toml` file, including inspection support (missing imports, for example) for multiple inputs in the toml file (Tectonic 0.15.1 or later). + The documentation can be found at [https://tectonic-typesetting.github.io/book/latest/](https://tectonic-typesetting.github.io/book/latest/) ## BibTeX compilers diff --git a/src/nl/hannahsten/texifyidea/run/compiler/LatexCompiler.kt b/src/nl/hannahsten/texifyidea/run/compiler/LatexCompiler.kt index 942a12a21..274ad36a3 100644 --- a/src/nl/hannahsten/texifyidea/run/compiler/LatexCompiler.kt +++ b/src/nl/hannahsten/texifyidea/run/compiler/LatexCompiler.kt @@ -12,6 +12,7 @@ import nl.hannahsten.texifyidea.settings.sdk.DockerSdk import nl.hannahsten.texifyidea.settings.sdk.DockerSdkAdditionalData import nl.hannahsten.texifyidea.settings.sdk.LatexSdkUtil import nl.hannahsten.texifyidea.util.LatexmkRcFileFinder +import nl.hannahsten.texifyidea.util.files.hasTectonicTomlFile import nl.hannahsten.texifyidea.util.runCommand import java.util.* @@ -231,15 +232,22 @@ enum class LatexCompiler(private val displayName: String, val executableName: St moduleRoot: VirtualFile?, moduleRoots: Array ): MutableList { - // The available command line arguments can be found at https://github.com/tectonic-typesetting/tectonic/blob/d7a8497c90deb08b5e5792a11d6e8b082f53bbb7/src/bin/tectonic.rs#L158 val command = mutableListOf(runConfig.compilerPath ?: executableName) - command.add("--synctex") + // The available command line arguments can be found at https://github.com/tectonic-typesetting/tectonic/blob/d7a8497c90deb08b5e5792a11d6e8b082f53bbb7/src/bin/tectonic.rs#L158 + // The V2 CLI uses a toml file and should not have arguments + if (runConfig.mainFile?.hasTectonicTomlFile() != true) { + command.add("--synctex") - command.add("--outfmt=${runConfig.outputFormat.name.lowercase(Locale.getDefault())}") + command.add("--outfmt=${runConfig.outputFormat.name.lowercase(Locale.getDefault())}") - if (outputPath != null) { - command.add("--outdir=$outputPath") + if (outputPath != null) { + command.add("--outdir=$outputPath") + } + } + else { + command.add("-X") + command.add("build") } return command @@ -364,7 +372,7 @@ enum class LatexCompiler(private val displayName: String, val executableName: St command.add(runConfig.beforeRunCommand + " \\input{${mainFile.name}}") } } - else { + else if (runConfig.compiler != TECTONIC || runConfig.mainFile?.hasTectonicTomlFile() != true) { command.add(mainFile.name) } diff --git a/src/nl/hannahsten/texifyidea/run/latex/LatexCommandLineState.kt b/src/nl/hannahsten/texifyidea/run/latex/LatexCommandLineState.kt index aff57a18c..90e463e43 100644 --- a/src/nl/hannahsten/texifyidea/run/latex/LatexCommandLineState.kt +++ b/src/nl/hannahsten/texifyidea/run/latex/LatexCommandLineState.kt @@ -27,6 +27,8 @@ import nl.hannahsten.texifyidea.run.pdfviewer.ExternalPdfViewer import nl.hannahsten.texifyidea.run.sumatra.SumatraAvailabilityChecker import nl.hannahsten.texifyidea.run.sumatra.SumatraForwardSearchListener import nl.hannahsten.texifyidea.util.files.commandsInFileSet +import nl.hannahsten.texifyidea.util.files.findTectonicTomlFile +import nl.hannahsten.texifyidea.util.files.hasTectonicTomlFile import nl.hannahsten.texifyidea.util.files.psiFile import nl.hannahsten.texifyidea.util.includedPackages import nl.hannahsten.texifyidea.util.magic.PackageMagic @@ -92,7 +94,8 @@ open class LatexCommandLineState(environment: ExecutionEnvironment, private val val command: List = compiler.getCommand(runConfig, environment.project) ?: throw ExecutionException("Compile command could not be created.") - val commandLine = GeneralCommandLine(command).withWorkDirectory(mainFile.parent.path) + val workingDirectory = if (compiler == LatexCompiler.TECTONIC && mainFile.hasTectonicTomlFile()) mainFile.findTectonicTomlFile()!!.parent.path else mainFile.parent.path + val commandLine = GeneralCommandLine(command).withWorkDirectory(workingDirectory) .withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE) .withEnvironment(runConfig.environmentVariables.envs) val handler = KillableProcessHandler(commandLine) diff --git a/src/nl/hannahsten/texifyidea/util/files/FileSet.kt b/src/nl/hannahsten/texifyidea/util/files/FileSet.kt index 26c5e12a4..d47e886f5 100644 --- a/src/nl/hannahsten/texifyidea/util/files/FileSet.kt +++ b/src/nl/hannahsten/texifyidea/util/files/FileSet.kt @@ -70,6 +70,26 @@ private fun findTectonicTomlFiles(project: Project): MutableSet { return tomlFiles } +/** + * A toml file can be in any parent directory. + */ +fun VirtualFile.hasTectonicTomlFile() = findTectonicTomlFile() != null + +fun VirtualFile.findTectonicTomlFile(): VirtualFile? { + var parent = this + for (i in 0..20) { + if (parent.parent != null && parent.parent.isDirectory && parent.parent.exists()) { + parent = parent.parent + } + else { + break + } + + parent?.findFile("Tectonic.toml")?.let { return it } + } + return null +} + /** * Finds all the files in the project that are somehow related using includes. * From 49a1f6f26f35614741651553f3236da9267e7b13 Mon Sep 17 00:00:00 2001 From: Thomas Schouten Date: Sat, 28 Dec 2024 20:59:52 +0100 Subject: [PATCH 4/6] Formatting --- .../texifyidea/util/files/FileSet.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/nl/hannahsten/texifyidea/util/files/FileSet.kt b/src/nl/hannahsten/texifyidea/util/files/FileSet.kt index d47e886f5..721e38ce4 100644 --- a/src/nl/hannahsten/texifyidea/util/files/FileSet.kt +++ b/src/nl/hannahsten/texifyidea/util/files/FileSet.kt @@ -51,15 +51,15 @@ fun findTectonicTomlInclusions(project: Project): List> { // Actually, according to https://tectonic-typesetting.github.io/book/latest/v2cli/build.html?highlight=tectonic.toml#remarks Tectonic.toml files can appear in any parent directory, but we only search in the project for now val tomlFiles = findTectonicTomlFiles(project) val filesets = tomlFiles.mapNotNull { tomlFile -> - val data = TomlMapper().readValue(File(tomlFile.path), Map::class.java) - val outputList = data.getOrDefault("output", null) as? List<*> ?: return@mapNotNull null - val inputs = (outputList.firstOrNull() as? Map<*, *>)?.getOrDefault("inputs", null) as? List<*> ?: return@mapNotNull null - // Inputs can be either a map "inline" -> String or file name - // Actually it can also be just a single file name, but then we don't need all this gymnastics - inputs.filterIsInstance().mapNotNull { - tomlFile.parent.findFile("src/$it")?.psiFile(project) - }.toSet() - } + val data = TomlMapper().readValue(File(tomlFile.path), Map::class.java) + val outputList = data.getOrDefault("output", null) as? List<*> ?: return@mapNotNull null + val inputs = (outputList.firstOrNull() as? Map<*, *>)?.getOrDefault("inputs", null) as? List<*> ?: return@mapNotNull null + // Inputs can be either a map "inline" -> String or file name + // Actually it can also be just a single file name, but then we don't need all this gymnastics + inputs.filterIsInstance().mapNotNull { + tomlFile.parent.findFile("src/$it")?.psiFile(project) + }.toSet() + } return filesets } From b8be34ea194c0a825a983a93d6397a691befad77 Mon Sep 17 00:00:00 2001 From: Thomas Schouten Date: Sun, 29 Dec 2024 21:01:37 +0100 Subject: [PATCH 5/6] Refresh cache in tests --- .../texifyidea/util/files/ReferencedFileSetCache.kt | 12 +++--------- .../bibtex/BibtexUnusedEntryInspectionTest.kt | 6 +++++- .../texifyidea/reference/BibtexIdCompletionTest.kt | 13 +++++++------ .../BibtexIdRemoteLibraryCompletionTest.kt | 6 +++++- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/nl/hannahsten/texifyidea/util/files/ReferencedFileSetCache.kt b/src/nl/hannahsten/texifyidea/util/files/ReferencedFileSetCache.kt index 98eea4cfb..c6db5cdaf 100644 --- a/src/nl/hannahsten/texifyidea/util/files/ReferencedFileSetCache.kt +++ b/src/nl/hannahsten/texifyidea/util/files/ReferencedFileSetCache.kt @@ -121,17 +121,11 @@ class ReferencedFileSetCache { // Use the keys of the whole project, because suppose a new include includes the current file, it could be anywhere in the project // Note that LatexIncludesIndex.Util.getItems(file.project) may be a slow operation and should not be run on EDT val includes = LatexIncludesIndex.Util.getItems(file.project) - val numberOfIncludesChanged = if (includes.size != numberOfIncludes[file.project]) { - numberOfIncludes[file.project] = includes.size - dropAllCaches() - true - } - else { - false - } // The cache should be complete once filled, any files not in there are assumed to not be part of a file set that has a valid root file - if (numberOfIncludesChanged) { + if (includes.size != numberOfIncludes[file.project]) { + numberOfIncludes[file.project] = includes.size + dropAllCaches() updateCachesFor(file) } } diff --git a/test/nl/hannahsten/texifyidea/inspections/bibtex/BibtexUnusedEntryInspectionTest.kt b/test/nl/hannahsten/texifyidea/inspections/bibtex/BibtexUnusedEntryInspectionTest.kt index f51cfbc4f..2af0d3b3f 100644 --- a/test/nl/hannahsten/texifyidea/inspections/bibtex/BibtexUnusedEntryInspectionTest.kt +++ b/test/nl/hannahsten/texifyidea/inspections/bibtex/BibtexUnusedEntryInspectionTest.kt @@ -2,6 +2,7 @@ package nl.hannahsten.texifyidea.inspections.bibtex import nl.hannahsten.texifyidea.inspections.TexifyInspectionTestBase import nl.hannahsten.texifyidea.testutils.writeCommand +import nl.hannahsten.texifyidea.util.files.ReferencedFileSetService class BibtexUnusedEntryInspectionTest : TexifyInspectionTestBase(BibtexUnusedEntryInspection()) { @@ -15,7 +16,10 @@ class BibtexUnusedEntryInspectionTest : TexifyInspectionTestBase(BibtexUnusedEnt } fun `test quick fix`() { - myFixture.configureByFiles("references-before.bib", "main-quick-fix.tex") + myFixture.configureByFiles("references-before.bib", "main-quick-fix.tex").forEach { + // Refresh cache + ReferencedFileSetService.getInstance().referencedFileSetOf(it) + } val quickFixes = myFixture.getAllQuickFixes() assertEquals("Expected number of quick fixes:", 2, quickFixes.size) writeCommand(myFixture.project) { diff --git a/test/nl/hannahsten/texifyidea/reference/BibtexIdCompletionTest.kt b/test/nl/hannahsten/texifyidea/reference/BibtexIdCompletionTest.kt index acfbd7d23..6eb659ff4 100644 --- a/test/nl/hannahsten/texifyidea/reference/BibtexIdCompletionTest.kt +++ b/test/nl/hannahsten/texifyidea/reference/BibtexIdCompletionTest.kt @@ -3,6 +3,8 @@ package nl.hannahsten.texifyidea.reference import com.intellij.codeInsight.completion.CompletionType import com.intellij.codeInsight.documentation.DocumentationManager import com.intellij.testFramework.fixtures.BasePlatformTestCase +import nl.hannahsten.texifyidea.util.files.ReferencedFileSetCache +import nl.hannahsten.texifyidea.util.files.ReferencedFileSetService import org.junit.Test class BibtexIdCompletionTest : BasePlatformTestCase() { @@ -16,7 +18,6 @@ class BibtexIdCompletionTest : BasePlatformTestCase() { super.setUp() } - @Test fun testCompleteLatexReferences() { // when runCompletion() @@ -30,7 +31,6 @@ class BibtexIdCompletionTest : BasePlatformTestCase() { assertTrue(entry1.allLookupStrings.contains("{Missing the Point(er): On the Effectiveness of Code Pointer Integrity}")) } - @Test fun testCompletionResultsLowerCase() { // when runCompletion() @@ -41,7 +41,6 @@ class BibtexIdCompletionTest : BasePlatformTestCase() { assertTrue(result?.contains("Muchnick1997") == true) } - @Test fun testCompletionResultsSecondEntry() { // when runCompletion() @@ -54,14 +53,12 @@ class BibtexIdCompletionTest : BasePlatformTestCase() { assertTrue(result?.contains("Burow2016") == true) } - @Test fun testCompleteBibtexWithCorrectCase() { // Using the following failed sometimes val testName = getTestName(false) myFixture.testCompletion("${testName}_before.tex", "${testName}_after.tex", "$testName.bib") } - @Test fun testBibtexEntryDocumentation() { runCompletion() val element = DocumentationManager.getInstance(myFixture.project).getElementFromLookup(myFixture.editor, myFixture.file) @@ -78,7 +75,11 @@ class BibtexIdCompletionTest : BasePlatformTestCase() { } private fun runCompletion() { - myFixture.configureByFiles("${getTestName(false)}.tex", "bibtex.bib") + val files = myFixture.configureByFiles("${getTestName(false)}.tex", "bibtex.bib") + // The first time completion runs, due to caching there may be a race condition + for (file in files) { + ReferencedFileSetService.getInstance().referencedFileSetOf(file) + } // when myFixture.complete(CompletionType.BASIC) } diff --git a/test/nl/hannahsten/texifyidea/reference/BibtexIdRemoteLibraryCompletionTest.kt b/test/nl/hannahsten/texifyidea/reference/BibtexIdRemoteLibraryCompletionTest.kt index c650b8257..027a2059b 100644 --- a/test/nl/hannahsten/texifyidea/reference/BibtexIdRemoteLibraryCompletionTest.kt +++ b/test/nl/hannahsten/texifyidea/reference/BibtexIdRemoteLibraryCompletionTest.kt @@ -8,6 +8,7 @@ import nl.hannahsten.texifyidea.remotelibraries.RemoteLibraryManager import nl.hannahsten.texifyidea.remotelibraries.state.BibtexEntryListConverter import nl.hannahsten.texifyidea.remotelibraries.state.LibraryState import nl.hannahsten.texifyidea.remotelibraries.zotero.ZoteroLibrary +import nl.hannahsten.texifyidea.util.files.ReferencedFileSetService class BibtexIdRemoteLibraryCompletionTest : BasePlatformTestCase() { @@ -101,7 +102,10 @@ class BibtexIdRemoteLibraryCompletionTest : BasePlatformTestCase() { mockkObject(RemoteLibraryManager) every { RemoteLibraryManager.getInstance().getLibraries() } returns mutableMapOf("aaa" to LibraryState("mocked", ZoteroLibrary::class.java, BibtexEntryListConverter().fromString(remoteBib), "test url")) - myFixture.configureByFiles("$path/before.tex", "$path/bibtex_before.bib") + myFixture.configureByFiles("$path/before.tex", "$path/bibtex_before.bib").forEach { + // Refresh cache + ReferencedFileSetService.getInstance().referencedFileSetOf(it) + } myFixture.complete(CompletionType.BASIC) From da28600c6e0f67976fb269484157a39426878791 Mon Sep 17 00:00:00 2001 From: Thomas Schouten Date: Sun, 29 Dec 2024 21:17:27 +0100 Subject: [PATCH 6/6] formatting --- .../hannahsten/texifyidea/reference/BibtexIdCompletionTest.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/nl/hannahsten/texifyidea/reference/BibtexIdCompletionTest.kt b/test/nl/hannahsten/texifyidea/reference/BibtexIdCompletionTest.kt index 6eb659ff4..edf8e591a 100644 --- a/test/nl/hannahsten/texifyidea/reference/BibtexIdCompletionTest.kt +++ b/test/nl/hannahsten/texifyidea/reference/BibtexIdCompletionTest.kt @@ -3,9 +3,7 @@ package nl.hannahsten.texifyidea.reference import com.intellij.codeInsight.completion.CompletionType import com.intellij.codeInsight.documentation.DocumentationManager import com.intellij.testFramework.fixtures.BasePlatformTestCase -import nl.hannahsten.texifyidea.util.files.ReferencedFileSetCache import nl.hannahsten.texifyidea.util.files.ReferencedFileSetService -import org.junit.Test class BibtexIdCompletionTest : BasePlatformTestCase() {