Skip to content

Commit

Permalink
Todo commands work except highlighting in the editor
Browse files Browse the repository at this point in the history
  • Loading branch information
slideclimb committed Nov 24, 2024
1 parent 1467dcb commit edd1bc6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
1 change: 1 addition & 0 deletions resources/META-INF/extensions/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<fileBasedIndex implementation="nl.hannahsten.texifyidea.index.file.LatexExternalPackageInclusionIndex" />
<indexedRootsProvider implementation="nl.hannahsten.texifyidea.index.file.LatexIndexableSetContributor" />
<indexPatternSearch implementation="nl.hannahsten.texifyidea.index.LatexTodoSearcher"/>
<indexPatternProvider implementation="nl.hannahsten.texifyidea.index.LatexTodoIndexPatternProvider"/>
<todoIndexer filetype="LaTeX source file" implementationClass="nl.hannahsten.texifyidea.index.LatexTodoIndexer"/>
</extensions>
</idea-plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package nl.hannahsten.texifyidea.index

import com.intellij.psi.search.IndexPattern
import com.intellij.psi.search.IndexPatternProvider
import nl.hannahsten.texifyidea.util.magic.CommandMagic

class LatexTodoIndexPatternProvider : IndexPatternProvider {
override fun getIndexPatterns(): Array<IndexPattern> {
return CommandMagic.todoCommands.map { IndexPattern("${it.replace("\\", "\\\\")}\\b", true) }.toTypedArray()
}
}
18 changes: 10 additions & 8 deletions src/nl/hannahsten/texifyidea/index/LatexTodoIndexer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ import nl.hannahsten.texifyidea.util.magic.CommandMagic
*/
class LatexTodoIndexer : LexerBasedTodoIndexer() {
override fun createLexer(consumer: OccurrenceConsumer): Lexer {
return object : BaseFilterLexer(LatexLexerAdapter(), consumer) {
override fun advance() {
val tokenType = delegate.tokenType
if (tokenType in LatexTokenSets.COMMENTS || (tokenType == LatexTypes.COMMAND_TOKEN && delegate.tokenText in CommandMagic.todoCommands)) {
advanceTodoItemCountsInToken()
}
delegate.advance()
}
return LatexFilterLexer(consumer)
}
}

class LatexFilterLexer(consumer: OccurrenceConsumer) : BaseFilterLexer(LatexLexerAdapter(), consumer) {
override fun advance() {
val tokenType = delegate.tokenType
if (tokenType in LatexTokenSets.COMMENTS || (tokenType == LatexTypes.COMMAND_TOKEN && delegate.tokenText in CommandMagic.todoCommands)) {
advanceTodoItemCountsInToken()
}
delegate.advance()
}
}
15 changes: 7 additions & 8 deletions src/nl/hannahsten/texifyidea/index/LatexTodoSearcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.intellij.util.Processor
import nl.hannahsten.texifyidea.file.LatexFile
import nl.hannahsten.texifyidea.util.files.commandsInFile
import nl.hannahsten.texifyidea.util.magic.CommandMagic
import nl.hannahsten.texifyidea.util.matches

/**
* Provides the "to do" item in the toolwindow and highlighting in the editor.
Expand All @@ -18,15 +19,13 @@ import nl.hannahsten.texifyidea.util.magic.CommandMagic
class LatexTodoSearcher : QueryExecutorBase<IndexPatternOccurrence, IndexPatternSearch.SearchParameters>() {
override fun processQuery(queryParameters: IndexPatternSearch.SearchParameters, consumer: Processor<in IndexPatternOccurrence>) {
val file = queryParameters.file as? LatexFile ?: return
val pattern = queryParameters.pattern
?: queryParameters.patternProvider.indexPatterns.firstOrNull { it.patternString.contains("todo", true) }
?: return

file.commandsInFile().filter { it.name in CommandMagic.todoCommands }
.forEach {
println("${it.text}: ${it.textRange}")
consumer.process(LatexTodoOccurrence(file, it.textRange, pattern))
}
queryParameters.patternProvider.indexPatterns.forEach { pattern ->
file.commandsInFile().filter { it.name in CommandMagic.todoCommands }.filter { pattern.pattern?.matches(it.name) == true }
.forEach {
consumer.process(LatexTodoOccurrence(file, it.textRange, pattern))
}
}
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/nl/hannahsten/texifyidea/util/magic/CommandMagic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,7 @@ object CommandMagic {
)

/**
* Commands that should be contributed to the todo toolwindow.
* Commands that should be contributed to the to do toolwindow.
*/
val todoCommands = setOf(
LatexTodoCommand.TODO.cmd, LatexTodoCommand.MISSINGFIGURE.cmd
)
val todoCommands = setOf(LatexTodoCommand.TODO.cmd, LatexTodoCommand.MISSINGFIGURE.cmd)
}

0 comments on commit edd1bc6

Please sign in to comment.