Search in sources :

Example 1 with DaemonProgressIndicator

use of com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator in project intellij-community by JetBrains.

the class OfflineDescriptorResolveResult method createDescriptor.

@Nullable
private static CommonProblemDescriptor createDescriptor(@Nullable RefEntity element, @NotNull OfflineProblemDescriptor offlineDescriptor, @NotNull InspectionToolWrapper toolWrapper, @NotNull InspectionToolPresentation presentation) {
    if (toolWrapper instanceof GlobalInspectionToolWrapper) {
        final LocalInspectionToolWrapper localTool = ((GlobalInspectionToolWrapper) toolWrapper).getSharedLocalInspectionToolWrapper();
        if (localTool != null) {
            final CommonProblemDescriptor descriptor = createDescriptor(element, offlineDescriptor, localTool, presentation);
            if (descriptor != null) {
                return descriptor;
            }
        }
        return createRerunGlobalToolDescriptor((GlobalInspectionToolWrapper) toolWrapper, element);
    }
    if (!(toolWrapper instanceof LocalInspectionToolWrapper))
        return null;
    final InspectionManager inspectionManager = InspectionManager.getInstance(presentation.getContext().getProject());
    final OfflineProblemDescriptor offlineProblemDescriptor = offlineDescriptor;
    if (element instanceof RefElement) {
        final PsiElement psiElement = ((RefElement) element).getElement();
        if (psiElement != null) {
            ProblemDescriptor descriptor = ProgressManager.getInstance().runProcess(() -> runLocalTool(psiElement, inspectionManager, offlineProblemDescriptor, (LocalInspectionToolWrapper) toolWrapper), new DaemonProgressIndicator());
            if (descriptor != null)
                return descriptor;
        }
        return null;
    }
    final List<String> hints = offlineProblemDescriptor.getHints();
    CommonProblemDescriptor descriptor = inspectionManager.createProblemDescriptor(offlineProblemDescriptor.getDescription(), (QuickFix) null);
    final QuickFix[] quickFixes = getFixes(descriptor, hints, presentation);
    if (quickFixes != null) {
        descriptor = inspectionManager.createProblemDescriptor(offlineProblemDescriptor.getDescription(), quickFixes);
    }
    return descriptor;
}
Also used : GlobalInspectionToolWrapper(com.intellij.codeInspection.ex.GlobalInspectionToolWrapper) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) OfflineProblemDescriptor(com.intellij.codeInspection.offline.OfflineProblemDescriptor) OfflineProblemDescriptor(com.intellij.codeInspection.offline.OfflineProblemDescriptor) RefElement(com.intellij.codeInspection.reference.RefElement) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with DaemonProgressIndicator

use of com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator in project intellij-community by JetBrains.

the class InjectedLanguageManagerImpl method startRunInjectors.

@Override
public void startRunInjectors(@NotNull final Document hostDocument, final boolean synchronously) {
    if (myProject.isDisposed())
        return;
    if (!synchronously && ApplicationManager.getApplication().isWriteAccessAllowed())
        return;
    // use cached to avoid recreate PSI in alien project
    final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
    final PsiFile hostPsiFile = documentManager.getCachedPsiFile(hostDocument);
    if (hostPsiFile == null)
        return;
    final ConcurrentList<DocumentWindow> injected = InjectedLanguageUtil.getCachedInjectedDocuments(hostPsiFile);
    if (injected.isEmpty())
        return;
    if (myProgress.isCanceled()) {
        myProgress = new DaemonProgressIndicator();
    }
    final Set<DocumentWindow> newDocuments = Collections.synchronizedSet(new THashSet<>());
    final Processor<DocumentWindow> commitProcessor = documentWindow -> {
        if (myProject.isDisposed())
            return false;
        ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
        if (indicator != null && indicator.isCanceled())
            return false;
        if (documentManager.isUncommited(hostDocument) || !hostPsiFile.isValid())
            return false;
        InjectedLanguageUtil.enumerate(documentWindow, hostPsiFile, (injectedPsi, places) -> {
            DocumentWindow newDocument = (DocumentWindow) injectedPsi.getViewProvider().getDocument();
            if (newDocument != null) {
                PsiDocumentManagerBase.checkConsistency(injectedPsi, newDocument);
                newDocuments.add(newDocument);
            }
        });
        return true;
    };
    final Runnable commitInjectionsRunnable = () -> {
        if (myProgress.isCanceled())
            return;
        JobLauncher.getInstance().invokeConcurrentlyUnderProgress(new ArrayList<>(injected), myProgress, true, commitProcessor);
        synchronized (ourInjectionPsiLock) {
            injected.clear();
            injected.addAll(newDocuments);
        }
    };
    if (synchronously) {
        if (Thread.holdsLock(PsiLock.LOCK)) {
            // hack for the case when docCommit was called from within PSI modification, e.g. in formatter.
            // we can't spawn threads to do injections there, otherwise a deadlock is imminent
            ContainerUtil.process(new ArrayList<>(injected), commitProcessor);
        } else {
            commitInjectionsRunnable.run();
        }
    } else {
        JobLauncher.getInstance().submitToJobThread(() -> ApplicationManagerEx.getApplicationEx().tryRunReadAction(commitInjectionsRunnable), null);
    }
}
Also used : InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) JobLauncher(com.intellij.concurrency.JobLauncher) VirtualFile(com.intellij.openapi.vfs.VirtualFile) EditorWindowImpl(com.intellij.injected.editor.EditorWindowImpl) Document(com.intellij.openapi.editor.Document) THashSet(gnu.trove.THashSet) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) ContainerUtil(com.intellij.util.containers.ContainerUtil) FileContextUtil(com.intellij.psi.impl.source.resolve.FileContextUtil) SmartList(com.intellij.util.SmartList) MultiHostInjector(com.intellij.lang.injection.MultiHostInjector) Project(com.intellij.openapi.project.Project) Segment(com.intellij.openapi.util.Segment) Logger(com.intellij.openapi.diagnostic.Logger) MultiHostRegistrar(com.intellij.lang.injection.MultiHostRegistrar) Extensions(com.intellij.openapi.extensions.Extensions) ProgressManager(com.intellij.openapi.progress.ProgressManager) DumbService(com.intellij.openapi.project.DumbService) DocumentWindow(com.intellij.injected.editor.DocumentWindow) ExtensionPoint(com.intellij.openapi.extensions.ExtensionPoint) ExtensionPointListener(com.intellij.openapi.extensions.ExtensionPointListener) DocumentWindowImpl(com.intellij.injected.editor.DocumentWindowImpl) TextRange(com.intellij.openapi.util.TextRange) Disposable(com.intellij.openapi.Disposable) TestOnly(org.jetbrains.annotations.TestOnly) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ExtensionPointImpl(com.intellij.openapi.extensions.impl.ExtensionPointImpl) ConcurrentList(com.intellij.util.containers.ConcurrentList) PsiDocumentManagerBase(com.intellij.psi.impl.PsiDocumentManagerBase) Processor(com.intellij.util.Processor) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) ApplicationManagerEx(com.intellij.openapi.application.ex.ApplicationManagerEx) PluginDescriptor(com.intellij.openapi.extensions.PluginDescriptor) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) DocumentWindow(com.intellij.injected.editor.DocumentWindow) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)

Example 3 with DaemonProgressIndicator

use of com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator in project intellij-community by JetBrains.

the class MultiHostRegistrarImpl method registerDocument.

// under com.intellij.psi.PsiLock.LOCK
private static PsiFile registerDocument(final DocumentWindowImpl documentWindow, final PsiFile injectedPsi, final Place shreds, final PsiFile hostPsiFile, final PsiDocumentManager documentManager) {
    List<DocumentWindow> injected = InjectedLanguageUtil.getCachedInjectedDocuments(hostPsiFile);
    for (int i = injected.size() - 1; i >= 0; i--) {
        DocumentWindowImpl oldDocument = (DocumentWindowImpl) injected.get(i);
        final PsiFileImpl oldFile = (PsiFileImpl) documentManager.getCachedPsiFile(oldDocument);
        FileViewProvider viewProvider;
        if (oldFile == null || !oldFile.isValid() || !((viewProvider = oldFile.getViewProvider()) instanceof InjectedFileViewProvider) || ((InjectedFileViewProvider) viewProvider).isDisposed()) {
            injected.remove(i);
            Disposer.dispose(oldDocument);
            continue;
        }
        InjectedFileViewProvider oldViewProvider = (InjectedFileViewProvider) viewProvider;
        final ASTNode injectedNode = injectedPsi.getNode();
        final ASTNode oldFileNode = oldFile.getNode();
        assert injectedNode != null : "New node is null";
        if (oldDocument.areRangesEqual(documentWindow)) {
            if (oldFile.getFileType() != injectedPsi.getFileType() || oldFile.getLanguage() != injectedPsi.getLanguage()) {
                injected.remove(i);
                Disposer.dispose(oldDocument);
                continue;
            }
            oldFile.putUserData(FileContextUtil.INJECTED_IN_ELEMENT, injectedPsi.getUserData(FileContextUtil.INJECTED_IN_ELEMENT));
            assert shreds.isValid();
            if (!oldFile.textMatches(injectedPsi)) {
                oldViewProvider.performNonPhysically(() -> {
                    DebugUtil.startPsiModification("injected tree diff");
                    try {
                        final DiffLog diffLog = BlockSupportImpl.mergeTrees(oldFile, oldFileNode, injectedNode, new DaemonProgressIndicator(), oldFileNode.getText());
                        DocumentCommitThread.doActualPsiChange(oldFile, diffLog);
                    } finally {
                        DebugUtil.finishPsiModification();
                    }
                });
            }
            assert shreds.isValid();
            return oldFile;
        }
    }
    injected.add(documentWindow);
    return injectedPsi;
}
Also used : DocumentWindow(com.intellij.injected.editor.DocumentWindow) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) DocumentWindowImpl(com.intellij.injected.editor.DocumentWindowImpl) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) ASTNode(com.intellij.lang.ASTNode) DiffLog(com.intellij.psi.impl.source.text.DiffLog)

Example 4 with DaemonProgressIndicator

use of com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator in project intellij-community by JetBrains.

the class JobUtilTest method checkProgressAndReadAction.

private static void checkProgressAndReadAction(final List<Object> objects, final DaemonProgressIndicator progress, final boolean runInReadAction) throws Throwable {
    final AtomicReference<Throwable> exception = new AtomicReference<>();
    JobLauncher.getInstance().invokeConcurrentlyUnderProgress(objects, progress, runInReadAction, o -> {
        try {
            if (objects.size() <= 1 || JobSchedulerImpl.CORES_COUNT <= JobLauncherImpl.CORES_FORK_THRESHOLD) {
                assertTrue(ApplicationManager.getApplication().isDispatchThread());
            } else {
            }
            ProgressIndicator actualIndicator = ProgressManager.getInstance().getProgressIndicator();
            if (progress == null) {
                assertNotNull(actualIndicator);
                assertTrue(actualIndicator instanceof AbstractProgressIndicatorBase);
            } else {
                assertTrue(actualIndicator instanceof SensitiveProgressWrapper);
                ProgressIndicator original = ((SensitiveProgressWrapper) actualIndicator).getOriginalProgressIndicator();
                assertSame(progress, original);
            }
            assertTrue(!runInReadAction || ApplicationManager.getApplication().isReadAccessAllowed());
        } catch (Throwable e) {
            exception.set(e);
        }
        return true;
    });
    if (exception.get() != null)
        throw exception.get();
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) AbstractProgressIndicatorBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorBase) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 5 with DaemonProgressIndicator

use of com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator in project intellij-community by JetBrains.

the class JobUtilTest method testCorrectProgressAndReadAction.

public void testCorrectProgressAndReadAction() throws Throwable {
    checkProgressAndReadAction(Collections.singletonList(null), new DaemonProgressIndicator(), true);
    checkProgressAndReadAction(Collections.singletonList(null), new DaemonProgressIndicator(), false);
    checkProgressAndReadAction(Collections.emptyList(), new DaemonProgressIndicator(), true);
    checkProgressAndReadAction(Collections.emptyList(), new DaemonProgressIndicator(), false);
    checkProgressAndReadAction(Arrays.asList(new Object(), new Object()), new DaemonProgressIndicator(), true);
    checkProgressAndReadAction(Arrays.asList(new Object(), new Object()), new DaemonProgressIndicator(), false);
    checkProgressAndReadAction(Arrays.asList(new Object(), new Object()), null, false);
}
Also used : DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)

Aggregations

DaemonProgressIndicator (com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)8 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 DocumentWindow (com.intellij.injected.editor.DocumentWindow)2 DocumentWindowImpl (com.intellij.injected.editor.DocumentWindowImpl)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 Document (com.intellij.openapi.editor.Document)2 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)2 ProgressManager (com.intellij.openapi.progress.ProgressManager)2 AbstractProgressIndicatorBase (com.intellij.openapi.progress.util.AbstractProgressIndicatorBase)2 Nullable (org.jetbrains.annotations.Nullable)2 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1 GlobalInspectionToolWrapper (com.intellij.codeInspection.ex.GlobalInspectionToolWrapper)1 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)1 OfflineProblemDescriptor (com.intellij.codeInspection.offline.OfflineProblemDescriptor)1 RefElement (com.intellij.codeInspection.reference.RefElement)1 JobLauncher (com.intellij.concurrency.JobLauncher)1 SensitiveProgressWrapper (com.intellij.concurrency.SensitiveProgressWrapper)1 ThreadDumper (com.intellij.diagnostic.ThreadDumper)1 DelegatingProgressIndicator (com.intellij.ide.util.DelegatingProgressIndicator)1 EditorWindowImpl (com.intellij.injected.editor.EditorWindowImpl)1