Java Code Examples for com.intellij.openapi.project.DumbService#isDumb()
The following examples show how to use
com.intellij.openapi.project.DumbService#isDumb() .
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: ORFileManager.java From reasonml-idea-plugin with MIT License | 6 votes |
@Nullable public static PsiFile findCmtFileFromSource(@NotNull Project project, @NotNull String filenameWithoutExtension) { if (!DumbService.isDumb(project)) { GlobalSearchScope scope = GlobalSearchScope.allScope(project); String filename = filenameWithoutExtension + ".cmt"; PsiFile[] cmtFiles = FilenameIndex.getFilesByName(project, filename, scope); if (cmtFiles.length == 0) { if (LOG.isDebugEnabled()) { LOG.debug("File module for " + filename + " is NOTĀ FOUND, files found: [" + Joiner.join(", ", cmtFiles) + "]"); } return null; } if (LOG.isDebugEnabled()) { LOG.debug("Found cmt " + filename + " (" + cmtFiles[0].getVirtualFile().getPath() + ")"); } return cmtFiles[0]; } else { LOG.info("Cant find cmt while reindexing"); } return null; }
Example 2
Source File: MuleSdk.java From mule-intellij-plugins with Apache License 2.0 | 6 votes |
@Nullable private static String getMuleHome(@NotNull Module module) { if (!DumbService.isDumb(module.getProject())) { final OrderEnumerator enumerator = ModuleRootManager.getInstance(module) .orderEntries().recursively().librariesOnly().exportedOnly(); final String[] home = new String[1]; enumerator.forEachLibrary(library -> { if (MuleLibraryKind.MULE_LIBRARY_KIND.equals(((LibraryEx) library).getKind()) && library.getFiles(OrderRootType.CLASSES) != null && library.getFiles(OrderRootType.CLASSES).length > 0) { home[0] = getMuleHome(library.getFiles(OrderRootType.CLASSES)[0]); return false; } else { return true; } }); return home[0]; } return null; }
Example 3
Source File: FunctionResolveTestCase.java From BashSupport with Apache License 2.0 | 6 votes |
@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 4
Source File: ProjectViewDropTarget.java From consulo with Apache License 2.0 | 6 votes |
private void doDrop(@Nonnull TreePath target, PsiElement[] sources) { final PsiElement targetElement = getPsiElement(target); if (targetElement == null) return; if (DumbService.isDumb(myProject)) { Messages.showMessageDialog(myProject, "Copy refactoring is not available while indexing is in progress", "Indexing", null); return; } final PsiDirectory psiDirectory; if (targetElement instanceof PsiDirectoryContainer) { final PsiDirectoryContainer directoryContainer = (PsiDirectoryContainer)targetElement; final PsiDirectory[] psiDirectories = directoryContainer.getDirectories(); psiDirectory = psiDirectories.length != 0 ? psiDirectories[0] : null; } else if (targetElement instanceof PsiDirectory) { psiDirectory = (PsiDirectory)targetElement; } else { final PsiFile containingFile = targetElement.getContainingFile(); LOG.assertTrue(containingFile != null, targetElement); psiDirectory = containingFile.getContainingDirectory(); } TransactionGuard.getInstance().submitTransactionAndWait(() -> CopyHandler.doCopy(sources, psiDirectory)); }
Example 5
Source File: DocGenerateAction.java From CodeMaker with Apache License 2.0 | 6 votes |
/** * @see com.intellij.openapi.actionSystem.AnAction#actionPerformed(com.intellij.openapi.actionSystem.AnActionEvent) */ @Override public void actionPerformed(AnActionEvent e) { Project project = e.getProject(); if (project == null) { return; } DumbService dumbService = DumbService.getInstance(project); if (dumbService.isDumb()) { dumbService.showDumbModeNotification("CodeMaker plugin is not available during indexing"); return; } PsiFile javaFile = e.getData(CommonDataKeys.PSI_FILE); Editor editor = e.getData(CommonDataKeys.EDITOR); if (javaFile == null || editor == null) { return; } List<PsiClass> classes = CodeMakerUtil.getClasses(javaFile); PsiElementFactory psiElementFactory = PsiElementFactory.SERVICE.getInstance(project); for (PsiClass psiClass : classes) { for (PsiMethod psiMethod : PsiTreeUtil.getChildrenOfTypeAsList(psiClass, PsiMethod.class)) { createDocForMethod(psiMethod, psiElementFactory); } } }
Example 6
Source File: GotoSymbolAction.java From consulo with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(@Nonnull AnActionEvent e) { Project project = e.getProject(); if (project == null) return; boolean dumb = DumbService.isDumb(project); if (Registry.is("new.search.everywhere")) { if (!dumb || new SymbolSearchEverywhereContributor(project, null).isDumbAware()) { showInSearchEverywherePopup(SymbolSearchEverywhereContributor.class.getSimpleName(), e, true, true); } else { GotoClassAction.invokeGoToFile(project, e); } } else { if (!dumb) { super.actionPerformed(e); } else { GotoClassAction.invokeGoToFile(project, e); } } }
Example 7
Source File: GenerateAction.java From consulo with Apache License 2.0 | 6 votes |
private static DefaultActionGroup wrapGroup(DefaultActionGroup actionGroup, DataContext dataContext, @Nonnull Project project) { final DefaultActionGroup copy = new DefaultActionGroup(); for (final AnAction action : actionGroup.getChildren(null)) { if (DumbService.isDumb(project) && !action.isDumbAware()) { continue; } if (action instanceof GenerateActionPopupTemplateInjector) { final AnAction editTemplateAction = ((GenerateActionPopupTemplateInjector)action).createEditTemplateAction(dataContext); if (editTemplateAction != null) { copy.add(new GenerateWrappingGroup(action, editTemplateAction)); continue; } } if (action instanceof DefaultActionGroup) { copy.add(wrapGroup((DefaultActionGroup)action, dataContext, project)); } else { copy.add(action); } } return copy; }
Example 8
Source File: IntentionListStep.java From consulo with Apache License 2.0 | 6 votes |
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 9
Source File: ResumeAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(AnActionEvent e) { if (!performWithHandler(e)) { Project project = getEventProject(e); if (project != null && !DumbService.isDumb(project)) { new ChooseDebugConfigurationPopupAction().actionPerformed(e); } } }
Example 10
Source File: CodeInsightTestFixtureImpl.java From consulo with Apache License 2.0 | 5 votes |
private long collectAndCheckHighlighting(@Nonnull ExpectedHighlightingData data) { final Project project = getProject(); PsiDocumentManager.getInstance(project).commitAllDocuments(); PsiFileImpl file = (PsiFileImpl)getHostFile(); FileElement hardRefToFileElement = file.calcTreeElement();//to load text //to initialize caches if (!DumbService.isDumb(project)) { CacheManager.getInstance(project).getFilesWithWord(XXX, UsageSearchContext.IN_COMMENTS, GlobalSearchScope.allScope(project), true); } List<HighlightInfo> infos; final long start = System.currentTimeMillis(); try { ((PsiManagerImpl)PsiManager.getInstance(project)).setAssertOnFileLoadingFilter(myJavaFilesFilter, myTestRootDisposable); // ProfilingUtil.startCPUProfiling(); infos = doHighlighting(); removeDuplicatedRangesForInjected(infos); // ProfilingUtil.captureCPUSnapshot("testing"); } finally { ((PsiManagerImpl)PsiManager.getInstance(project)).setAssertOnFileLoadingFilter(VirtualFileFilter.NONE, myTestRootDisposable); } final long elapsed = System.currentTimeMillis() - start; data.checkResult(infos, file.getText()); hardRefToFileElement.hashCode(); // use it so gc won't collect it return elapsed; }
Example 11
Source File: UniqueNameEditorTabTitleProvider.java From consulo with Apache License 2.0 | 5 votes |
@Override public String getEditorTabTitle(@Nonnull Project project, @Nonnull VirtualFile file) { UISettings uiSettings = UISettings.getInstanceOrNull(); if (uiSettings == null || !uiSettings.getShowDirectoryForNonUniqueFilenames() || DumbService.isDumb(project)) { return null; } // Even though this is a 'tab title provider' it is used also when tabs are not shown, namely for building IDE frame title. String uniqueName = uiSettings.getEditorTabPlacement() == UISettings.TABS_NONE ? UniqueVFilePathBuilder.getInstance().getUniqueVirtualFilePath(project, file) : UniqueVFilePathBuilder.getInstance().getUniqueVirtualFilePathWithinOpenedFileEditors(project, file); uniqueName = getEditorTabText(uniqueName, File.separator, uiSettings.getHideKnownExtensionInTabs()); return uniqueName.equals(file.getName()) ? null : uniqueName; }
Example 12
Source File: ApplicationStatisticsListeners.java From consulo with Apache License 2.0 | 5 votes |
private static void doPersistProjectUsages(@Nonnull Project project) { if (DumbService.isDumb(project)) return; for (UsagesCollector usagesCollector : UsagesCollector.EP_NAME.getExtensionList()) { if (usagesCollector instanceof AbstractApplicationUsagesCollector) { ((AbstractApplicationUsagesCollector)usagesCollector).persistProjectUsages(project); } } }
Example 13
Source File: AsyncFilterRunner.java From consulo with Apache License 2.0 | 5 votes |
private void runTasks() { ApplicationManager.getApplication().assertReadAccessAllowed(); if (myEditor.isDisposed()) return; while (!myQueue.isEmpty()) { HighlighterJob highlighter = myQueue.peek(); if (!DumbService.isDumbAware(highlighter.filter) && DumbService.isDumb(highlighter.myProject)) return; while (highlighter.hasUnprocessedLines()) { ProgressManager.checkCanceled(); addLineResult(highlighter.analyzeNextLine()); } LOG.assertTrue(highlighter == myQueue.remove()); } }
Example 14
Source File: GenerateApiTableHtmlAction.java From CodeMaker with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(AnActionEvent e) { Project project = e.getProject(); if (project == null) { return; } DumbService dumbService = DumbService.getInstance(project); if (dumbService.isDumb()) { dumbService .showDumbModeNotification("CodeMaker plugin is not available during indexing"); return; } PsiFile javaFile = e.getData(CommonDataKeys.PSI_FILE); Editor editor = e.getData(CommonDataKeys.EDITOR); if (javaFile == null || editor == null) { return; } List<PsiClass> classes = CodeMakerUtil.getClasses(javaFile); StringBuilder table = new StringBuilder(128); table.append("<table border=\"1\">"); for (PsiClass psiClass : classes) { for (ClassEntry.Field field : CodeMakerUtil.getAllFields(psiClass)) { if (field.getModifier().contains("static")) { continue; } table.append("<tr>"); table.append("<th>").append(field.getName()).append("</th>"); table.append("<th>").append(StringEscapeUtils.escapeHtml(field.getType())) .append("</th>"); table.append("<th>").append(StringEscapeUtils.escapeHtml(field.getComment())) .append("</th>"); table.append("</tr>"); } } table.append("</table>"); CopyPasteManager.getInstance() .setContents(new SimpleTransferable(table.toString(), DataFlavor.allHtmlFlavor)); }
Example 15
Source File: FreezeLoggerImpl.java From consulo with Apache License 2.0 | 5 votes |
private static void dumpThreads(@Nullable Project project, @Nonnull ModalityState initialState) { final ThreadInfo[] infos = ThreadDumper.getThreadInfos(); final String edtTrace = ThreadDumper.dumpEdtStackTrace(infos); if (edtTrace.contains("java.lang.ClassLoader.loadClass")) { return; } final boolean isInDumbMode = project != null && !project.isDisposed() && DumbService.isDumb(project); ApplicationManager.getApplication().invokeLater(() -> { if (!initialState.equals(ModalityState.current())) return; sendDumpsInBackground(infos, isInDumbMode); }, ModalityState.any()); }
Example 16
Source File: HaxeIndexUtil.java From intellij-haxe with Apache License 2.0 | 5 votes |
public static boolean warnIfDumbMode(Project project) { if (DumbService.isDumb(project)) { LOG.warn("Unexpected index activity while in dumb mode at " + HaxeDebugUtil.printCallers(1)); return false; } return true; }
Example 17
Source File: ProjectViewDropTarget.java From consulo with Apache License 2.0 | 5 votes |
private void doDrop(PsiElement target, PsiElement[] sources, boolean externalDrop) { if (target == null) return; if (DumbService.isDumb(myProject)) { Messages.showMessageDialog(myProject, "Move refactoring is not available while indexing is in progress", "Indexing", null); return; } if (!myProject.isInitialized()) { Messages.showMessageDialog(myProject, "Move refactoring is not available while project initialization is in progress", "Project Initialization", null); return; } Module module = getModule(target); final DataContext dataContext = DataManager.getInstance().getDataContext(myTree); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); if (!target.isValid()) return; for (PsiElement element : sources) { if (!element.isValid()) return; } DataContext context = new DataContext() { @javax.annotation.Nullable @Override public <T> T getData(@Nonnull Key<T> dataId) { if (LangDataKeys.TARGET_MODULE == dataId) { if (module != null) return (T)module; } if (LangDataKeys.TARGET_PSI_ELEMENT == dataId) { return (T)target; } else { return externalDrop ? null : dataContext.getData(dataId); } } }; TransactionGuard.getInstance().submitTransactionAndWait(() -> getActionHandler().invoke(myProject, sources, context)); }
Example 18
Source File: BashVarDefImpl.java From BashSupport with Apache License 2.0 | 4 votes |
@NotNull @Override public BashReference getReference() { return DumbService.isDumb(getProject()) ? dumbReference : reference; }
Example 19
Source File: FileInclusionManager.java From BashSupport with Apache License 2.0 | 4 votes |
@NotNull public static Set<PsiFile> findIncludedFiles(@NotNull PsiFile sourceFile, boolean diveDeep, boolean bashOnly) { if (!(sourceFile instanceof BashFile)) { return Collections.emptySet(); } if (!sourceFile.isPhysical()) { return Collections.emptySet(); } if (DumbService.isDumb(sourceFile.getProject())) { return Collections.emptySet(); } Project project = sourceFile.getProject(); Set<PsiFile> includersTodo = Sets.newLinkedHashSet(Collections.singletonList(sourceFile)); Set<PsiFile> includersDone = Sets.newLinkedHashSet(); Set<PsiFile> allIncludedFiles = Sets.newHashSet(); while (!includersTodo.isEmpty()) { Iterator<PsiFile> iterator = includersTodo.iterator(); PsiFile file = iterator.next(); iterator.remove(); includersDone.add(file); VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile == null) { continue; } String filePath = virtualFile.getPath(); Collection<BashIncludeCommand> commands = StubIndex.getElements(BashIncludeCommandIndex.KEY, filePath, project, BashSearchScopes.bashOnly(BashSearchScopes.moduleScope(file)), BashIncludeCommand.class); if (commands.isEmpty()) { continue; } for (BashIncludeCommand command : commands) { BashFileReference fileReference = command.getFileReference(); if (fileReference != null && fileReference.isStatic()) { PsiFile referencedFile = fileReference.findReferencedFile(); if (bashOnly && !(referencedFile instanceof BashFile)) { continue; } if (referencedFile != null) { allIncludedFiles.add(referencedFile); if (!includersDone.contains(referencedFile)) { //the include commands of this command have to be collected, too includersTodo.add(referencedFile); } } } } if (!diveDeep) { //the first iteration is the original source break; } } return allIncludedFiles; }
Example 20
Source File: SearchEverywhereUI.java From consulo with Apache License 2.0 | 4 votes |
private void rebuildList() { ApplicationManager.getApplication().assertIsDispatchThread(); stopSearching(); myResultsList.setEmptyText(IdeBundle.message("label.choosebyname.searching")); String rawPattern = getSearchPattern(); updateViewType(rawPattern.isEmpty() ? ViewType.SHORT : ViewType.FULL); String namePattern = mySelectedTab.getContributor().map(contributor -> contributor.filterControlSymbols(rawPattern)).orElse(rawPattern); MinusculeMatcher matcher = NameUtil.buildMatcherWithFallback("*" + rawPattern, "*" + namePattern, NameUtil.MatchingCaseSensitivity.NONE); MatcherHolder.associateMatcher(myResultsList, matcher); Map<SearchEverywhereContributor<?>, Integer> contributorsMap = new HashMap<>(); Optional<SearchEverywhereContributor<?>> selectedContributor = mySelectedTab.getContributor(); if (selectedContributor.isPresent()) { contributorsMap.put(selectedContributor.get(), SINGLE_CONTRIBUTOR_ELEMENTS_LIMIT); } else { contributorsMap.putAll(getAllTabContributors().stream().collect(Collectors.toMap(c -> c, c -> MULTIPLE_CONTRIBUTORS_ELEMENTS_LIMIT))); } List<SearchEverywhereContributor<?>> contributors = DumbService.getInstance(myProject).filterByDumbAwareness(contributorsMap.keySet()); if (contributors.isEmpty() && DumbService.isDumb(myProject)) { myResultsList.setEmptyText(IdeBundle.message("searcheverywhere.indexing.mode.not.supported", mySelectedTab.getText(), ApplicationNamesInfo.getInstance().getFullProductName())); myListModel.clear(); return; } if (contributors.size() != contributorsMap.size()) { myResultsList.setEmptyText(IdeBundle.message("searcheverywhere.indexing.incomplete.results", mySelectedTab.getText(), ApplicationNamesInfo.getInstance().getFullProductName())); } myListModel.expireResults(); contributors.forEach(contributor -> myListModel.setHasMore(contributor, false)); String commandPrefix = SearchTopHitProvider.getTopHitAccelerator(); if (rawPattern.startsWith(commandPrefix)) { String typedCommand = rawPattern.split(" ")[0].substring(commandPrefix.length()); List<SearchEverywhereCommandInfo> commands = getCommandsForCompletion(contributors, typedCommand); if (!commands.isEmpty()) { if (rawPattern.contains(" ")) { contributorsMap.keySet().retainAll(commands.stream().map(SearchEverywhereCommandInfo::getContributor).collect(Collectors.toSet())); } else { myListModel.clear(); List<SearchEverywhereFoundElementInfo> lst = ContainerUtil.map(commands, command -> new SearchEverywhereFoundElementInfo(command, 0, myStubCommandContributor)); myListModel.addElements(lst); ScrollingUtil.ensureSelectionExists(myResultsList); } } } mySearchProgressIndicator = mySearcher.search(contributorsMap, rawPattern); }