diff --git a/CHANGELOG.md b/CHANGELOG.md index 53861e483..8be471e84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Added ### Fixed +* Fix exceptions in structure view when command parameters are missing * Fix default Docker image name when running Dockerized TeX Live without a project SDK ## [0.9.9-alpha.3] - 2024-11-12 diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexParagraphPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexParagraphPresentation.kt index e1cd110d3..9f9c584c2 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexParagraphPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexParagraphPresentation.kt @@ -21,7 +21,7 @@ class LatexParagraphPresentation(paragraphCommand: LatexCommands) : EditableHint this.paragraphName = "" } else { - this.paragraphName = paragraphCommand.getRequiredParameters()[0] + this.paragraphName = paragraphCommand.getRequiredParameters().firstOrNull() ?: "Unnamed paragraph" } } diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexPartPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexPartPresentation.kt index 23d459139..a765f7b3a 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexPartPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexPartPresentation.kt @@ -17,7 +17,7 @@ class LatexPartPresentation(partCommand: LatexCommands) : EditableHintPresentati throw IllegalArgumentException("command is no \\part-command") } - this.partName = partCommand.getRequiredParameters()[0] + this.partName = partCommand.getRequiredParameters().firstOrNull() ?: "Unnamed part" } override fun getPresentableText() = partName diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewElement.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewElement.kt index 1dc3b787f..1a56359d9 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewElement.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewElement.kt @@ -13,18 +13,18 @@ import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.util.PsiTreeUtil import nl.hannahsten.texifyidea.file.* import nl.hannahsten.texifyidea.index.LatexCommandsIndex +import nl.hannahsten.texifyidea.lang.commands.LatexGenericRegularCommand import nl.hannahsten.texifyidea.psi.LatexCommands import nl.hannahsten.texifyidea.psi.LatexTypes import nl.hannahsten.texifyidea.settings.TexifySettings import nl.hannahsten.texifyidea.structure.bibtex.BibtexStructureViewElement import nl.hannahsten.texifyidea.structure.latex.SectionNumbering.DocumentClass -import nl.hannahsten.texifyidea.util.parser.allCommands import nl.hannahsten.texifyidea.util.getIncludeCommands -import nl.hannahsten.texifyidea.util.parser.getIncludedFiles import nl.hannahsten.texifyidea.util.labels.getLabelDefinitionCommands import nl.hannahsten.texifyidea.util.magic.CommandMagic +import nl.hannahsten.texifyidea.util.parser.allCommands +import nl.hannahsten.texifyidea.util.parser.getIncludedFiles import java.util.* -import kotlin.collections.ArrayList /** * @author Hannah Schellekens @@ -72,8 +72,8 @@ class LatexStructureViewElement(private val element: PsiElement) : StructureView // Get document class. val scope = GlobalSearchScope.fileScope(element as PsiFile) val docClass = LatexCommandsIndex.Util.getItems(element.getProject(), scope).asSequence() - .filter { cmd -> cmd.commandToken.text == "\\documentclass" && cmd.getRequiredParameters().isNotEmpty() } - .map { cmd -> cmd.getRequiredParameters()[0] } + .filter { cmd -> cmd.name == LatexGenericRegularCommand.DOCUMENTCLASS.commandWithSlash && cmd.getRequiredParameters().isNotEmpty() } + .mapNotNull { cmd -> cmd.getRequiredParameters().firstOrNull() } .firstOrNull() ?: "article" // Fetch all commands in the active file. @@ -87,7 +87,7 @@ class LatexStructureViewElement(private val element: PsiElement) : StructureView // Add sectioning. val sections = ArrayDeque() for (currentCmd in commands) { - val token = currentCmd.commandToken.text + val token = currentCmd.name // Update counter. if (token == "\\addtocounter" || token == "\\setcounter") { diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubParagraphPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubParagraphPresentation.kt index 71abf3b69..1dec33498 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubParagraphPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubParagraphPresentation.kt @@ -13,11 +13,11 @@ class LatexSubParagraphPresentation(subParagraphCommand: LatexCommands) : Editab private var hint = "" init { - if (subParagraphCommand.commandToken.text != "\\subparagraph") { + if (subParagraphCommand.name != "\\subparagraph") { throw IllegalArgumentException("command is no \\subparagraph-command") } - this.subParagraphName = subParagraphCommand.getRequiredParameters()[0] + this.subParagraphName = subParagraphCommand.getRequiredParameters().firstOrNull() ?: "Unknown subparagraph" } override fun getPresentableText() = subParagraphName diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSectionPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSectionPresentation.kt index 2e233d68c..d78628c96 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSectionPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSectionPresentation.kt @@ -17,7 +17,7 @@ class LatexSubSectionPresentation(sectionCommand: LatexCommands) : EditableHintP throw IllegalArgumentException("command is no \\subsection-command") } - this.subSectionName = sectionCommand.getRequiredParameters()[0] + this.subSectionName = sectionCommand.getRequiredParameters().firstOrNull() ?: "Unnamed subsection" } override fun getPresentableText() = subSectionName diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSubSectionPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSubSectionPresentation.kt index e3539d798..64d647858 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSubSectionPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSubSectionPresentation.kt @@ -17,7 +17,7 @@ class LatexSubSubSectionPresentation(sectionCommand: LatexCommands) : EditableHi throw IllegalArgumentException("command is no \\subsubsection-command") } - this.subSubSectionName = sectionCommand.getRequiredParameters()[0] + this.subSubSectionName = sectionCommand.getRequiredParameters().firstOrNull() ?: "Unnamed subsubsection" } override fun getPresentableText() = subSubSectionName