-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into minted-env
# Conflicts: # CHANGELOG.md
- Loading branch information
Showing
25 changed files
with
264 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
resources/inspectionDescriptions/LatexMissingGlossaryReference.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<html> | ||
<body> | ||
Reports occurrences of glossary entries that are not marked with a \gls command. | ||
<!-- tooltip end --> | ||
<p> | ||
When using a glossary, it is good practice to reference every glossary entry with a \gls-like command. | ||
This makes sure that the list of pages with occurrences in the glossary is complete. | ||
</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...hsten/texifyidea/inspections/latex/typesetting/LatexMissingGlossaryReferenceInspection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package nl.hannahsten.texifyidea.inspections.latex.typesetting | ||
|
||
import com.intellij.codeInspection.InspectionManager | ||
import com.intellij.codeInspection.LocalQuickFix | ||
import com.intellij.codeInspection.ProblemDescriptor | ||
import com.intellij.codeInspection.ProblemHighlightType | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiFile | ||
import nl.hannahsten.texifyidea.index.LatexGlossaryEntryIndex | ||
import nl.hannahsten.texifyidea.inspections.InsightGroup | ||
import nl.hannahsten.texifyidea.inspections.TexifyInspectionBase | ||
import nl.hannahsten.texifyidea.lang.commands.LatexGlossariesCommand | ||
import nl.hannahsten.texifyidea.psi.LatexNormalText | ||
import nl.hannahsten.texifyidea.psi.LatexPsiHelper | ||
import nl.hannahsten.texifyidea.util.parser.childrenOfType | ||
import nl.hannahsten.texifyidea.util.toTextRange | ||
|
||
/** | ||
* Glossary entries should be referenced for all occurrences. | ||
*/ | ||
class LatexMissingGlossaryReferenceInspection : TexifyInspectionBase() { | ||
override val inspectionGroup = InsightGroup.LATEX | ||
override val inspectionId = "MissingGlossaryReference" | ||
override fun getDisplayName() = "Missing glossary reference" | ||
|
||
override fun inspectFile(file: PsiFile, manager: InspectionManager, isOntheFly: Boolean): List<ProblemDescriptor> { | ||
val descriptors = mutableListOf<ProblemDescriptor>() | ||
val names = LatexGlossaryEntryIndex.Util.getItemsInFileSet(file).mapNotNull { LatexGlossariesCommand.extractGlossaryName(it) } | ||
// Unfortunately the lowest level we have is a block of text, so we have to do a text-based search | ||
file.childrenOfType<LatexNormalText>().forEach { textElement -> | ||
val text = textElement.text | ||
names.forEach { name -> | ||
val correctOccurrences = "\\\\gls[^{]+\\{($name)}".toRegex().findAll(text).mapNotNull { it.groups.firstOrNull()?.range } | ||
val allOccurrences = name.toRegex().findAll(text).map { it.range } | ||
allOccurrences.filter { !correctOccurrences.contains(it) }.forEach { range -> | ||
descriptors.add( | ||
manager.createProblemDescriptor( | ||
textElement, | ||
range.toTextRange(), | ||
"Missing glossary reference", | ||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, | ||
isOntheFly, | ||
AddGlsFix(), | ||
) | ||
) | ||
} | ||
} | ||
} | ||
return descriptors | ||
} | ||
|
||
private class AddGlsFix : LocalQuickFix { | ||
override fun getFamilyName() = "Add \\gls command" | ||
|
||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) { | ||
val range = descriptor.textRangeInElement | ||
val newText = descriptor.psiElement.text.replaceRange(range.endOffset, range.endOffset, "}") | ||
.replaceRange(range.startOffset, range.startOffset, "\\gls{") | ||
|
||
val newElement = LatexPsiHelper(project).createFromText(newText).firstChild | ||
descriptor.psiElement.replace(newElement) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.