Java Code Examples for com.intellij.openapi.project.DumbService#isDumbAware()

The following examples show how to use com.intellij.openapi.project.DumbService#isDumbAware() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntentionListStep.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void applyAction(@Nonnull IntentionActionWithTextCaching cachedAction) {
  myFinalRunnable = () -> {
    HintManager.getInstance().hideAllHints();
    if (myProject.isDisposed()) return;
    if (myEditor != null && (myEditor.isDisposed() || (!myEditor.getComponent().isShowing() && !ApplicationManager.getApplication().isUnitTestMode()))) return;

    if (DumbService.isDumb(myProject) && !DumbService.isDumbAware(cachedAction)) {
      DumbService.getInstance(myProject).showDumbModeNotification(cachedAction.getText() + " is not available during indexing");
      return;
    }

    PsiDocumentManager.getInstance(myProject).commitAllDocuments();

    PsiFile file = myEditor != null ? PsiUtilBase.getPsiFileInEditor(myEditor, myProject) : myFile;
    if (file == null) {
      return;
    }

    ShowIntentionActionsHandler.chooseActionAndInvoke(file, myEditor, cachedAction.getAction(), cachedAction.getText(), myProject);
  };
}
 
Example 2
Source File: UsageNodeTreeBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
UsageNode appendOrGet(@Nonnull Usage usage, boolean filterDuplicateLines, @Nonnull Consumer<? super Node> edtInsertedUnderQueue) {
  if (!isVisible(usage)) return null;

  final boolean dumb = DumbService.isDumb(myProject);

  GroupNode groupNode = myRoot;
  for (int i = 0; i < myGroupingRules.length; i++) {
    UsageGroupingRule rule = myGroupingRules[i];
    if (dumb && !DumbService.isDumbAware(rule)) continue;

    List<UsageGroup> groups = rule.getParentGroupsFor(usage, myTargets);
    for (UsageGroup group : groups) {
      groupNode = groupNode.addOrGetGroup(group, i, edtInsertedUnderQueue);
    }
  }

  return groupNode.addOrGetUsage(usage, filterDuplicateLines, edtInsertedUnderQueue);
}
 
Example 3
Source File: DefaultHighlightVisitor.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void runAnnotators(PsiElement element) {
  List<Annotator> annotators = myCachedAnnotators.get(element.getLanguage().getID());
  if (annotators.isEmpty()) return;
  final boolean dumb = myDumbService.isDumb();

  //noinspection ForLoopReplaceableByForEach
  for (int i = 0; i < annotators.size(); i++) {
    Annotator annotator = annotators.get(i);
    if (dumb && !DumbService.isDumbAware(annotator)) {
      continue;
    }

    ProgressManager.checkCanceled();

    annotator.annotate(element, myAnnotationHolder);
  }
}
 
Example 4
Source File: TextEditorHighlightingPass.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected boolean isValid() {
  if (isDumbMode() && !DumbService.isDumbAware(this)) {
    return false;
  }

  if (PsiModificationTracker.SERVICE.getInstance(myProject).getModificationCount() != myInitialPsiStamp) {
    return false;
  }

  if (myDocument != null) {
    if (myDocument.getModificationStamp() != myInitialDocStamp) return false;
    PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(myDocument);
    return file != null && file.isValid();
  }

  return true;
}
 
Example 5
Source File: ProjectUtils.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 5 votes vote down vote up
/**
 * Runs the DumbService
 * @param project
 * @param r
 */
public static void runDumbAware(final Project project, final Runnable r) {
    if (DumbService.isDumbAware(r)) {
        r.run();
    } else {
        DumbService.getInstance(project).runWhenSmart(DisposeAwareRunnable.create(r, project));
    }
}
 
Example 6
Source File: FoldingUpdate.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the ability to initialize folding in the Dumb Mode for file.
 *
 * @param file the file to test
 * @return true  if folding initialization available in the Dumb Mode
 */
private static boolean supportsDumbModeFolding(@Nonnull PsiFile file) {
  final FileViewProvider viewProvider = file.getViewProvider();
  for (final Language language : viewProvider.getLanguages()) {
    final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language);
    if (foldingBuilder != null && !DumbService.isDumbAware(foldingBuilder)) return false;
  }
  return true;
}
 
Example 7
Source File: UnresolvedReferenceQuickFixProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static <T extends PsiReference> void registerReferenceFixes(T ref, QuickFixActionRegistrar registrar) {

    final boolean dumb = DumbService.getInstance(ref.getElement().getProject()).isDumb();
    UnresolvedReferenceQuickFixProvider[] fixProviders = Extensions.getExtensions(EXTENSION_NAME);
    Class<? extends PsiReference> referenceClass = ref.getClass();
    for (UnresolvedReferenceQuickFixProvider each : fixProviders) {
      if (dumb && !DumbService.isDumbAware(each)) {
        continue;
      }
      if (ReflectionUtil.isAssignable(each.getReferenceClass(), referenceClass)) {
        each.registerFixes(ref, registrar);
      }
    }
  }
 
Example 8
Source File: StartupManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void registerPostStartupActivity(@Nonnull Consumer<UIAccess> runnable) {
  checkNonDefaultProject();
  if (myPostStartupActivitiesPassed) {
    LOG.error("Registering post-startup activity that will never be run:" + " disposed=" + myProject.isDisposed() + "; open=" + myProject.isOpen() + "; passed=" + myStartupActivitiesPassed);
  }

  Deque<Consumer<UIAccess>> list = DumbService.isDumbAware(runnable) ? myDumbAwarePostStartupActivities : myNotDumbAwarePostStartupActivities;
  synchronized (myLock) {
    list.add(runnable);
  }
}
 
Example 9
Source File: FileEditorProviderManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public FileEditorProvider[] getProviders(@Nonnull final Project project, @Nonnull final VirtualFile file) {
  // Collect all possible editors
  List<FileEditorProvider> sharedProviders = new ArrayList<>();
  boolean doNotShowTextEditor = false;
  for (final FileEditorProvider provider : myProviders) {
    ThrowableComputable<Boolean, RuntimeException> action = () -> {
      if (DumbService.isDumb(project) && !DumbService.isDumbAware(provider)) {
        return false;
      }
      return provider.accept(project, file);
    };
    if (AccessRule.read(action)) {
      sharedProviders.add(provider);
      doNotShowTextEditor |= provider.getPolicy() == FileEditorPolicy.HIDE_DEFAULT_EDITOR;
    }
  }

  // Throw out default editors provider if necessary
  if (doNotShowTextEditor) {
    ContainerUtil.retainAll(sharedProviders, provider -> !(provider instanceof TextEditorProvider));
  }

  // Sort editors according policies
  Collections.sort(sharedProviders, MyComparator.ourInstance);

  return sharedProviders.toArray(new FileEditorProvider[sharedProviders.size()]);
}
 
Example 10
Source File: TextCompletionUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static TextCompletionProvider getProvider(@Nonnull PsiFile file) {
  TextCompletionProvider provider = file.getUserData(COMPLETING_TEXT_FIELD_KEY);

  if (provider == null || (DumbService.isDumb(file.getProject()) && !DumbService.isDumbAware(provider))) {
    return null;
  }
  return provider;
}
 
Example 11
Source File: QueryExecutorBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public final boolean execute(@Nonnull final Params queryParameters, @Nonnull final Processor<? super Result> consumer) {
  final AtomicBoolean toContinue = new AtomicBoolean(true);
  final Processor<Result> wrapper = result -> {
    if (!toContinue.get()) {
      return false;
    }

    if (!consumer.process(result)) {
      toContinue.set(false);
      return false;
    }
    return true;
  };

  if (myRequireReadAction && !ApplicationManager.getApplication().isReadAccessAllowed()) {
    Runnable runnable = () -> {
      if (!(queryParameters instanceof QueryParameters) || ((QueryParameters)queryParameters).isQueryValid()) {
        processQuery(queryParameters, wrapper);
      }
    };

    if (!DumbService.isDumbAware(this)) {
      Project project = queryParameters instanceof QueryParameters ? ((QueryParameters)queryParameters).getProject() : null;
      if (project != null) {
        DumbService.getInstance(project).runReadActionInSmartMode(runnable);
        return toContinue.get();
      }
    }

    ApplicationManager.getApplication().runReadAction(runnable);
  }
  else {
    processQuery(queryParameters, wrapper);
  }

  return toContinue.get();
}
 
Example 12
Source File: TextEditorHighlightingPass.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public final void applyInformationToEditor() {
  if (!isValid()) return; // Document has changed.
  if (DumbService.getInstance(myProject).isDumb() && !DumbService.isDumbAware(this)) {
    Document document = getDocument();
    PsiFile file = document == null ? null : PsiDocumentManager.getInstance(myProject).getPsiFile(document);
    if (file != null) {
      DaemonCodeAnalyzerEx.getInstanceEx(myProject).getFileStatusMap().markFileUpToDate(getDocument(), getId());
    }
    return;
  }
  doApplyInformationToEditor();
}
 
Example 13
Source File: SMTestLocator.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public List<Location> getLocation(@Nonnull String protocol, @Nonnull String path, @Nonnull Project project, @Nonnull GlobalSearchScope scope) {
  SMTestLocator locator = myLocators.get(protocol);

  if (locator != null && (!DumbService.isDumb(project) || DumbService.isDumbAware(locator))) {
    return locator.getLocation(protocol, path, project, scope);
  }

  return Collections.emptyList();
}
 
Example 14
Source File: ContributorsBasedGotoByModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private List<ChooseByNameContributor> filterDumb(List<ChooseByNameContributor> contributors) {
  if (!DumbService.getInstance(myProject).isDumb()) return contributors;
  List<ChooseByNameContributor> answer = new ArrayList<>(contributors.size());
  for (ChooseByNameContributor contributor : contributors) {
    if (DumbService.isDumbAware(contributor)) {
      answer.add(contributor);
    }
  }

  return answer;
}
 
Example 15
Source File: SMTestRunnerConnectionUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public List<Location> getLocation(@Nonnull String protocol, @Nonnull String path, @Nonnull Project project, @Nonnull GlobalSearchScope scope) {
  if (URLUtil.FILE_PROTOCOL.equals(protocol)) {
    return FileUrlProvider.INSTANCE.getLocation(protocol, path, project, scope);
  }
  else if (!DumbService.isDumb(project) || DumbService.isDumbAware(myLocator)) {
    return myLocator.getLocation(protocol, path, project, scope);
  }
  else {
    return Collections.emptyList();
  }
}
 
Example 16
Source File: CrudUtils.java    From crud-intellij-plugin with Apache License 2.0 5 votes vote down vote up
public static void runDumbAware(final Project project, final Runnable r) {
    if (DumbService.isDumbAware(r)) {
        r.run();
    } else {
        DumbService.getInstance(project).runWhenSmart(DisposeAwareRunnable.create(r, project));
    }
}
 
Example 17
Source File: EditorGutterComponentImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private boolean checkDumbAware(@Nonnull Object possiblyDumbAware) {
  return !isDumbMode() || DumbService.isDumbAware(possiblyDumbAware);
}
 
Example 18
Source File: CompositeFilter.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nullable
public Result applyFilter(@Nonnull final String line, final int entireLength) {
  ApplicationManager.getApplication().assertReadAccessAllowed();
  final boolean dumb = myDumbService.isDumb();
  List<Filter> filters = myFilters;
  int count = filters.size();

  List<ResultItem> resultItems = null;
  for (int i = 0; i < count; i++) {
    ProgressManager.checkCanceled();
    Filter filter = filters.get(i);
    if (!dumb || DumbService.isDumbAware(filter)) {
      long t0 = System.currentTimeMillis();

      Result result;
      try {
        result = filter.applyFilter(line, entireLength);
      }
      catch (ProcessCanceledException ignore) {
        result = null;
      }
      catch (Throwable t) {
        throw new RuntimeException("Error while applying " + filter + " to '" + line + "'", t);
      }
      if (result != null) {
        resultItems = merge(resultItems, result, entireLength, filter);
      }

      t0 = System.currentTimeMillis() - t0;
      if (t0 > 1000) {
        LOG.warn(filter.getClass().getSimpleName() + ".applyFilter() took " + t0 + " ms on '''" + line + "'''");
      }
      if (result != null && shouldStopFiltering(result)) {
        break;
      }
    }
  }
  if (resultItems == null) {
    return null;
  }
  return createFinalResult(resultItems);
}
 
Example 19
Source File: ChooseByNameBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public Continuation runBackgroundProcess(@Nonnull final ProgressIndicator indicator) {
  if (myProject == null || DumbService.isDumbAware(myModel)) return super.runBackgroundProcess(indicator);

  return DumbService.getInstance(myProject).runReadActionInSmartMode(() -> performInReadAction(indicator));
}
 
Example 20
Source File: IntentionActionWithTextCaching.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isDumbAware() {
  return DumbService.isDumbAware(myAction);
}