Cleanup (moving storage VFS listener closer to its service and giving it a saner name)

GitOrigin-RevId: 1ddaa9377108a74b19f3db03b746b1632873f46e
This commit is contained in:
Roman Shevchenko
2024-02-20 00:02:49 +01:00
committed by intellij-monorepo-bot
parent 1dfc5bad15
commit fe6a04f70b
3 changed files with 14 additions and 24 deletions

View File

@@ -5,12 +5,8 @@ package com.intellij.configurationStore
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.*
import com.intellij.openapi.components.StateStorageChooserEx.Resolution
import com.intellij.openapi.diagnostic.debug
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.roots.ProjectModelElement
import com.intellij.openapi.util.io.FileUtilRt
import com.intellij.openapi.vfs.AsyncFileListener
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
import com.intellij.platform.settings.SettingsController
import com.intellij.util.ReflectionUtil
import com.intellij.util.SmartList
@@ -383,22 +379,9 @@ fun removeMacroIfStartsWith(path: String, macro: String): String = path.removePr
internal val Storage.path: String
get() = value.ifEmpty { file }
@Internal
data class Macro(@JvmField val key: String, @JvmField var value: Path)
private class MyAsyncVfsListener : AsyncFileListener {
override fun prepareChange(events: List<VFileEvent>): AsyncFileListener.ChangeApplier? {
LOG.debug { "Got a change in MyAsyncVfsListener: $events" }
service<StorageVirtualFileTracker>().schedule(events)
return null
}
companion object {
private val LOG = logger<MyAsyncVfsListener>()
}
}
private fun createDefaultVirtualTracker(componentManager: ComponentManager?): StorageVirtualFileTracker? {
return if (componentManager == null) null else service<StorageVirtualFileTracker>()
}

View File

@@ -5,9 +5,11 @@ import com.intellij.openapi.components.Service
import com.intellij.openapi.components.StateStorage
import com.intellij.openapi.components.impl.stores.ComponentStorageUtil
import com.intellij.openapi.components.impl.stores.IComponentStore
import com.intellij.openapi.components.service
import com.intellij.openapi.components.stateStore
import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.AsyncFileListener
import com.intellij.openapi.vfs.VfsUtil
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.newvfs.events.*
@@ -63,12 +65,10 @@ internal class StorageVirtualFileTracker {
else {
val path = event.path
storage = filePathToStorage.get(path)
// We don't care about parent directory create (because it doesn't affect anything)
// and move (because it is not a supported case),
// but we should detect deletion - but again, it is not a supported case.
// So, we don't check if some of the registered storages located inside changed directory.
// but if we have DirectoryBasedStorage, we check - if file located inside it
// We don't care about parent directory creation (because it doesn't affect anything) and move (because it is not a supported case),
// but we should detect deletion (though again, it is not a supported case).
// So, we don't check if some of the registered storages located inside changed directory,
// but if we have `DirectoryBasedStorage`, we check if a file is located inside it.
if (storage == null && hasDirectoryBasedStorages && path.endsWith(ComponentStorageUtil.DEFAULT_EXT, ignoreCase = true)) {
storage = filePathToStorage[VfsUtil.getParentDir(path)]
}
@@ -128,3 +128,10 @@ internal class StorageVirtualFileTracker {
}
}
}
private class StorageVfsListener : AsyncFileListener {
override fun prepareChange(events: List<VFileEvent>): AsyncFileListener.ChangeApplier? {
service<StorageVirtualFileTracker>().schedule(events)
return null
}
}

View File

@@ -194,7 +194,7 @@
<applicationService serviceInterface="com.intellij.openapi.components.impl.stores.IComponentStore"
serviceImplementation="com.intellij.configurationStore.ApplicationStoreImpl"/>
<vfs.asyncListener implementation="com.intellij.configurationStore.MyAsyncVfsListener"/>
<vfs.asyncListener implementation="com.intellij.configurationStore.StorageVfsListener"/>
<applicationService serviceInterface="com.intellij.openapi.components.PathMacroManager"
serviceImplementation="com.intellij.configurationStore.ApplicationPathMacroManager"/>