InspectionWidgetActionProvider: update state after extension changes on EDT

InspectionWidgetActionProvider's state is not protected by any locks and should be accessed on EDT only.
At the same time, extension point events are delivered on a background thread

GitOrigin-RevId: 83b9608c29e19b6d66ac0ac344f5050c39d955d0
This commit is contained in:
Max Medvedev
2024-04-24 13:36:55 +02:00
committed by intellij-monorepo-bot
parent 83cd25885f
commit 06271cdaeb
2 changed files with 15 additions and 9 deletions

View File

@@ -4,6 +4,7 @@ package com.intellij.openapi.editor.markup
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.util.concurrency.annotations.RequiresEdt
interface InspectionWidgetActionProvider {
companion object {
@@ -18,5 +19,6 @@ interface InspectionWidgetActionProvider {
*
* May return null if no action should be created for the given editor.
*/
@RequiresEdt
fun createAction(editor: Editor): AnAction?
}

View File

@@ -441,19 +441,23 @@ public final class EditorMarkupModelImpl extends MarkupModelImpl
InspectionWidgetActionProvider.EP_NAME.addExtensionPointListener(new ExtensionPointListener<>() {
@Override
public void extensionAdded(@NotNull InspectionWidgetActionProvider extension, @NotNull PluginDescriptor pluginDescriptor) {
AnAction action = extension.createAction(myEditor);
if (action != null) {
extensionActions.put(extension, action);
addInspectionWidgetAction(action, null);
}
ApplicationManager.getApplication().invokeLater(() -> {
AnAction action = extension.createAction(myEditor);
if (action != null) {
extensionActions.put(extension, action);
addInspectionWidgetAction(action, null);
}
});
}
@Override
public void extensionRemoved(@NotNull InspectionWidgetActionProvider extension, @NotNull PluginDescriptor pluginDescriptor) {
AnAction action = extensionActions.remove(extension);
if (action != null) {
removeInspectionWidgetAction(action);
}
ApplicationManager.getApplication().invokeLater(() -> {
AnAction action = extensionActions.remove(extension);
if (action != null) {
removeInspectionWidgetAction(action);
}
});
}
}, resourcesDisposable);
}