use of org.dartlang.analysis.server.protocol.SearchResult in project intellij-plugins by JetBrains.
the class DartServerFindUsagesHandler method processElementUsages.
@Override
public boolean processElementUsages(@NotNull final PsiElement elementToSearch, @NotNull final Processor<UsageInfo> processor, @NotNull final FindUsagesOptions options) {
final SearchScope scope = options.searchScope;
final Project project = ReadAction.compute(this::getProject);
final DartAnalysisServerService service = DartAnalysisServerService.getInstance(project);
final ReadActionConsumer<SearchResult> searchResultProcessor = new ReadActionConsumer<SearchResult>() {
@Override
public void consumeInReadAction(SearchResult result) {
if (result.getKind().equals(SearchResultKind.DECLARATION))
return;
final Location location = result.getLocation();
final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(location.getFile()));
if (vFile == null)
return;
if (!scope.contains(vFile))
return;
final PsiFile psiFile = elementToSearch.getManager().findFile(vFile);
if (psiFile == null)
return;
final int offset = service.getConvertedOffset(vFile, location.getOffset());
final int length = service.getConvertedOffset(vFile, location.getOffset() + location.getLength()) - offset;
final TextRange range = TextRange.create(offset, offset + length);
final boolean potentialUsage = result.isPotential();
final PsiElement usageElement = getUsagePsiElement(psiFile, range);
final UsageInfo usageInfo = usageElement == null ? null : getUsageInfo(usageElement, range, potentialUsage);
if (usageInfo != null && usageInfo.getElement() != null && (!(scope instanceof LocalSearchScope) || PsiSearchScopeUtil.isInScope((LocalSearchScope) scope, usageInfo.getElement()))) {
processor.process(usageInfo);
}
}
};
final VirtualFile file = ReadAction.compute(() -> elementToSearch.getContainingFile().getVirtualFile());
final int offset = elementToSearch.getTextRange().getStartOffset();
service.search_findElementReferences(file, offset, searchResultProcessor);
return true;
}
Aggregations