Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exceptions in structure view when command parameters are missing #3747

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
Loading