Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package com.sina.weibo.agent.actors

import com.intellij.openapi.Disposable
import com.intellij.openapi.diagnostic.Logger
import com.sina.weibo.agent.plugin.SystemObjectProvider
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package com.sina.weibo.agent.actors

import com.intellij.openapi.Disposable
import com.intellij.openapi.diagnostic.Logger
import com.sina.weibo.agent.plugin.SystemObjectProvider
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.intellij.openapi.Disposable
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.WindowManager
import com.sina.weibo.agent.plugin.SystemObjectProvider
import com.sina.weibo.agent.plugin.WecoderPluginService
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,55 +15,66 @@ import java.util.concurrent.ConcurrentHashMap
*/
object SystemObjectProvider {
private val logger = Logger.getInstance(SystemObjectProvider::class.java)

// Mapping for storing system objects
private val systemObjects = ConcurrentHashMap<String, Any>()


/**
* System object keys
*/
// Mapping for storing system objects per project instance
private val projectObjects = ConcurrentHashMap<Project, ConcurrentHashMap<String, Any>>()

/**
* System object keys
*/
object Keys {
const val APPLICATION = "application"
// More system object keys can be added
// More system object keys can be added
}
/**
* Initialize the system object provider
* @param project current project
*/

/**
* Initialize the system object provider for a project
* @param project current project
*/
fun initialize(project: Project) {
logger.info("Initializing SystemObjectProvider with project: ${project.name}")

register(Keys.APPLICATION, ApplicationManager.getApplication())
val objects = projectObjects.computeIfAbsent(project) { ConcurrentHashMap() }
objects[Keys.APPLICATION] = ApplicationManager.getApplication()
}

/**
* Register a system object
* @param key object key
* @param obj object instance
*/
fun register(key: String, obj: Any) {
systemObjects[key] = obj
logger.debug("Registered system object: $key")

/**
* Register a system object for a project
* @param project current project
* @param key object key
* @param obj object instance
*/
fun register(project: Project, key: String, obj: Any) {
val objects = projectObjects.computeIfAbsent(project) { ConcurrentHashMap() }
objects[key] = obj
logger.debug("Registered system object for project ${project.name}: $key")
}

/**
* Get a system object
* @param key object key
* @return object instance or null
*/

/**
* Get a system object for a project
* @param project current project
* @param key object key
* @return object instance or null
*/
@Suppress("UNCHECKED_CAST")
fun <T> get(key: String): T? {
return systemObjects[key] as? T
fun <T> get(project: Project, key: String): T? {
return projectObjects[project]?.get(key) as? T
}

/**
* Clean up resources for a project
*/
fun dispose(project: Project) {
logger.info("Disposing SystemObjectProvider for project: ${project.name}")
projectObjects.remove(project)?.clear()
}


/**
* Clean up resources
*/
fun dispose() {
logger.info("Disposing SystemObjectProvider")
systemObjects.clear()
/**
* Clean up resources for all projects
*/
fun disposeAll() {
logger.info("Disposing SystemObjectProvider for all projects")
projectObjects.clear()
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class WecoderPlugin : StartupActivity.DumbAware {
LOG.info("Disposing RunVSAgent plugin for project: ${project.name}")
pluginService.dispose()
extensionManager.dispose()
SystemObjectProvider.dispose()
SystemObjectProvider.dispose(project)
})

LOG.info("RunVSAgent plugin initialized successfully for project: ${project.name}")
Expand Down Expand Up @@ -359,7 +359,7 @@ class WecoderPluginService(private var currentProject: Project) : Disposable {
udsSocketServer.project = project

// Register to system object provider
SystemObjectProvider.register("pluginService", this)
SystemObjectProvider.register(project, "pluginService", this)

// Start initialization in background thread
coroutineScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ class RunVSAgentToolWindowFactory : ToolWindowFactory {
logger.info("Disposing RunVSAgent plugin for project: ${project.name}")
pluginService.dispose()
extensionManager.dispose()
SystemObjectProvider.dispose()
SystemObjectProvider.dispose(project)
// Reset state when disposing
isPluginRunning = false
isPluginStarting = false
Expand Down