How to add items to the TODO panel
Hi guys,
I have TODO items in my AsciiDoc documents, and I'd like to add them to IntelliJ's todo Panel. How can I accomplish such a feat?
(In the meantime, I checked the Markdown plugin, and copied some of their work. Unfortunately, it doesn't work. What I did was the following:
- Add a todo indexer to the plugin.xml
- Create a AsciiDocTodoIndexer
- Create a AsciiDocIdIndexer
- Create a AsciiDocFilterLexer
plugin.xml
<todoIndexer filetype="AsciiDoc" implementationClass="org.asciidoc.intellij.todo.AsciiDocTodoIndexer"/>
AsciiDocTodoIndexerpublic class AsciiDocTodoIndexer extends LexerBasedTodoIndexer {
@Override
public Lexer createLexer(OccurrenceConsumer consumer) {
return AsciiDocIdIndexer.createIndexingLexer(consumer);
}
}
AsciiDocIdIndexerpublic class AsciiDocIdIndexer extends LexerBasedIdIndexer {
public static Lexer createIndexingLexer(OccurrenceConsumer consumer) {
return new AsciiDocFilterLexer(new EmptyLexer(), consumer);
}
@Override
public Lexer createLexer(final OccurrenceConsumer consumer) {
return createIndexingLexer(consumer);
}
}
AsciiDocFilterLexerpublic class AsciiDocFilterLexer extends BaseFilterLexer {
public AsciiDocFilterLexer(final Lexer originalLexer, final OccurrenceConsumer table) {
super(originalLexer, table);
}
@Override
public void advance() {
scanWordsInToken(UsageSearchContext.IN_PLAIN_TEXT, false, false);
advanceTodoItemCountsInToken();
myDelegate.advance();
}
}
I'm not sure why, and if, I need them, but the Markdown plugin has it, so I thought it would be a good idea to copy. However, none of the TODO's in my AsciiDoc are added. Comments in AsciiDoc can look like this:
//TODO: this is my comment
This is also possible:
//// TODO: another comment here! This part is hidden and not important ////
It would be nice to see these comments in the TODO panel.
Thanks!!
Erik
请先登录再写评论。
I don't see anything wrong with the code at first glance (it's a hack because it parses the entire contents of a file as a single token, but this should still work).
Can you verify whether your TODO indexer is actually called?
Note that, since you don't have a lexer that would be able to distinguish comments from non-comments, your code would detect TODOs anywhere where such a string is encountered in a file, not just in comments.
Hi Dmitry,
Thanks for the quick response. I've added debug points to all methods of the TODO parser, and IntelliJ breaks at none of them, so it seems like it's indeed not called.
Could it be that the line with the todoIndexer might be wrong? I'm not sure what the filetype points to exactly, and what it should match with...
But my AsciiDocFileType looks like this:
So I thought that would be okay.
Any idea how I can debug this?
PS: thanks about the remark about TODO's, but this is the first step. Implementing the full Lexer would be very time consuming, especially since I have never done anything like that before, so I think I'll stick to the poor man's version for now. If I can get it to work, that is... Thanks again!
Hi guys,
I'm still stuck with this. Anyone got a suggestion?
Erik
Try to use this as todoIndexer implementation (just for checking) for your file type:
This should add some TODO occurrences to TODO tool window. Let me now if it's working.
Hi Marcin,
Thanks for the reply. I've done what you said, and my plugin.xml now looks like this:
Are You sure that your plugin is up to date while you are debugging it? Did You try to refresh indices (File > Invalidate caches)? I'm pretty sure that this should collect every todo/fixme phrase in file.