todo: support searching for todos inside a range, to improve performance (part of IJPL-28717 Todo line lose coloring)

GitOrigin-RevId: e3d44ee80f342985497740fffbe7a76eae5c747e
This commit is contained in:
Alexey Kudravtsev
2024-07-15 16:38:20 +02:00
committed by intellij-monorepo-bot
parent a1fa3b8c52
commit ee26890170
3 changed files with 16 additions and 2 deletions

View File

@@ -46,8 +46,9 @@ public class PsiTodoSearchHelperImpl implements PsiTodoSearchHelper {
public TodoItem @NotNull [] findTodoItems(@NotNull PsiFile file, int startOffset, int endOffset) {
List<TodoItem> occurrences = new ArrayList<>();
TodoItemCreator todoItemCreator = new TodoItemCreator();
boolean multiLine = TodoConfiguration.getInstance().isMultiLine();
for (IndexPatternProvider provider : IndexPatternProvider.EP_NAME.getExtensionList()) {
IndexPatternSearch.search(file, provider, TodoConfiguration.getInstance().isMultiLine()).forEach(occurrence -> {
IndexPatternSearch.search(file, provider, startOffset, endOffset, multiLine).forEach(occurrence -> {
if (occurrence.getTextRange().intersects(startOffset, endOffset)) {
occurrences.add(todoItemCreator.createTodo(occurrence));
}

View File

@@ -129,6 +129,19 @@ public abstract class IndexPatternSearch extends ExtensibleQueryFactory<IndexPat
return getInstance().createQuery(parameters);
}
/**
* Returns a query which can be used to process occurrences of any pattern from the specified provider in the specified text range.
* The query is executed by parsing the contents of the file.
*/
@NotNull
public static Query<IndexPatternOccurrence> search(@NotNull PsiFile file,
@NotNull IndexPatternProvider patternProvider,
int startOffset,
int endOffset, boolean multiLines) {
final SearchParameters parameters = new SearchParameters(file, patternProvider, new TextRange(startOffset, endOffset), multiLines);
return getInstance().createQuery(parameters);
}
/**
* Returns a query which can be used to process occurrences of any pattern from the
* specified provider in the specified file. The query is executed by parsing the

View File

@@ -131,6 +131,6 @@ public final class IndexTodoCacheManagerImpl implements TodoCacheManager {
private static @Nullable Map<TodoIndexEntry, Integer> getTodoMapFromIndex(@NotNull Project project, @NotNull VirtualFile file) {
Map<Integer, Map<TodoIndexEntry, Integer>> map = FileBasedIndexScanUtil.getIndexData(TodoIndex.NAME, project, file);
return map == null ? null : ContainerUtil.getFirstItem(map.values());
return map == null || map.isEmpty() ? null : ContainerUtil.getFirstItem(map.values());
}
}