Skip to content

Commit

Permalink
Merge pull request #2678 from Hannah-Sten/crashes
Browse files Browse the repository at this point in the history
Fix exceptions
  • Loading branch information
PHPirates authored Oct 1, 2022
2 parents 106d624 + 2fe6f94 commit dfffc77
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ abstract class TexifyRegexInspection(

val groups = groupFetcher(matcher)
val textRange = highlightRange(matcher)
val startOffset = if (textRange.startOffset < 0) 0 else textRange.startOffset
val endOffset = if (textRange.endOffset > file.textLength) file.textLength else textRange.endOffset
val textRangeFixed = TextRange(startOffset, endOffset)

val range = replacementRange(matcher)
val error = errorMessage(matcher)
val quickFix = quickFixName(matcher)
Expand All @@ -220,7 +224,7 @@ abstract class TexifyRegexInspection(
descriptors.add(
manager.createProblemDescriptor(
file,
textRange,
textRangeFixed,
error,
highlight,
true,
Expand Down
6 changes: 5 additions & 1 deletion src/nl/hannahsten/texifyidea/psi/LatexPsiHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.impl.source.tree.LeafPsiElement
import nl.hannahsten.texifyidea.LatexLanguage
import nl.hannahsten.texifyidea.psi.LatexTypes.*
import nl.hannahsten.texifyidea.util.Log
import nl.hannahsten.texifyidea.util.childrenOfType
import nl.hannahsten.texifyidea.util.findFirstChild
import nl.hannahsten.texifyidea.util.firstChildOfType
Expand Down Expand Up @@ -114,7 +115,7 @@ class LatexPsiHelper(private val project: Project) {
}

/**
* Set the value of the optional parameter with the givevn key name. If the the parameter already exists,
* Set the value of the optional parameter with the given key name. If the parameter already exists,
* its value is changed. If no key with the given name exists yet, a new one is created with the given value.
*
* @param name The name of the parameter to change
Expand Down Expand Up @@ -143,6 +144,9 @@ class LatexPsiHelper(private val project: Project) {
existing
}
else {
if (closeBracket.treeParent != optionalParam.node) {
Log.error("Close bracket is not a child of the optional parameter for ${command.text}, name=$name, value=$value")
}
val comma = createFromText(",").firstChildOfType(LatexNormalText::class)?.firstChild ?: return pair
optionalParam.addBefore(comma, closeBracket)
optionalParam.addBefore(pair, closeBracket)
Expand Down
2 changes: 2 additions & 0 deletions src/nl/hannahsten/texifyidea/util/Log.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ object Log {
fun warn(message: String) = logger.warn("$prefix $message")

fun debug(message: String) = logger.debug("$prefix $message")

fun error(message: String) = logger.error("$prefix $message")
}
1 change: 1 addition & 0 deletions src/nl/hannahsten/texifyidea/util/Projects.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ fun Project.allFiles(type: FileType): Collection<VirtualFile> {
* Get all LaTeX run configurations in the project.
*/
fun Project.getLatexRunConfigurations(): Collection<LatexRunConfiguration> {
if (isDisposed) return emptyList()
return (RunManagerImpl.getInstanceImpl(this) as RunManager).allConfigurationsList.filterIsInstance<LatexRunConfiguration>()
}

Expand Down

0 comments on commit dfffc77

Please sign in to comment.