public void setScopesFromContext(@Nullable SearchScope scope) {
    if (scope != null) myScope = scope;
    DataManager.getInstance().getDataContextFromFocusAsync().onSuccess(context -> {
      Scopes.Type foundScope = null;
      myUpdating = true;
      try {
        boolean moduleFound = false;
        boolean directoryFound = false;
        boolean namedScopeFound = false;
        final Module[] modules = ModuleManager.getInstance(myProject).getModules();
        if (modules.length > 0) {
          // set some defaults
          final Module module = modules[0];
          myModulesComboBox.setSelectedModule(module);
          final VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
          if (roots.length > 0) {
            final VirtualFile root = roots[0];
            myDirectoryComboBox.setDirectory(root.isDirectory() ? root : root.getParent());
          }
        }

        final Module module = PlatformCoreDataKeys.MODULE.getData(context);
        if (module != null) {
          moduleFound = true;
          myModulesComboBox.setSelectedModule(module);
        }
        final Editor editor = CommonDataKeys.HOST_EDITOR.getData(context);
        if (editor != null) {
          final VirtualFile file = FileDocumentManager.getInstance().getFile(editor.getDocument());
          if (file != null) {
            myDirectoryComboBox.setDirectory(file.getParent());
          }
          selectNamedScope(PredefinedSearchScopeProviderImpl.getCurrentFileScopeName());
          setScope(scope);
          return;
        }

        final FindModel findModel = new FindModel();
        for (FindInProjectExtension extension : FindInProjectExtension.EP_NAME.getExtensionList()) {
          namedScopeFound = extension.initModelFromContext(findModel, context);
          if (namedScopeFound) {
            selectNamedScope(findModel.getCustomScopeName());
            foundScope = Scopes.Type.NAMED;
            break;
          }
        }

        final VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(context);
        if (files != null && files.length > 0) {
          if (!moduleFound) {
            final Module fileModule = ModuleUtilCore.findModuleForFile(files[0], myProject);
            if (fileModule != null) {
              myModulesComboBox.setSelectedModule(fileModule);
            }
          }
          if (!namedScopeFound) {
            final SearchScope selectedFilesScope = PredefinedSearchScopeProviderImpl.getSelectedFilesScope(myProject, context, null);
            if (selectedFilesScope != null) {
              selectNamedScope(selectedFilesScope.getDisplayName());
            }
          }
          if (files.length == 1) {
            directoryFound = true;
            final VirtualFile file = files[0];
            myDirectoryComboBox.setDirectory(file.isDirectory() ? file : file.getParent());
            if (foundScope == null) {
              foundScope = Scopes.Type.DIRECTORY;
            }
          }
          else {
            for (VirtualFile file : files) {
              if (file.isDirectory()) {
                myDirectoryComboBox.setDirectory(file);
                directoryFound = true;
                break;
              }
            }
            if (foundScope == null) {
              foundScope = Scopes.Type.NAMED;
            }
          }
          if (!directoryFound) {
            final VirtualFile ancestor = VfsUtil.getCommonAncestor(List.of(files));
            if (ancestor != null) {
              myDirectoryComboBox.setDirectory(ancestor);
              directoryFound = true;
            }
          }
          if (!directoryFound) {
            final VirtualFile directory = files[0].getParent();
            if (directory != null) {
              myDirectoryComboBox.setDirectory(directory);
            }
          }
        }
      } finally {
        myUpdating = false;
      }
      showScope(foundScope == null ? Scopes.Type.PROJECT : foundScope);
    });
  }
public void setScopesFromContext(@Nullable SearchScope scope)