[tests] ensure to quickly return navigatable and do slow navigate when needed later

EA-331746 - T: FileBasedIndexImpl.ensureUpToDate

GitOrigin-RevId: b5feaf5c4c97d4e659db268fbe685b3ed1d81157
This commit is contained in:
Anna Kozlova
2021-07-27 06:56:25 +00:00
committed by intellij-monorepo-bot
parent 8f07b83138
commit 658e24ec59
2 changed files with 37 additions and 8 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2020 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.
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.testframework.sm.runner;
import com.intellij.execution.Location;
@@ -17,6 +17,8 @@ import com.intellij.ide.DataManager;
import com.intellij.ide.nls.NlsMessages;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.ExecutionDataKeys;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
@@ -30,6 +32,7 @@ import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.CachedValue;
import com.intellij.psi.util.CachedValueProvider;
import com.intellij.psi.util.CachedValuesManager;
import com.intellij.util.concurrency.AppExecutorUtil;
import com.intellij.util.concurrency.annotations.RequiresEdt;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
@@ -46,7 +49,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
*
* @author Roman Chernyatchik
*/
public class SMTestProxy extends AbstractTestProxy {
public class SMTestProxy extends AbstractTestProxy implements Navigatable {
public static final Key<String> NODE_ID = Key.create("test.proxy.id");
private static final Logger LOG = Logger.getInstance(SMTestProxy.class.getName());
@@ -268,6 +271,34 @@ public class SMTestProxy extends AbstractTestProxy {
return myConfig;
}
private Navigatable getNavigatable() {
SMRootTestProxy root = getRoot();
if (root == null) return null;
return TestsUIUtil.getOpenFileDescriptor(this, root.myTestConsoleProperties);
}
@Override
public void navigate(boolean requestFocus) {
ReadAction.nonBlocking(() -> getNavigatable())
.expireWith(this)
.finishOnUiThread(ModalityState.NON_MODAL, navigatable -> {
if (navigatable != null) {
navigatable.navigate(requestFocus);
}
}).submit(AppExecutorUtil.getAppExecutorService());
}
@Override
public boolean canNavigate() {
Navigatable navigatable = getNavigatable();
return navigatable != null && navigatable.canNavigate();
}
@Override
public boolean canNavigateToSource() {
return canNavigate();
}
@Override
@Nullable
public Location getLocation(@NotNull Project project, @NotNull GlobalSearchScope searchScope) {
@@ -1,4 +1,4 @@
// Copyright 2000-2020 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.
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.testframework;
import com.intellij.execution.Location;
@@ -102,9 +102,10 @@ public abstract class TestTreeView extends Tree implements DataProvider, CopyPro
AbstractTestProxy testProxy = getSelectedTest(selectionPath);
if (testProxy == null) return null;
if (AbstractTestProxy.DATA_KEY.is(dataId)) {
if (AbstractTestProxy.DATA_KEY.is(dataId) || CommonDataKeys.NAVIGATABLE.is(dataId)) {
return testProxy;
}
if (PlatformDataKeys.SLOW_DATA_PROVIDERS.is(dataId)) {
TestFrameworkRunningModel model = myModel;
return Collections.<DataProvider>singletonList(dataId1 -> getSlowData(dataId1, testProxy, model));
@@ -125,10 +126,7 @@ public abstract class TestTreeView extends Tree implements DataProvider, CopyPro
@NotNull TestFrameworkRunningModel model) {
Project project = model.getProperties().getProject();
if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
return TestsUIUtil.getOpenFileDescriptor(testProxy, model);
}
else if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
Location<?> location = testProxy.getLocation(project, model.getProperties().getScope());
PsiElement psiElement = location != null ? location.getPsiElement() : null;
return psiElement == null || !psiElement.isValid() ? null : psiElement;