From 4b958d927cf94f7ea08098c14eb8b66961a5bb4a Mon Sep 17 00:00:00 2001 From: Thomas Schouten Date: Thu, 14 Nov 2024 13:57:42 +0100 Subject: [PATCH 1/4] Support references in \subfix command --- CHANGELOG.md | 1 + .../texifyidea/util/parser/LatexCommandsImplMixinUtil.kt | 5 +++++ .../texifyidea/reference/InputFileReferenceTest.kt | 6 ++++++ test/resources/reference/subfix/main-after.tex | 7 +++++++ test/resources/reference/subfix/main.tex | 7 +++++++ test/resources/reference/subfix/subdir2/chapter2.tex | 6 ++++++ test/resources/reference/subfix/subdir2/references.bib | 6 ++++++ 7 files changed, 38 insertions(+) create mode 100644 test/resources/reference/subfix/main-after.tex create mode 100644 test/resources/reference/subfix/main.tex create mode 100644 test/resources/reference/subfix/subdir2/chapter2.tex create mode 100644 test/resources/reference/subfix/subdir2/references.bib diff --git a/CHANGELOG.md b/CHANGELOG.md index 69b1d5e1b..99b4d306f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased] ### Added +* Support references in \subfix command ### Fixed diff --git a/src/nl/hannahsten/texifyidea/util/parser/LatexCommandsImplMixinUtil.kt b/src/nl/hannahsten/texifyidea/util/parser/LatexCommandsImplMixinUtil.kt index 432aa4826..5efd15c18 100644 --- a/src/nl/hannahsten/texifyidea/util/parser/LatexCommandsImplMixinUtil.kt +++ b/src/nl/hannahsten/texifyidea/util/parser/LatexCommandsImplMixinUtil.kt @@ -50,6 +50,11 @@ fun LatexCommands.getFileArgumentsReferences(): List { it.shiftRight(requiredParameter.textOffset - this.textOffset) } } + else if (requiredParameter.firstChildOfType(LatexParameterText::class)?.children?.size == 1 && requiredParameter.firstChildOfType(LatexCommands::class) != null) { + // Special case if there is a single command instead of text, we ignore it. Example: \subfix from the subfiles package, can be ignored for our purposes + val newRequiredParameter = requiredParameter.firstChildOfType(LatexCommands::class)?.requiredParameters()?.firstOrNull() ?: requiredParameter + listOf(newRequiredParameter.textRange.shrink(1).shiftLeft(this.textOffset)) + } else { listOf(requiredParameter.textRange.shrink(1).shiftLeft(this.textOffset)) } diff --git a/test/nl/hannahsten/texifyidea/reference/InputFileReferenceTest.kt b/test/nl/hannahsten/texifyidea/reference/InputFileReferenceTest.kt index 7b4ac76ad..01d004520 100644 --- a/test/nl/hannahsten/texifyidea/reference/InputFileReferenceTest.kt +++ b/test/nl/hannahsten/texifyidea/reference/InputFileReferenceTest.kt @@ -28,4 +28,10 @@ class InputFileReferenceTest : BasePlatformTestCase() { myFixture.renameElementAtCaret("newmain.tex") myFixture.checkResultByFile("simplesubfile/subdir/onedown-after.tex") } + + fun testRenameSubfix() { + myFixture.configureByFiles("subfix/main.tex", "subfix/subdir2/chapter2.tex", "subfix/subdir2/references.bib") + myFixture.renameElementAtCaret("newreferences.bib") + myFixture.checkResultByFile("subfix/main-after.tex") + } } \ No newline at end of file diff --git a/test/resources/reference/subfix/main-after.tex b/test/resources/reference/subfix/main-after.tex new file mode 100644 index 000000000..31f1062d8 --- /dev/null +++ b/test/resources/reference/subfix/main-after.tex @@ -0,0 +1,7 @@ +\documentclass[11pt]{report} +\usepackage{subfiles} +\usepackage{biblatex} +\addbibresource{\subfix{subdir2/newreferences.bib}} +\begin{document} + \subfile{subdir2/chapter2.tex} +\end{document} \ No newline at end of file diff --git a/test/resources/reference/subfix/main.tex b/test/resources/reference/subfix/main.tex new file mode 100644 index 000000000..60a334cbb --- /dev/null +++ b/test/resources/reference/subfix/main.tex @@ -0,0 +1,7 @@ +\documentclass[11pt]{report} +\usepackage{subfiles} +\usepackage{biblatex} +\addbibresource{\subfix{subdir2/references.bib}} +\begin{document} + \subfile{subdir2/chapter2.tex} +\end{document} \ No newline at end of file diff --git a/test/resources/reference/subfix/subdir2/chapter2.tex b/test/resources/reference/subfix/subdir2/chapter2.tex new file mode 100644 index 000000000..c17bbfc20 --- /dev/null +++ b/test/resources/reference/subfix/subdir2/chapter2.tex @@ -0,0 +1,6 @@ +\documentclass[../main.tex]{subfiles} +\begin{document} + \chapter{Some 2} + I~\cite{tectonic} + \printbibliography +\end{document} \ No newline at end of file diff --git a/test/resources/reference/subfix/subdir2/references.bib b/test/resources/reference/subfix/subdir2/references.bib new file mode 100644 index 000000000..4758ffee3 --- /dev/null +++ b/test/resources/reference/subfix/subdir2/references.bib @@ -0,0 +1,6 @@ +@online{tectonic, + title = {The Tectonic Typesetting System — The Tectonic Typesetting System}, + url = {https://tectonic-typesetting.github.io/en-US/index.html}, + urldate = {2018-12-27}, +} + From 22fc7e52373656a9837f058639bd19c65ec55089 Mon Sep 17 00:00:00 2001 From: Thomas Schouten Date: Thu, 14 Nov 2024 14:06:40 +0100 Subject: [PATCH 2/4] Add subfix command to fix gutter icons --- .../texifyidea/lang/commands/LatexGenericRegularCommand.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/nl/hannahsten/texifyidea/lang/commands/LatexGenericRegularCommand.kt b/src/nl/hannahsten/texifyidea/lang/commands/LatexGenericRegularCommand.kt index ff628bfc5..e7b156501 100644 --- a/src/nl/hannahsten/texifyidea/lang/commands/LatexGenericRegularCommand.kt +++ b/src/nl/hannahsten/texifyidea/lang/commands/LatexGenericRegularCommand.kt @@ -287,6 +287,7 @@ enum class LatexGenericRegularCommand( STRETCH("stretch", "factor".asRequired()), SUBFILE("subfile", RequiredFileArgument("sourcefile", true, false, "tex"), dependency = LatexPackage.SUBFILES), SUBFILEINCLUDE("subfileinclude", RequiredFileArgument("sourcefile", true, false, "tex"), dependency = LatexPackage.SUBFILES), + SUBFIX("subfix", RequiredFileArgument("file", true, false, "tex"), dependency = LatexPackage.SUBFILES), SUBIMPORT("subimport", RequiredFolderArgument("relative path"), RequiredFileArgument("filename", false, false, "tex"), dependency = LatexPackage.IMPORT), SUBINCLUDEFROM("subincludefrom", RequiredFolderArgument("relative path"), RequiredFileArgument("filename", false, false, "tex"), dependency = LatexPackage.IMPORT), SUBINPUTFROM("subinputfrom"), From 2b80d1fe536a60db002096c1950172bbaa0b6b6a Mon Sep 17 00:00:00 2001 From: Thomas Schouten Date: Sun, 24 Nov 2024 18:30:17 +0100 Subject: [PATCH 3/4] Provide autocompletion for all relevant directories when using subfiles --- CHANGELOG.md | 1 + .../texifyidea/completion/LatexCompletionContributor.kt | 4 ++-- .../completion/pathcompletion/LatexPathProviderBase.kt | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99b4d306f..e5f2b36d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Added * Support references in \subfix command +* Provide autocompletion for all relevant directories when using subfiles ### Fixed diff --git a/src/nl/hannahsten/texifyidea/completion/LatexCompletionContributor.kt b/src/nl/hannahsten/texifyidea/completion/LatexCompletionContributor.kt index f2f08f3e6..74633d1f8 100644 --- a/src/nl/hannahsten/texifyidea/completion/LatexCompletionContributor.kt +++ b/src/nl/hannahsten/texifyidea/completion/LatexCompletionContributor.kt @@ -97,7 +97,7 @@ open class LatexCompletionContributor : CompletionContributor() { .inside(LatexRequiredParam::class.java) .withPattern("File name completion pattern") { psiElement, processingContext -> val command = getParentOfType(psiElement, LatexCommands::class.java) ?: return@withPattern false - val name = command.commandToken.text + val name = command.name ?: return@withPattern false val cmd = LatexRegularCommand[name.substring(1)] ?: return@withPattern false val args = cmd.first().getArgumentsOf(RequiredFileArgument::class) @@ -117,7 +117,7 @@ open class LatexCompletionContributor : CompletionContributor() { .inside(LatexRequiredParam::class.java) .withPattern("Folder name completion pattern") { psiElement, processingContext -> val command = getParentOfType(psiElement, LatexCommands::class.java) ?: return@withPattern false - val name = command.commandToken.text + val name = command.name ?: return@withPattern false val cmd = LatexRegularCommand[name.substring(1)] ?: return@withPattern false val args = cmd.first().getArgumentsOf(RequiredFolderArgument::class) diff --git a/src/nl/hannahsten/texifyidea/completion/pathcompletion/LatexPathProviderBase.kt b/src/nl/hannahsten/texifyidea/completion/pathcompletion/LatexPathProviderBase.kt index 25c6911dc..245347d93 100644 --- a/src/nl/hannahsten/texifyidea/completion/pathcompletion/LatexPathProviderBase.kt +++ b/src/nl/hannahsten/texifyidea/completion/pathcompletion/LatexPathProviderBase.kt @@ -20,6 +20,7 @@ import nl.hannahsten.texifyidea.lang.commands.RequiredFileArgument import nl.hannahsten.texifyidea.psi.LatexRequiredParam import nl.hannahsten.texifyidea.util.expandCommandsOnce import nl.hannahsten.texifyidea.util.files.findRootFile +import nl.hannahsten.texifyidea.util.files.findRootFiles import nl.hannahsten.texifyidea.util.files.isLatexFile import nl.hannahsten.texifyidea.util.replaceAfterFrom import java.io.File @@ -205,8 +206,8 @@ abstract class LatexPathProviderBase : CompletionProvider( val baseFile = this.originalFile.virtualFile if (this.originalFile.isLatexFile()) { - this.originalFile.findRootFile().containingDirectory?.virtualFile?.apply { - resultList.add(this) + this.originalFile.findRootFiles().mapNotNull { it.containingDirectory?.virtualFile }.forEach { + resultList.add(it) } } else resultList.add(baseFile.parent) From 88e844a02176a4b8a5c823a3199c5d1e23b0bd67 Mon Sep 17 00:00:00 2001 From: Thomas Schouten Date: Sun, 24 Nov 2024 19:27:06 +0100 Subject: [PATCH 4/4] Unused import --- .../completion/pathcompletion/LatexPathProviderBase.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/nl/hannahsten/texifyidea/completion/pathcompletion/LatexPathProviderBase.kt b/src/nl/hannahsten/texifyidea/completion/pathcompletion/LatexPathProviderBase.kt index 245347d93..1ef9b41d9 100644 --- a/src/nl/hannahsten/texifyidea/completion/pathcompletion/LatexPathProviderBase.kt +++ b/src/nl/hannahsten/texifyidea/completion/pathcompletion/LatexPathProviderBase.kt @@ -19,7 +19,6 @@ import nl.hannahsten.texifyidea.completion.handlers.LatexReferenceInsertHandler import nl.hannahsten.texifyidea.lang.commands.RequiredFileArgument import nl.hannahsten.texifyidea.psi.LatexRequiredParam import nl.hannahsten.texifyidea.util.expandCommandsOnce -import nl.hannahsten.texifyidea.util.files.findRootFile import nl.hannahsten.texifyidea.util.files.findRootFiles import nl.hannahsten.texifyidea.util.files.isLatexFile import nl.hannahsten.texifyidea.util.replaceAfterFrom