-
-
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.
Support todonotes commands as todo items, fixes #3673
- Loading branch information
1 parent
836552b
commit e29fc91
Showing
7 changed files
with
99 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package nl.hannahsten.texifyidea.index | ||
|
||
import com.intellij.lexer.Lexer | ||
import com.intellij.psi.impl.cache.impl.BaseFilterLexer | ||
import com.intellij.psi.impl.cache.impl.OccurrenceConsumer | ||
import com.intellij.psi.impl.cache.impl.todo.LexerBasedTodoIndexer | ||
import nl.hannahsten.texifyidea.grammar.LatexLexerAdapter | ||
import nl.hannahsten.texifyidea.psi.LatexTypes | ||
import nl.hannahsten.texifyidea.util.magic.CommandMagic | ||
|
||
/** | ||
* Counts the "to do" item, so that it shows up in the Project "to do" window and the count of the number of items is correct. | ||
*/ | ||
class LatexTodoIndexer : LexerBasedTodoIndexer() { | ||
override fun createLexer(consumer: OccurrenceConsumer): Lexer { | ||
return object : BaseFilterLexer(LatexLexerAdapter(), consumer) { | ||
override fun advance() { | ||
val tokenType = delegate.tokenType | ||
if (tokenType == LatexTypes.COMMAND_TOKEN && delegate.tokenText in CommandMagic.todoCommands) { | ||
advanceTodoItemCountsInToken() | ||
} | ||
delegate.advance() | ||
} | ||
} | ||
} | ||
} |
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,37 @@ | ||
package nl.hannahsten.texifyidea.index | ||
|
||
import com.intellij.openapi.application.QueryExecutorBase | ||
import com.intellij.openapi.util.TextRange | ||
import com.intellij.psi.PsiFile | ||
import com.intellij.psi.search.IndexPattern | ||
import com.intellij.psi.search.IndexPatternOccurrence | ||
import com.intellij.psi.search.searches.IndexPatternSearch | ||
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 | ||
|
||
/** | ||
* Provides the "to do" item in the toolwindow and highlighting in the editor. | ||
*/ | ||
@Suppress("UnstableApiUsage") | ||
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)) | ||
} | ||
} | ||
} | ||
|
||
private data class LatexTodoOccurrence(private val file: LatexFile, private val textRange: TextRange, private val pattern: IndexPattern) : IndexPatternOccurrence { | ||
override fun getFile(): PsiFile = file | ||
override fun getTextRange(): TextRange = textRange | ||
override fun getPattern(): IndexPattern = pattern | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/nl/hannahsten/texifyidea/lang/commands/LatexTodoCommand.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,23 @@ | ||
package nl.hannahsten.texifyidea.lang.commands | ||
|
||
import nl.hannahsten.texifyidea.lang.LatexPackage | ||
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.ALGPSEUDOCODE | ||
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.TODONOTES | ||
|
||
enum class LatexTodoCommand( | ||
override val command: String, | ||
override vararg val arguments: Argument = emptyArray(), | ||
override val dependency: LatexPackage = LatexPackage.DEFAULT, | ||
override val display: String? = null, | ||
override val isMathMode: Boolean = false, | ||
val collapse: Boolean = false | ||
) : LatexCommand { | ||
|
||
TODO("todo", "note".asRequired(), dependency = TODONOTES), | ||
MISSINGFIGURE("missingfigure", "note".asRequired(), dependency = TODONOTES), | ||
LISTOFTODOS("listoftodos", "name".asOptional(), dependency = TODONOTES) | ||
; | ||
|
||
override val identifier: String | ||
get() = name | ||
} |
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