CPP-10107 Freezes while looking up Doxygen comments

avoid multiple requests running simultaneously on different threads
This commit is contained in:
Dmitry Batrak
2018-01-11 19:57:30 +03:00
parent bc7d9fa388
commit 6e71e9ddbd
@@ -1,17 +1,5 @@
/*
* Copyright 2000-2017 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package com.intellij.codeInsight.navigation;
@@ -34,7 +22,6 @@ import com.intellij.navigation.NavigationItem;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.actionSystem.impl.ActionButton;
import com.intellij.openapi.actionSystem.impl.PresentationFactory;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.AbstractProjectComponent;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
@@ -100,6 +87,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.EventObject;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
public class CtrlMouseHandler extends AbstractProjectComponent {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.navigation.CtrlMouseHandler");
@@ -115,6 +103,7 @@ public class CtrlMouseHandler extends AbstractProjectComponent {
private final DocumentationManager myDocumentationManager;
@Nullable private Point myPrevMouseLocation;
private LightweightHint myHint;
private final AtomicReference<ProgressIndicator> myCurrentRequestProgress = new AtomicReference<>();
public enum BrowseMode {None, Declaration, TypeDeclaration, Implementation}
@@ -652,7 +641,8 @@ public class CtrlMouseHandler extends AbstractProjectComponent {
@NotNull final Consumer<String> newTextConsumer,
@NotNull final LightweightHint hint)
{
myDocAlarm.cancelAllRequests();
ProgressIndicatorBase progress = new ProgressIndicatorBase();
myCurrentRequestProgress.set(progress);
myDocAlarm.addRequest(() -> {
final Ref<String> fullTextRef = new Ref<>();
final Ref<String> qualifiedNameRef = new Ref<>();
@@ -668,7 +658,8 @@ public class CtrlMouseHandler extends AbstractProjectComponent {
qualifiedNameRef.set(((PsiQualifiedNamedElement)anchorElement).getQualifiedName());
}
}
}, DOC_GENERATION_TIMEOUT_MS, DOC_GENERATION_RETRY_DELAY_MS, null);
}, DOC_GENERATION_TIMEOUT_MS, DOC_GENERATION_RETRY_DELAY_MS, progress);
myCurrentRequestProgress.compareAndSet(progress, null);
String fullText = fullTextRef.get();
if (fullText == null) {
return;
@@ -930,6 +921,8 @@ public class CtrlMouseHandler extends AbstractProjectComponent {
}
});
myDocAlarm.cancelAllRequests();
ProgressIndicator currentIndicator = myCurrentRequestProgress.getAndSet(null);
if (currentIndicator != null) currentIndicator.cancel();
if (newTextConsumer != null && docInfo.docProvider != null && docInfo.documentationAnchor != null) {
fulfillDocInfo(docInfo.text, docInfo.docProvider, info.myElementAtPointer, docInfo.documentationAnchor, newTextConsumer, hint);
}