Add checkCanceled on common for autocompletion and highlighting resolve path

This commit is contained in:
Vladimir Dolzhenko
2020-02-24 18:06:08 +01:00
parent 9c530b1121
commit 15e2afe5ab
7 changed files with 25 additions and 0 deletions
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.resolve;
import com.google.common.collect.Maps;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.util.containers.Queue;
@@ -196,6 +197,8 @@ public class BodyResolver {
Set<ConstructorDescriptor> visitedInCurrentChain = new HashSet<>();
ConstructorDescriptor currentConstructorDescriptor = constructorDescriptor;
while (true) {
ProgressManager.checkCanceled();
visitedInCurrentChain.add(currentConstructorDescriptor);
ConstructorDescriptor delegatedConstructorDescriptor = getDelegatedConstructor(currentConstructorDescriptor);
if (delegatedConstructorDescriptor == null) break;
@@ -267,6 +270,8 @@ public class BodyResolver {
@NotNull LexicalScope scopeForConstructorResolution,
@NotNull LexicalScope scopeForMemberResolution
) {
ProgressManager.checkCanceled();
LexicalScope scopeForConstructor =
primaryConstructor == null
? null
@@ -399,6 +404,8 @@ public class BodyResolver {
}
for (KtSuperTypeListEntry delegationSpecifier : ktClass.getSuperTypeListEntries()) {
ProgressManager.checkCanceled();
delegationSpecifier.accept(visitor);
}
@@ -657,6 +664,8 @@ public class BodyResolver {
@NotNull KtAnonymousInitializer anonymousInitializer,
@NotNull ClassDescriptorWithResolutionScopes classDescriptor
) {
ProgressManager.checkCanceled();
LexicalScope scopeForInitializers = classDescriptor.getScopeForInitializerResolution();
KtExpression body = anonymousInitializer.getBody();
if (body != null) {
@@ -935,6 +944,8 @@ public class BodyResolver {
// Creates wrapper scope for header resolution if necessary (see resolveSecondaryConstructorBody)
@Nullable Function1<LexicalScope, LexicalScope> headerScopeFactory
) {
ProgressManager.checkCanceled();
PreliminaryDeclarationVisitor.Companion.createForDeclaration(function, trace, languageVersionSettings);
LexicalScope innerScope = FunctionDescriptorUtil.getFunctionInnerScope(scope, functionDescriptor, trace, overloadChecker);
List<KtParameter> valueParameters = function.getValueParameters();
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.resolve;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -270,6 +271,7 @@ public class ModifiersChecker {
missingSupertypesResolver
);
for (DeclarationChecker checker : declarationCheckers) {
ProgressManager.checkCanceled();
checker.check(declaration, descriptor, context);
}
OperatorModifierChecker.INSTANCE.check(declaration, descriptor, trace, languageVersionSettings);
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.resolve.lazy;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.*;
@@ -70,6 +71,8 @@ public class ForceResolveUtil {
}
private static void doForceResolveAllContents(Object object) {
ProgressManager.checkCanceled();
if (object instanceof LazyEntity) {
LazyEntity lazyEntity = (LazyEntity) object;
lazyEntity.forceResolveAllContents();
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.types.expressions;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -303,6 +304,7 @@ public class ExpressionTypingServices {
boolean isFirstStatement = true;
for (Iterator<? extends KtElement> iterator = block.iterator(); iterator.hasNext(); ) {
ProgressManager.checkCanceled();
// Use filtering trace to keep effect system cache only for one statement
AbstractFilteringTrace traceForSingleStatement = new EffectsFilteringTrace(context.trace);
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.types.expressions;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.IndexNotReadyException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -159,6 +160,7 @@ public abstract class ExpressionTypingVisitorDispatcher extends KtVisitor<Kotlin
@NotNull
private KotlinTypeInfo getTypeInfo(@NotNull KtExpression expression, ExpressionTypingContext context, KtVisitor<KotlinTypeInfo, ExpressionTypingContext> visitor) {
ProgressManager.checkCanceled();
return typeInfoPerfCounter.time(() -> {
try {
KotlinTypeInfo recordedTypeInfo = BindingContextUtils.getRecordedTypeInfo(expression, context.trace.getBindingContext());
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.asJava.classes
import com.intellij.openapi.progress.ProgressManager
import com.intellij.psi.*
import com.intellij.psi.impl.light.LightMethodBuilder
import com.intellij.psi.impl.light.LightModifierList
@@ -174,6 +175,7 @@ internal class UltraLightMembersCreator(
numberOfDefaultParametersToAdd: Int = -1,
methodIndex: Int
): KtLightMethod {
ProgressManager.checkCanceled()
val isConstructor = ktFunction is KtConstructor<*>
val name =
if (isConstructor) containingClass.name
@@ -17,6 +17,7 @@ import com.intellij.codeInspection.ex.EntryPointsManagerBase
import com.intellij.codeInspection.ex.EntryPointsManagerImpl
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.text.StringUtil
import com.intellij.psi.PsiClass
@@ -201,6 +202,7 @@ class UnusedSymbolInspection : AbstractKotlinInspection() {
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
return namedDeclarationVisitor(fun(declaration) {
ProgressManager.checkCanceled()
val message = declaration.describe()?.let { "$it is never used" } ?: return
if (!ProjectRootsUtil.isInProjectSource(declaration)) return
@@ -321,6 +323,7 @@ class UnusedSymbolInspection : AbstractKotlinInspection() {
private val KtNamedDeclaration.isObjectOrEnum: Boolean get() = this is KtObjectDeclaration || this is KtClass && isEnum()
private fun checkReference(ref: PsiReference, declaration: KtNamedDeclaration, descriptor: DeclarationDescriptor?): Boolean {
ProgressManager.checkCanceled()
if (declaration.isAncestor(ref.element)) return true // usages inside element's declaration are not counted
if (ref.element.parent is KtValueArgumentName) return true // usage of parameter in form of named argument is not counted