diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b608fb5f..b3d6baeb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Added * Automatically index bibliography files outside the project that are included by an absolute path * Disable quotes inspection when TeX ligatures are disabled by fontspec +* Inspections can now be suppressed for any single line, or block of text ### Fixed diff --git a/Writerside/topics/Inspections.md b/Writerside/topics/Inspections.md index 08dc1e6d4..a9b186a75 100644 --- a/Writerside/topics/Inspections.md +++ b/Writerside/topics/Inspections.md @@ -9,6 +9,7 @@ If you see a minor bug in an inspection, like some missing metadata about comman Most inspections can be ignored for only a single line, environment or file. To do this, use the format `%! Suppress = MyInspectionName`. The easiest way is usually to use the available context menu on the inspection warning itself. +In some cases, like block of text spanning multiple lines, placing a magic comment in front of it will suppress the inspection for the whole block, instead of for a single line. ![Suppression](suppression-menu.png) diff --git a/src/nl/hannahsten/texifyidea/lang/magic/MagicComments.kt b/src/nl/hannahsten/texifyidea/lang/magic/MagicComments.kt index 88eb90b34..bb9768ed5 100644 --- a/src/nl/hannahsten/texifyidea/lang/magic/MagicComments.kt +++ b/src/nl/hannahsten/texifyidea/lang/magic/MagicComments.kt @@ -5,9 +5,12 @@ package nl.hannahsten.texifyidea.lang.magic import com.intellij.psi.PsiComment import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile +import com.intellij.psi.PsiWhiteSpace +import com.intellij.psi.util.prevLeaf +import com.intellij.psi.util.prevLeafs import nl.hannahsten.texifyidea.psi.* -import nl.hannahsten.texifyidea.util.* import nl.hannahsten.texifyidea.util.files.document +import nl.hannahsten.texifyidea.util.lineIndentationByOffset import nl.hannahsten.texifyidea.util.parser.* import java.util.* @@ -296,7 +299,15 @@ fun PsiElement.magicComment(): MagicComment? = when (this) { is LatexMathEnvironment -> this.magicComment() is LatexCommands -> this.magicComment() is LatexGroup -> this.magicComment() - else -> null + else -> this.commentOnPreviousLine() +} + +/** + * To find any comment at the previous line, we need to check for newlines explicitly. + * Return null if the previous line is not a magic comment. + */ +fun PsiElement.commentOnPreviousLine(): MagicComment? { + return prevLeafs.firstOrNull { it is PsiWhiteSpace && it.text.contains("\n") }?.backwardMagicCommentLookup { prevLeaf(true) } } /**