Skip to content
Open
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
11 changes: 11 additions & 0 deletions src/main/kotlin/insyncwithfoo/ryecharm/Loaders.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package insyncwithfoo.ryecharm

import kotlin.reflect.KClass


internal val ClassLoader.id: Int
get() = System.identityHashCode(this)


internal val KClass<*>.loaderID: Int
get() = java.classLoader.id
13 changes: 11 additions & 2 deletions src/main/kotlin/insyncwithfoo/ryecharm/RootDisposable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@ package insyncwithfoo.ryecharm
import com.intellij.openapi.Disposable
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.project.Project


@Service(Service.Level.APP, Service.Level.PROJECT)
internal class RootDisposable : Disposable {
internal class RootDisposable(private val project: Project? = null) : Disposable {

override fun dispose() {}
init {
thisLogger().info("RootDisposable initialized; $project; ${this::class.loaderID}")
thisLogger().info(Throwable().stackTraceToString())
}

override fun dispose() {
thisLogger().info("RootDisposable disposed; $project; ${this::class.loaderID}")
thisLogger().info(Throwable().stackTraceToString())
}

companion object {
fun getInstance() = service<RootDisposable>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package insyncwithfoo.ryecharm.configurations

import com.intellij.openapi.Disposable
import com.intellij.openapi.components.BaseState
import com.intellij.openapi.components.SimplePersistentStateComponent
import com.intellij.openapi.diagnostic.thisLogger
import insyncwithfoo.ryecharm.loaderID


/**
Expand All @@ -11,4 +14,18 @@ import com.intellij.openapi.components.SimplePersistentStateComponent
*
* @see SimplePersistentStateComponent
*/
internal open class ConfigurationService<S : BaseState>(state: S) : SimplePersistentStateComponent<S>(state)
internal open class ConfigurationService<S : BaseState>(state: S) :
SimplePersistentStateComponent<S>(state), Disposable
{

init {
thisLogger().info("${this::class.qualifiedName} initialized; ${this::class.loaderID}")
thisLogger().info(Throwable().stackTraceToString())
}

override fun dispose() {
thisLogger().info("${this::class.qualifiedName} disposed; ${this::class.loaderID}")
thisLogger().info(Throwable().stackTraceToString())
}

}
20 changes: 15 additions & 5 deletions src/main/kotlin/insyncwithfoo/ryecharm/ruff/RuffCache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import com.intellij.ide.util.PropertiesComponent
import com.intellij.openapi.Disposable
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
import insyncwithfoo.ryecharm.RootDisposable
import insyncwithfoo.ryecharm.RyeCharm
import insyncwithfoo.ryecharm.loaderID
import insyncwithfoo.ryecharm.parseAsJSON
import insyncwithfoo.ryecharm.propertiesComponent
import insyncwithfoo.ryecharm.ruff.documentation.RuleName
Expand Down Expand Up @@ -39,10 +40,11 @@ private operator fun PropertiesComponent.set(property: KProperty<*>, value: Stri


@Service(Service.Level.PROJECT)
private class ParseCache : Disposable {
private class ParseCache(private val project: Project) : Disposable {

init {
Disposer.register(RootDisposable.getInstance(), this)
thisLogger().info("ParseCache initialized; $project; ${this::class.loaderID}")
thisLogger().info(Throwable().stackTraceToString())
}

private val parsed = mutableMapOf<String, CachedResult<*>>()
Expand All @@ -63,6 +65,8 @@ private class ParseCache : Disposable {
}

override fun dispose() {
thisLogger().info("ParseCache disposed; $project; ${this::class.loaderID}")
thisLogger().info(Throwable().stackTraceToString())
clear()
}

Expand All @@ -72,8 +76,13 @@ private class ParseCache : Disposable {
@Service(Service.Level.PROJECT)
internal class RuffCache(private val project: Project) : Disposable {

init {
thisLogger().info("RuffCache initialized; $project; ${this::class.loaderID}")
thisLogger().info(Throwable().stackTraceToString())
}

private val parseCache: ParseCache
get() = project.service<ParseCache>()
get() = project.service<ParseCache>().also { Disposer.register(this, it) }

private val storage: PropertiesComponent
get() = project.propertiesComponent
Expand Down Expand Up @@ -108,7 +117,8 @@ internal class RuffCache(private val project: Project) : Disposable {
}

override fun dispose() {
clear()
thisLogger().info("RuffCache disposed; $project; ${this::class.loaderID}")
thisLogger().info(Throwable().stackTraceToString())
}

companion object {
Expand Down
Loading