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:

  1. Add a todo indexer to the plugin.xml
  2. Create a AsciiDocTodoIndexer
  3. Create a AsciiDocIdIndexer
  4. Create a AsciiDocFilterLexer

plugin.xml
 
<todoIndexer filetype="AsciiDoc" implementationClass="org.asciidoc.intellij.todo.AsciiDocTodoIndexer"/>     


AsciiDocTodoIndexer
 
public class AsciiDocTodoIndexer extends LexerBasedTodoIndexer {

  @Override
  public
Lexer createLexer(OccurrenceConsumer consumer) {
    return AsciiDocIdIndexer.createIndexingLexer(consumer);
  }
}


AsciiDocIdIndexer
 
public 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);
  }
}


AsciiDocFilterLexer
 
public 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

0

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.

0

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...

<extensions defaultExtensionNs="com.intellij">
  <fileTypeFactory implementation="org.asciidoc.intellij.file.AsciiDocFileTypeFactory"/>
  <fileEditorProvider implementation="org.asciidoc.intellij.editor.AsciiDocPreviewEditorProvider"/>
  <todoIndexer filetype="AsciiDoc" implementationClass="org.asciidoc.intellij.todo.AsciiDocTodoIndexer"/>
</extensions>



But my AsciiDocFileType looks like this:

public class AsciiDocFileType extends LanguageFileType {

  /** The {@link AsciiDocFileType} instance. */
  public static final
AsciiDocFileType INSTANCE = new AsciiDocFileType();
  /** . */
  public static final
String[] DEFAULT_ASSOCIATED_EXTENSIONS = {"adoc", "asciidoc", "ad", "asc"};

  public AsciiDocFileType() {
    super(new AsciiDocLanguage());
  }

  @NotNull
  public
String getName() {
    return "AsciiDoc";
  }

  @NotNull
  public
String getDescription() {
    return "AsciiDoc files";
  }

  @NotNull
  public
String getDefaultExtension() {
    return DEFAULT_ASSOCIATED_EXTENSIONS[0];
  }

  @Nullable
  public
Icon getIcon() {
    return AsciiDocIcons.ASCIIDOC_ICON;
  }
}


So I thought that would be okay.

Any idea how I can debug this?

0

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!

0

Hi guys,

I'm still stuck with this. Anyone got a suggestion?

Erik

0

Try to use this as todoIndexer implementation (just for checking) for your file type:

implementationClass="com.intellij.psi.impl.cache.impl.id.PlatformIdTableBuilding$PlainTextTodoIndexer"


This should add some TODO occurrences to TODO tool window. Let me now if it's working.

0

Hi Marcin,

Thanks for the reply. I've done what you said, and my plugin.xml now looks like this:

 
<extensions defaultExtensionNs="com.intellij">
  <fileTypeFactory implementation="org.asciidoc.intellij.file.AsciiDocFileTypeFactory"/>
  <fileEditorProvider implementation="org.asciidoc.intellij.editor.AsciiDocPreviewEditorProvider"/>
  <todoIndexer filetype="AsciiDoc" implementationClass="com.intellij.psi.impl.cache.impl.id.PlatformIdTableBuilding$PlainTextTodoIndexer" />
</extensions>


However, whenever I type a TODO in an .adoc file, no item is added to the TODO view..

0

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.

0

请先登录再写评论。