com.intellij.openapi.project.DumbServiceImpl Java Examples

The following examples show how to use com.intellij.openapi.project.DumbServiceImpl. 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: VarResolveTestCase.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
@NotNull
private PsiElement doAssertIsWellDefined(boolean dumMode) throws Exception {
    DumbServiceImpl instance = DumbServiceImpl.getInstance(myProject);

    boolean oldDumb = instance.isDumb();
    instance.setDumb(dumMode);
    try {
        PsiReference start = configure();
        PsiElement varDef = start.resolve();
        //Assert.assertTrue("The reference is NOT a var reference", start.getElement() instanceof BashVarUse);
        Assert.assertNotNull("Could not find a definition for the reference: " + start.getElement().getText(), varDef);
        Assert.assertTrue("The definition is NOT a variable definition: " + varDef, varDef instanceof BashVarDef);
        Assert.assertTrue("The reference is NOT a reference to the definition", start.isReferenceTo(varDef));
        return varDef;
    } finally {
        instance.setDumb(oldDumb);
    }
}
 
Example #2
Source File: FunctionResolveTestCase.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
@NotNull
private PsiElement doCheckFunctionReference(boolean dumbMode) throws Exception {
    boolean oldDumb = DumbService.isDumb(myProject);

    DumbServiceImpl.getInstance(myProject).setDumb(dumbMode);
    try {
        PsiReference psiReference = configure();
        Assert.assertTrue(psiReference.getElement() instanceof BashCommand);
        BashCommand commandElement = (BashCommand) psiReference.getElement();

        Assert.assertTrue(psiReference.resolve() instanceof BashFunctionDef);
        Assert.assertTrue(commandElement.isFunctionCall());
        Assert.assertFalse(commandElement.isVarDefCommand());
        Assert.assertFalse(commandElement.isExternalCommand());
        Assert.assertTrue(commandElement.getReference().isReferenceTo(psiReference.resolve()));

        return psiReference.resolve();
    } finally {
        DumbServiceImpl.getInstance(myProject).setDumb(oldDumb);
    }
}
 
Example #3
Source File: ToggleDumbModeAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent e) {
  if (myDumb) {
    myDumb = false;
  }
  else {
    myDumb = true;
    final Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null) return;

    DumbServiceImpl.getInstance(project).queueTask(new DumbModeTask() {
      @Override
      public void performInDumbMode(@Nonnull ProgressIndicator indicator) {
        while (myDumb) {
          indicator.checkCanceled();
          TimeoutUtil.sleep(100);
        }
      }
    });
  }
}
 
Example #4
Source File: PantsMetrics.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * This starts the indexing timer when certain conditions are met,
 * because the factor to determine whether indexing has started is
 * different in unit test and in GUI mode.
 *
 * @param myProject current Project.
 */
public static void prepareTimeIndexing(Project myProject) {
  if (!isMetricsEnabled()) {
    return;
  }
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    markIndexStart();
    return;
  }

  /**
   * This portion only applies in manual testing.
   */
  handle = indexThreadPool.scheduleWithFixedDelay(new Runnable() {
    @Override
    public void run() {
      // Start counting now in unit test mode, because dumb mode is never set.
      if (!DumbServiceImpl.getInstance(myProject).isDumb()) {
        return;
      }
      // Still in smart mode, meaning indexing hasn't started yet.
      counter++;
      if (counter > 10) {
        handle.cancel(false);
        counter = 0;
      }
      markIndexStart();
      DumbServiceImpl.getInstance(myProject).runWhenSmart(new Runnable() {
        @Override
        public void run() {
          markIndexEnd();
          report();
        }
      });
      handle.cancel(false);
    }
  }, 0, 1, TimeUnit.SECONDS);
}
 
Example #5
Source File: ToggleLaggingModeAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(final AnActionEvent e) {
  final Presentation presentation = e.getPresentation();
  final Project project = e.getData(CommonDataKeys.PROJECT);
  presentation.setEnabled(project != null && myLagging == DumbServiceImpl.getInstance(project).isDumb());
  if (myLagging) {
    presentation.setText("Exit lagging mode");
  }
  else {
    presentation.setText("Enter lagging mode");
  }
}
 
Example #6
Source File: ToggleDumbModeAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(final AnActionEvent e) {
  final Presentation presentation = e.getPresentation();
  final Project project = e.getData(CommonDataKeys.PROJECT);
  presentation.setEnabled(project != null && myDumb == DumbServiceImpl.getInstance(project).isDumb());
  if (myDumb) {
    presentation.setText("Exit Dumb Mode");
  }
  else {
    presentation.setText("Enter Dumb Mode");
  }
}
 
Example #7
Source File: ProjectRootManagerComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void doUpdateOnRefresh() {
  if (ApplicationManager.getApplication().isUnitTestMode() && (!myStartupActivityPerformed || myProject.isDisposed())) {
    return; // in test mode suppress addition to a queue unless project is properly initialized
  }
  if (myProject.isDefault()) {
    return;
  }

  if (myDoLogCachesUpdate) LOG.debug("refresh");
  DumbServiceImpl dumbService = DumbServiceImpl.getInstance(myProject);
  DumbModeTask task = FileBasedIndexProjectHandler.createChangedFilesIndexingTask(myProject);
  if (task != null) {
    dumbService.queueTask(task);
  }
}
 
Example #8
Source File: ProjectRootManagerComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void doSynchronizeRoots() {
  if (!myStartupActivityPerformed) return;

  if (myDoLogCachesUpdate) {
    LOG.debug(new Throwable("sync roots"));
  }
  else if (!ApplicationManager.getApplication().isUnitTestMode()) LOG.info("project roots have changed");

  DumbServiceImpl dumbService = DumbServiceImpl.getInstance(myProject);
  if (FileBasedIndex.getInstance() instanceof FileBasedIndexImpl) {
    dumbService.queueTask(new UnindexedFilesUpdater(myProject));
  }
}
 
Example #9
Source File: PantsExternalMetricsListenerExtensionTest.java    From intellij-pants-plugin with Apache License 2.0 4 votes vote down vote up
public void testDurationIndexing() throws Throwable {
  class DurationMetricsTestListener extends EmptyMetricsTestListener {
    private long duration = -1;

    @Override
    public void logIndexingDuration(long milliSeconds) throws Throwable {
      duration = milliSeconds;
    }
  }

  DurationMetricsTestListener listener = new DurationMetricsTestListener();
  Extensions.getRootArea().getExtensionPoint(PantsExternalMetricsListener.EP_NAME).registerExtension(listener);

  // Set DumbService manually to explicitly trigger the StopWatch for indexing.
  // The goal is to test the whether `logIndexingDuration` works.
  DumbServiceImpl.getInstance(myProject).setDumb(true);

  // Set dumb mode multiple times to test the semaphore behavior.
  DumbServiceImpl.getInstance(myProject).setDumb(true);

  long sleepTimeMilliSeconds = 500;
  Thread.sleep(sleepTimeMilliSeconds);

  // Unset dumb service to signify indexing has ended.
  DumbServiceImpl.getInstance(myProject).setDumb(false);
  DumbServiceImpl.getInstance(myProject).setDumb(false);

  assertTrue(
    String.format("Indexing duration should be greater than %s, but is %s.", sleepTimeMilliSeconds, listener.duration),
    listener.duration >= sleepTimeMilliSeconds
  );

  // reset
  listener.duration = -1;

  // 2nd wave of indexing.
  DumbServiceImpl.getInstance(myProject).setDumb(true);

  long secondSleepTimeMilliSeconds = 1000;
  Thread.sleep(secondSleepTimeMilliSeconds);

  // Unset dumb service to signify indexing has ended.
  DumbServiceImpl.getInstance(myProject).setDumb(false);

  assertTrue(
    String.format("Indexing duration should be greater than %s, but is %s.", secondSleepTimeMilliSeconds, listener.duration),
    listener.duration >= secondSleepTimeMilliSeconds
  );
}
 
Example #10
Source File: FindInProjectUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void setDirectoryName(@Nonnull FindModel model, @Nonnull DataContext dataContext) {
  PsiElement psiElement = null;
  Project project = dataContext.getData(CommonDataKeys.PROJECT);

  Editor editor = dataContext.getData(CommonDataKeys.EDITOR);
  if (project != null && editor == null && !DumbServiceImpl.getInstance(project).isDumb()) {
    try {
      psiElement = dataContext.getData(CommonDataKeys.PSI_ELEMENT);
    }
    catch (IndexNotReadyException ignore) {
    }
  }

  String directoryName = null;

  if (psiElement instanceof PsiDirectory) {
    directoryName = ((PsiDirectory)psiElement).getVirtualFile().getPresentableUrl();
  }

  if (directoryName == null && psiElement instanceof PsiDirectoryContainer) {
    final PsiDirectory[] directories = ((PsiDirectoryContainer)psiElement).getDirectories();
    directoryName = directories.length == 1 ? directories[0].getVirtualFile().getPresentableUrl() : null;
  }

  if (directoryName == null) {
    VirtualFile virtualFile = dataContext.getData(CommonDataKeys.VIRTUAL_FILE);
    if (virtualFile != null && virtualFile.isDirectory()) directoryName = virtualFile.getPresentableUrl();
  }

  Module module = dataContext.getData(LangDataKeys.MODULE_CONTEXT);
  if (module != null) {
    model.setModuleName(module.getName());
    model.setDirectoryName(null);
    model.setCustomScope(false);
  }

  if (model.getModuleName() == null || editor == null) {
    if (directoryName != null) {
      model.setDirectoryName(directoryName);
      model.setCustomScope(false); // to select "Directory: " radio button
    }
  }

  if (directoryName == null && module == null && project != null) {
    ChangeList changeList = ArrayUtil.getFirstElement(dataContext.getData(VcsDataKeys.CHANGE_LISTS));
    if (changeList == null) {
      Change change = ArrayUtil.getFirstElement(dataContext.getData(VcsDataKeys.CHANGES));
      changeList = change == null ? null : ChangeListManager.getInstance(project).getChangeList(change);
    }

    if (changeList != null) {
      String changeListName = changeList.getName();
      DefaultSearchScopeProviders.ChangeLists changeListsScopeProvider = SearchScopeProvider.EP_NAME.findExtension(DefaultSearchScopeProviders.ChangeLists.class);
      if (changeListsScopeProvider != null) {
        SearchScope changeListScope = ContainerUtil.find(changeListsScopeProvider.getSearchScopes(project), scope -> scope.getDisplayName().equals(changeListName));
        if (changeListScope != null) {
          model.setCustomScope(true);
          model.setCustomScopeName(changeListScope.getDisplayName());
          model.setCustomScope(changeListScope);
        }
      }
    }
  }

  // set project scope if we have no other settings
  model.setProjectScope(model.getDirectoryName() == null && model.getModuleName() == null && !model.isCustomScope());
}