Search in sources :

Example 11 with FindManagerImpl

use of com.intellij.find.impl.FindManagerImpl in project intellij-community by JetBrains.

the class PsiElement2UsageTargetAdapter method highlightUsages.

@Override
public void highlightUsages(@NotNull PsiFile file, @NotNull Editor editor, boolean clearHighlights) {
    PsiElement target = getElement();
    if (file instanceof PsiCompiledFile)
        file = ((PsiCompiledFile) file).getDecompiledPsiFile();
    Project project = target.getProject();
    final FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(project)).getFindUsagesManager();
    final FindUsagesHandler handler = findUsagesManager.getFindUsagesHandler(target, true);
    // in case of injected file, use host file to highlight all occurrences of the target in each injected file
    PsiFile context = InjectedLanguageManager.getInstance(project).getTopLevelFile(file);
    SearchScope searchScope = new LocalSearchScope(context);
    Collection<PsiReference> refs = handler == null ? ReferencesSearch.search(target, searchScope, false).findAll() : handler.findReferencesToHighlight(target, searchScope);
    new HighlightUsagesHandler.DoHighlightRunnable(new ArrayList<>(refs), project, target, editor, context, clearHighlights).run();
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) HighlightUsagesHandler(com.intellij.codeInsight.highlighting.HighlightUsagesHandler) ArrayList(java.util.ArrayList) FindManagerImpl(com.intellij.find.impl.FindManagerImpl) Project(com.intellij.openapi.project.Project) SearchScope(com.intellij.psi.search.SearchScope) LocalSearchScope(com.intellij.psi.search.LocalSearchScope)

Example 12 with FindManagerImpl

use of com.intellij.find.impl.FindManagerImpl in project intellij-community by JetBrains.

the class FindInProjectManager method startFindInProject.

public void startFindInProject(@NotNull FindModel findModel) {
    if (findModel.getDirectoryName() != null && FindInProjectUtil.getDirectory(findModel) == null) {
        return;
    }
    com.intellij.usages.UsageViewManager manager = com.intellij.usages.UsageViewManager.getInstance(myProject);
    if (manager == null)
        return;
    final FindManager findManager = FindManager.getInstance(myProject);
    findManager.getFindInProjectModel().copyFrom(findModel);
    final FindModel findModelCopy = findModel.clone();
    final UsageViewPresentation presentation = FindInProjectUtil.setupViewPresentation(FindSettings.getInstance().isShowResultsInSeparateView(), findModelCopy);
    final boolean showPanelIfOnlyOneUsage = !FindSettings.getInstance().isSkipResultsWithOneUsage();
    final FindUsagesProcessPresentation processPresentation = FindInProjectUtil.setupProcessPresentation(myProject, showPanelIfOnlyOneUsage, presentation);
    ConfigurableUsageTarget usageTarget = new FindInProjectUtil.StringUsageTarget(myProject, findModel);
    ((FindManagerImpl) FindManager.getInstance(myProject)).getFindUsagesManager().addToHistory(usageTarget);
    manager.searchAndShowUsages(new UsageTarget[] { usageTarget }, () -> processor -> {
        myIsFindInProgress = true;
        try {
            Processor<UsageInfo> consumer = info -> {
                Usage usage = UsageInfo2UsageAdapter.CONVERTER.fun(info);
                usage.getPresentation().getIcon();
                return processor.process(usage);
            };
            FindInProjectUtil.findUsages(findModelCopy, myProject, consumer, processPresentation);
        } finally {
            myIsFindInProgress = false;
        }
    }, processPresentation, presentation, null);
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) FindManagerImpl(com.intellij.find.impl.FindManagerImpl) com.intellij.usages(com.intellij.usages) Content(com.intellij.ui.content.Content) UsageInfo(com.intellij.usageView.UsageInfo) FindInProjectUtil(com.intellij.find.impl.FindInProjectUtil) FindManager(com.intellij.find.FindManager) ReplaceInProjectManager(com.intellij.find.replaceInProject.ReplaceInProjectManager) PlatformDataKeys(com.intellij.openapi.actionSystem.PlatformDataKeys) ServiceManager(com.intellij.openapi.components.ServiceManager) Processor(com.intellij.util.Processor) FindModel(com.intellij.find.FindModel) Project(com.intellij.openapi.project.Project) FindSettings(com.intellij.find.FindSettings) NotNull(org.jetbrains.annotations.NotNull) UsageViewManager(com.intellij.usageView.UsageViewManager) FindModel(com.intellij.find.FindModel) FindManager(com.intellij.find.FindManager) com.intellij.usages(com.intellij.usages) UsageInfo(com.intellij.usageView.UsageInfo)

Aggregations

FindManagerImpl (com.intellij.find.impl.FindManagerImpl)12 FindUsagesHandler (com.intellij.find.findUsages.FindUsagesHandler)7 FindUsagesManager (com.intellij.find.findUsages.FindUsagesManager)7 PsiElement (com.intellij.psi.PsiElement)5 NotNull (org.jetbrains.annotations.NotNull)5 Project (com.intellij.openapi.project.Project)4 UsageInfo (com.intellij.usageView.UsageInfo)4 FindManager (com.intellij.find.FindManager)2 FindSettings (com.intellij.find.FindSettings)2 FindUsagesOptions (com.intellij.find.findUsages.FindUsagesOptions)2 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)2 CommonProcessors (com.intellij.util.CommonProcessors)2 Processor (com.intellij.util.Processor)2 DartServerFindUsagesHandler (com.jetbrains.lang.dart.ide.findUsages.DartServerFindUsagesHandler)2 TargetElementUtil (com.intellij.codeInsight.TargetElementUtil)1 HighlightUsagesHandler (com.intellij.codeInsight.highlighting.HighlightUsagesHandler)1 ReadWriteAccessDetector (com.intellij.codeInsight.highlighting.ReadWriteAccessDetector)1 HintManager (com.intellij.codeInsight.hint.HintManager)1 HintUtil (com.intellij.codeInsight.hint.HintUtil)1 FeatureUsageTracker (com.intellij.featureStatistics.FeatureUsageTracker)1