From 6e71e9ddbda65bb681b18cdcbd5603a914e32eab Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Thu, 11 Jan 2018 18:03:12 +0300 Subject: [PATCH] CPP-10107 Freezes while looking up Doxygen comments avoid multiple requests running simultaneously on different threads --- .../navigation/CtrlMouseHandler.java | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java index 058568f7fc46..2a8fcbfcf9ff 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java @@ -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 myCurrentRequestProgress = new AtomicReference<>(); public enum BrowseMode {None, Declaration, TypeDeclaration, Implementation} @@ -652,7 +641,8 @@ public class CtrlMouseHandler extends AbstractProjectComponent { @NotNull final Consumer newTextConsumer, @NotNull final LightweightHint hint) { - myDocAlarm.cancelAllRequests(); + ProgressIndicatorBase progress = new ProgressIndicatorBase(); + myCurrentRequestProgress.set(progress); myDocAlarm.addRequest(() -> { final Ref fullTextRef = new Ref<>(); final Ref 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); }