Skip to content

Commit

Permalink
Fix exceptions in structure view when command parameters are missing, f…
Browse files Browse the repository at this point in the history
…ix #3743
  • Loading branch information
PHPirates committed Nov 13, 2024
1 parent ebee52d commit f295ed3
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LatexParagraphPresentation(paragraphCommand: LatexCommands) : EditableHint
this.paragraphName = ""
}
else {
this.paragraphName = paragraphCommand.getRequiredParameters()[0]
this.paragraphName = paragraphCommand.getRequiredParameters().firstOrNull() ?: "Unnamed paragraph"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -87,7 +87,7 @@ class LatexStructureViewElement(private val element: PsiElement) : StructureView
// Add sectioning.
val sections = ArrayDeque<LatexStructureViewCommandElement>()
for (currentCmd in commands) {
val token = currentCmd.commandToken.text
val token = currentCmd.name

// Update counter.
if (token == "\\addtocounter" || token == "\\setcounter") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f295ed3

Please sign in to comment.