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;
}
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);
}
}
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;
}
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();
}
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);
}
Aggregations