public void startCacheUpdate() {
    try {
      DumbServiceImpl dumbService = DumbServiceImpl.getInstance(myProject);

      if (!ApplicationManager.getApplication().isUnitTestMode()) {
        // pre-startup activities have registered dumb tasks that load VFS (scanning files to index)
        // only after these tasks pass does VFS refresh make sense
        dumbService.queueTask(
            new DumbModeTask() {
              @Override
              public void performInDumbMode(@NotNull ProgressIndicator indicator) {
                scheduleInitialVfsRefresh();
              }

              @Override
              public String toString() {
                return "initial refresh";
              }
            });
      }
    } catch (ProcessCanceledException e) {
      throw e;
    } catch (Throwable e) {
      LOG.error(e);
    }
  }
  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.info("refresh");
    DumbServiceImpl dumbService = DumbServiceImpl.getInstance(myProject);
    DumbModeTask task = FileBasedIndexProjectHandler.createChangedFilesIndexingTask(myProject);
    if (task != null) {
      dumbService.queueTask(task);
    }

    if (myRefreshCacheUpdaters.size() == 0) {
      return;
    }

    if (ourScheduleCacheUpdateInDumbMode) {
      dumbService.queueCacheUpdateInDumbMode(myRefreshCacheUpdaters);
    } else {
      dumbService.queueCacheUpdate(myRefreshCacheUpdaters);
    }
  }
  @Override
  protected void doSynchronizeRoots() {
    if (!myStartupActivityPerformed) return;

    if (myDoLogCachesUpdate) LOG.info(new Throwable("sync roots"));

    DumbServiceImpl dumbService = DumbServiceImpl.getInstance(myProject);
    dumbService.queueTask(new UnindexedFilesUpdater(myProject, false));

    if (myRootsChangeUpdaters.isEmpty()) return;

    if (ourScheduleCacheUpdateInDumbMode) {
      dumbService.queueCacheUpdateInDumbMode(myRootsChangeUpdaters);
    } else {
      dumbService.queueCacheUpdate(myRootsChangeUpdaters);
    }
  }
 private void startCacheUpdate() {
   try {
     DumbServiceImpl.getInstance(myProject).queueCacheUpdate(myCacheUpdaters);
   } catch (ProcessCanceledException e) {
     throw e;
   } catch (Throwable e) {
     LOG.error(e);
   }
 }
  public static void setDirectoryName(@NotNull FindModel model, @NotNull DataContext dataContext) {
    PsiElement psiElement = null;
    Project project = CommonDataKeys.PROJECT.getData(dataContext);

    if (project != null && !DumbServiceImpl.getInstance(project).isDumb()) {
      try {
        psiElement = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
      } 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;
    }

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

    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    if (model.getModuleName() == null || editor == null) {
      model.setDirectoryName(directoryName);
      model.setProjectScope(
          directoryName == null && module == null && !model.isCustomScope() || editor != null);
      if (directoryName != null) {
        model.setCustomScope(false); // to select "Directory: " radio button
      }

      // for convenience set directory name to directory of current file, note that we doesn't
      // change default projectScope
      if (directoryName == null) {
        VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
        if (virtualFile != null && !virtualFile.isDirectory())
          virtualFile = virtualFile.getParent();
        if (virtualFile != null) model.setDirectoryName(virtualFile.getPresentableUrl());
      }
    }
  }
Exemplo n.º 6
0
  /**
   * Here we check if a given file belongs to our plugin. We take this road because we need the
   * actual file and not a filename to check files without extension.
   *
   * <p>A file is checked according to the rules defined in the facet settings. A file can be set to
   * ignored, accepted or auto. Auto means that the content is checked.
   *
   * @param file The file to check
   * @return True if BashSupport wants to take that file
   */
  public boolean isMyFileType(VirtualFile file) {
    if (file == null) {
      return false;
    }

    if (file.isDirectory()) {
      return false;
    }

    if (extensionList.contains(file.getExtension())) {
      return true;
    } else if (!file.isInLocalFileSystem()) {
      return false;
    } else if (StringUtils.isEmpty(file.getExtension())) {
      BashFacet facet = null;
      try {
        // no extensions, special checks (looking at the content, etc)

        // guess project
        Project project = ProjectUtil.guessProjectForFile(file);
        if (project == null) {
          return false;
        }

        DumbServiceImpl dumbService = DumbServiceImpl.getInstance(project);
        if (dumbService == null || dumbService.isDumb()) {
          return false;
        }

        DirectoryIndex directoryIndex = DirectoryIndex.getInstance(project);
        if (directoryIndex == null || !directoryIndex.isInitialized()) {
          return false;
        }

        Module module = ModuleUtil.findModuleForFile(file, project);
        if (module == null) {
          return false;
        }

        facet = BashFacet.getInstance(module);
        if (facet == null) {
          return false;
        }

        BashFacetConfiguration config = facet.getConfiguration();
        FileMode mode = config.findMode(file);

        if (mode == FileMode.accept()) {
          return true;
        } else if (mode == FileMode.ignore()) {
          return false;
        } else if (mode == FileMode.auto()) {
          return BashContentUtil.isProbablyBashFile(
              VfsUtil.virtualToIoFile(file),
              MIN_FILE_PROBABILIY,
              ProjectUtil.guessProjectForFile(file));
        }
      } catch (Exception e) {
        // ignore this
        LOG.warn("Could not check the file type due to exception", e);
      }
    }

    return false;
  }