Skip to content

Commit

Permalink
Merge pull request #3779 from Hannah-Sten/suppress-statement
Browse files Browse the repository at this point in the history
Inspection suppression for a single line
  • Loading branch information
PHPirates authored Dec 3, 2024
2 parents 89e2057 + 0e332b5 commit 04f07ce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
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
* 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

Expand Down
1 change: 1 addition & 0 deletions Writerside/topics/Inspections.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
15 changes: 13 additions & 2 deletions src/nl/hannahsten/texifyidea/lang/magic/MagicComments.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand Down Expand Up @@ -296,7 +299,15 @@ fun PsiElement.magicComment(): MagicComment<String, String>? = 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<String, String>? {
return prevLeafs.firstOrNull { it is PsiWhiteSpace && it.text.contains("\n") }?.backwardMagicCommentLookup { prevLeaf(true) }
}

/**
Expand Down

0 comments on commit 04f07ce

Please sign in to comment.