Process todo in docstrings (PY-11040)

This commit is contained in:
Dmitry Trofimov
2017-09-11 19:38:27 +03:00
parent fee6e2c22d
commit 35cbb00d8b
2 changed files with 22 additions and 0 deletions
@@ -58,6 +58,9 @@ public class PyFilterLexer extends BaseFilterLexer {
}
else if (PyTokenTypes.STRING_NODES.contains(tokenType)) {
scanWordsInToken(UsageSearchContext.IN_STRINGS | UsageSearchContext.IN_FOREIGN_LANGUAGES, false, true);
if (tokenType == PyTokenTypes.DOCSTRING) {
advanceTodoItemCountsInToken();
}
}
else if (PyIndexPatternBuilder.COMMENTS.contains(tokenType)) {
scanWordsInToken(UsageSearchContext.IN_COMMENTS, false, false);
@@ -44,4 +44,23 @@ public class PyTodoTest extends LightPlatformCodeInsightFixtureTestCase {
todo.setTodoPatterns(oldPatterns);
}
}
public void testTodoInDocstrings() {
myFixture.configureByText(PythonFileType.INSTANCE, "''' TODO: return dead parrot '''");
TodoItem[] items = PsiTodoSearchHelper.SERVICE.getInstance(getProject()).findTodoItems(myFixture.getFile());
assertEquals(1, items.length);
}
public void testTodoInDocstrings2() {
myFixture.configureByText(PythonFileType.INSTANCE, "def foo():\n''' TODO: return dead parrot '''");
TodoItem[] items = PsiTodoSearchHelper.SERVICE.getInstance(getProject()).findTodoItems(myFixture.getFile());
assertEquals(1, items.length);
}
public void testTodoInTripleQuotedString() {
myFixture.configureByText(PythonFileType.INSTANCE, "s = ''' TODO: return dead parrot '''");
TodoItem[] items = PsiTodoSearchHelper.SERVICE.getInstance(getProject()).findTodoItems(myFixture.getFile());
assertEquals(0, items.length); // no todo in normal triple quoted strings
}
}