Skip to content

Commit

Permalink
register PSW extensions firsts
Browse files Browse the repository at this point in the history
  • Loading branch information
LeFrosch committed Oct 21, 2024
1 parent cd26202 commit 3044283
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
26 changes: 26 additions & 0 deletions base/src/com/google/idea/blaze/base/util/ScopeService.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.google.idea.blaze.base.util

import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
Expand All @@ -9,6 +10,16 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel

@Service(Service.Level.APP)
private class PluginScopeService : Disposable {
// #api223 use the injected scope
val scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)

override fun dispose() {
scope.cancel()
}
}

@Service(Service.Level.PROJECT)
private class ProjectScopeService : Disposable {
// #api223 use the injected scope
Expand All @@ -19,7 +30,22 @@ private class ProjectScopeService : Disposable {
}
}

/**
* Gets a disposable that is disposed when either the project is closed or the plugin is unloaded.
*/
fun pluginProjectDisposable(project: Project): Disposable = project.service<ProjectScopeService>()

/**
* Gets a coroutine scope that is canceled when either the project is closed or the plugin is unloaded.
*/
fun pluginProjectScope(project: Project): CoroutineScope = project.service<ProjectScopeService>().scope

/**
* Gets a disposable that is disposed when either the application is closed or the plugin is unloaded.
*/
fun pluginDisposable(): Disposable = ApplicationManager.getApplication().service<PluginScopeService>()

/**
* Gets a coroutine scope that is disposed when either the application is closed or the plugin is unloaded.
*/
fun pluginScope(): CoroutineScope = ApplicationManager.getApplication().service<PluginScopeService>().scope
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ package com.google.idea.blaze.clwb

import com.google.idea.blaze.base.lang.buildfile.language.BuildFileType
import com.google.idea.blaze.base.settings.Blaze
import com.google.idea.blaze.base.util.pluginDisposable
import com.google.idea.blaze.base.wizard2.BazelImportCurrentProjectAction
import com.google.idea.blaze.base.wizard2.BazelNotificationProvider
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.extensions.LoadingOrder
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.ui.EditorNotificationProvider
Expand Down Expand Up @@ -49,13 +51,13 @@ private fun unregisterGenericProvider(project: Project) {

private fun registerSpecificProvider() {
val projectFixes = ProjectFixesProvider.Companion.EP_NAME.point
projectFixes.registerExtension(CLionNotificationProvider())
projectFixes.registerExtension(CLionNotificationProvider(), LoadingOrder.FIRST, pluginDisposable())

val projectNotifications = EditorNotificationWarningProvider.EP_NAME.point
projectNotifications.registerExtension(CLionNotificationProvider())
projectNotifications.registerExtension(CLionNotificationProvider(), LoadingOrder.FIRST, pluginDisposable())

val widgetStatus = WidgetStatusProvider.EP_NAME.point
widgetStatus.registerExtension(CLionNotificationProvider())
widgetStatus.registerExtension(CLionNotificationProvider(), LoadingOrder.FIRST, pluginDisposable())
}

private fun isBazelAwareFile(project: Project, file: VirtualFile): Boolean {
Expand Down

0 comments on commit 3044283

Please sign in to comment.