mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
following IDEA-CR-8206 (IDEA-151182)
This commit is contained in:
+3
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -1172,18 +1172,14 @@ public class DocumentationManager extends DockablePopupManager<DocumentationComp
|
||||
}
|
||||
|
||||
final Ref<String> result = new Ref<String>();
|
||||
long deadline = System.currentTimeMillis() + DOC_GENERATION_TIMEOUT_MILLISECONDS;
|
||||
while (!ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(new Runnable() {
|
||||
ProgressIndicatorUtils.runInReadActionWithWriteActionPriorityWithRetries(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final SmartPsiElementPointer originalElement = myElement.getUserData(ORIGINAL_ELEMENT_KEY);
|
||||
String doc = provider.generateDoc(myElement, originalElement != null ? originalElement.getElement() : null);
|
||||
result.set(doc);
|
||||
}
|
||||
}) && System.currentTimeMillis() < deadline) {
|
||||
//noinspection BusyWait
|
||||
Thread.sleep(DOC_GENERATION_PAUSE_MILLISECONDS);
|
||||
}
|
||||
}, DOC_GENERATION_TIMEOUT_MILLISECONDS, DOC_GENERATION_PAUSE_MILLISECONDS);
|
||||
return result.get();
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -295,12 +295,14 @@ public class QuickDocOnMouseOverManager {
|
||||
@Override
|
||||
public void run() {
|
||||
Ref<PsiElement> targetElementRef = new Ref<>();
|
||||
ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(new Runnable() {
|
||||
ProgressIndicatorUtils.runInReadActionWithWriteActionPriorityWithRetries(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
targetElementRef.set(docManager.findTargetElement(editor, offset, originalElement.getContainingFile(), originalElement));
|
||||
if (originalElement.isValid()) {
|
||||
targetElementRef.set(docManager.findTargetElement(editor, offset, originalElement.getContainingFile(), originalElement));
|
||||
}
|
||||
}
|
||||
});
|
||||
}, 5000, 100);
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
+24
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,6 +31,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.ide.PooledThreadExecutor;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
/**
|
||||
* Methods in this class are used to equip long background processes which take read actions with a special listener
|
||||
@@ -66,9 +67,30 @@ public class ProgressIndicatorUtils {
|
||||
scheduleWithWriteActionPriority(progressIndicator, PooledThreadExecutor.INSTANCE, readTask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeatedly tries to run given task in read action without blocking write actions (for this to work effectively the action should invoke
|
||||
* {@link ProgressManager#checkCanceled()} or {@link ProgressIndicator#checkCanceled()} often enough).
|
||||
*
|
||||
* @param action task to run
|
||||
* @param timeout timeout in milliseconds
|
||||
* @param pauseBetweenRetries pause between retries in milliseconds
|
||||
* @return <code>true</code> if the action succeeded to run without interruptions, <code>false</code> otherwise
|
||||
* @throws InterruptedException if execution was interrupted while waiting for the next attempt
|
||||
*/
|
||||
public static boolean runInReadActionWithWriteActionPriorityWithRetries(@NotNull final Runnable action,
|
||||
long timeout, long pauseBetweenRetries) {
|
||||
boolean result;
|
||||
long deadline = System.currentTimeMillis() + timeout;
|
||||
while (!(result = runInReadActionWithWriteActionPriority(action)) && System.currentTimeMillis() < deadline) {
|
||||
LockSupport.parkNanos(pauseBetweenRetries * 1000);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method attempts to run provided action synchronously in a read action, so that, if possible, it wouldn't impact any pending,
|
||||
* executing or future write actions.
|
||||
* executing or future write actions (for this to work effectively the action should invoke {@link ProgressManager#checkCanceled()} or
|
||||
* {@link ProgressIndicator#checkCanceled()} often enough).
|
||||
* It returns <code>true</code> if action was executed successfully. It returns <code>false</code> if the action was not
|
||||
* executed successfully, i.e. if:
|
||||
* <ul>
|
||||
|
||||
Reference in New Issue
Block a user