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