IJPL-1044 wrap clinit instance requests in non-cancellable section

GitOrigin-RevId: f63849ca504a01dbae51faac27f29e69f43bff86
This commit is contained in:
Daniil Ovchinnikov
2024-06-17 22:14:27 +02:00
committed by intellij-monorepo-bot
parent 1d063c0d01
commit 07f7cdaf55
17 changed files with 108 additions and 46 deletions

View File

@@ -4,6 +4,7 @@ package com.jetbrains.python
import com.intellij.lang.ASTNode
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.service
import com.intellij.openapi.progress.Cancellation
import com.intellij.psi.PsiElement
import com.intellij.psi.tree.IElementType
import java.util.function.Function
@@ -122,6 +123,10 @@ abstract class PyElementTypesFacade {
abstract val asPatternConstructor: Function<in ASTNode, out PsiElement>
companion object {
val INSTANCE: PyElementTypesFacade by lazy { ApplicationManager.getApplication().service<PyElementTypesFacade>() }
val INSTANCE: PyElementTypesFacade by lazy {
Cancellation.forceNonCancellableSectionInClassInitializer {
ApplicationManager.getApplication().service<PyElementTypesFacade>()
}
}
}
}

View File

@@ -3,6 +3,7 @@ package com.jetbrains.python.formatter;
import com.intellij.formatting.*;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.progress.Cancellation;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CodeStyleSettings;
@@ -20,7 +21,9 @@ import static com.jetbrains.python.PyTokenTypes.*;
@SuppressWarnings("UseOfSystemOutOrSystemErr")
public class PythonFormattingModelBuilder implements FormattingModelBuilder, CustomFormattingModelBuilder {
private static final boolean DUMP_FORMATTING_AST = false;
static final TokenSet STATEMENT_OR_DECLARATION = PythonDialectsTokenSetProvider.getInstance().getStatementTokens();
static final TokenSet STATEMENT_OR_DECLARATION = Cancellation.forceNonCancellableSectionInClassInitializer(
() -> PythonDialectsTokenSetProvider.getInstance().getStatementTokens()
);
private static final TokenSet STAR_PATTERNS = TokenSet.create(SINGLE_STAR_PATTERN, DOUBLE_STAR_PATTERN);
private static final TokenSet EXPRESSIONS_WITH_COLON = TokenSet.create(KEY_VALUE_EXPRESSION, KEY_VALUE_PATTERN, LAMBDA_EXPRESSION);

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.codeInsight.typing
import com.google.common.cache.Cache
@@ -15,6 +15,7 @@ import com.intellij.notification.NotificationType
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleUtilCore
import com.intellij.openapi.progress.Cancellation
import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.util.Key
@@ -48,7 +49,9 @@ private class PyStubPackagesAdvertiser : PyInspection() {
"traits" to "traits") // top-level package to package on PyPI, sorted by the latter
private val BALLOON_SHOWING = Key.create<Boolean>("showingStubPackagesAdvertiserBalloon")
private val BALLOON_NOTIFICATIONS = NotificationGroupManager.getInstance().getNotificationGroup("Python Stub Packages Advertiser")
private val BALLOON_NOTIFICATIONS = Cancellation.forceNonCancellableSectionInClassInitializer {
NotificationGroupManager.getInstance().getNotificationGroup("Python Stub Packages Advertiser")
}
}
var ignoredPackages: MutableList<String> = mutableListOf()

View File

@@ -11,7 +11,6 @@ import com.intellij.codeInspection.util.InspectionMessage;
import com.intellij.codeInspection.util.IntentionFamilyName;
import com.intellij.core.CoreBundle;
import com.intellij.execution.ExecutionException;
import com.intellij.icons.AllIcons;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.idea.ActionsBundle;
import com.intellij.model.SideEffectGuard;
@@ -20,10 +19,10 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.progress.Cancellation;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.ui.DoNotAskOption;
import com.intellij.openapi.ui.MessageDialogBuilder;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.JDOMExternalizableStringList;
import com.intellij.openapi.util.NlsSafe;
@@ -63,7 +62,9 @@ import static com.intellij.codeInspection.options.OptPane.pane;
public final class PyPackageRequirementsInspection extends PyInspection {
public JDOMExternalizableStringList ignoredPackages = new JDOMExternalizableStringList();
private static final @NotNull NotificationGroup BALLOON_NOTIFICATIONS = NotificationGroupManager.getInstance().getNotificationGroup("Package requirements");
private static final @NotNull NotificationGroup BALLOON_NOTIFICATIONS = Cancellation.forceNonCancellableSectionInClassInitializer(
() -> NotificationGroupManager.getInstance().getNotificationGroup("Package requirements")
);
@Override
public @NotNull OptPane getOptionsPane() {

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.sdk.pipenv
import com.google.gson.Gson
@@ -29,6 +29,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleUtil
import com.intellij.openapi.module.ModuleUtilCore
import com.intellij.openapi.progress.Cancellation
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.Task
@@ -45,11 +46,11 @@ import com.intellij.openapi.vfs.StandardFileSystems
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.util.PathUtil
import com.jetbrains.python.PyBundle
import com.jetbrains.python.icons.PythonIcons
import com.jetbrains.python.inspections.PyPackageRequirementsInspection
import com.jetbrains.python.packaging.*
import com.jetbrains.python.sdk.*
import com.jetbrains.python.sdk.flavors.PythonSdkFlavor
import com.jetbrains.python.icons.PythonIcons
import org.jetbrains.annotations.SystemDependent
import org.jetbrains.annotations.TestOnly
import java.io.File
@@ -394,7 +395,9 @@ private val Document.virtualFile: VirtualFile?
private fun VirtualFile.getModule(project: Project): Module? =
ModuleUtil.findModuleForFile(this, project)
private val LOCK_NOTIFICATION_GROUP = NotificationGroupManager.getInstance().getNotificationGroup("Pipfile Watcher")
private val LOCK_NOTIFICATION_GROUP = Cancellation.forceNonCancellableSectionInClassInitializer {
NotificationGroupManager.getInstance().getNotificationGroup("Pipfile Watcher")
}
private val Sdk.packageManager: PyPackageManager
get() = PyPackageManagers.getInstance().forSdk(this)