mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 15:06:56 +07:00
IJPL-149878 IJent WSL FS refactoring: get rid of interface IjentNioFsStrategy
There were two implementations. One of them did nothing. It was easily replaced with a nullable class. GitOrigin-RevId: 0070d7c08c56ef4ccf530d2b13c9d8e1c09585a7
This commit is contained in:
committed by
intellij-monorepo-bot
parent
79eeb3ca76
commit
5ce0d4c891
@@ -10,7 +10,9 @@ import com.intellij.platform.ijent.IjentId
|
||||
import com.intellij.platform.ijent.community.impl.nio.IjentNioFileSystemProvider
|
||||
import com.intellij.platform.ijent.community.impl.nio.telemetry.TracingFileSystemProvider
|
||||
import com.intellij.util.containers.forEachGuaranteed
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.job
|
||||
import kotlinx.coroutines.launch
|
||||
import java.net.URI
|
||||
import java.nio.file.FileSystem
|
||||
import java.nio.file.FileSystemAlreadyExistsException
|
||||
@@ -18,30 +20,15 @@ import java.nio.file.spi.FileSystemProvider
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.function.BiConsumer
|
||||
|
||||
internal interface IjentWslNioFsToggleStrategy {
|
||||
fun initialize()
|
||||
val isInitialized: Boolean
|
||||
fun enable(distro: WSLDistribution, ijentId: IjentId)
|
||||
fun disable(distro: WSLDistribution)
|
||||
}
|
||||
|
||||
internal object FallbackIjentWslNioFsToggleStrategy : IjentWslNioFsToggleStrategy {
|
||||
override val isInitialized: Boolean = false
|
||||
override fun initialize(): Unit = Unit
|
||||
override fun enable(distro: WSLDistribution, ijentId: IjentId): Unit = Unit
|
||||
override fun disable(distro: WSLDistribution): Unit = Unit
|
||||
}
|
||||
|
||||
internal class DefaultIjentWslNioFsToggleStrategy(
|
||||
internal class IjentWslNioFsToggleStrategy(
|
||||
multiRoutingFileSystemProvider: FileSystemProvider,
|
||||
private val coroutineScope: CoroutineScope,
|
||||
) : IjentWslNioFsToggleStrategy {
|
||||
) {
|
||||
private val ownFileSystems = OwnFileSystems(multiRoutingFileSystemProvider)
|
||||
|
||||
override val isInitialized: Boolean = true
|
||||
val isInitialized: Boolean = true
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
override fun initialize() {
|
||||
fun initialize() {
|
||||
coroutineScope.coroutineContext.job.invokeOnCompletion {
|
||||
ownFileSystems.unregisterAll()
|
||||
}
|
||||
@@ -86,7 +73,7 @@ internal class DefaultIjentWslNioFsToggleStrategy(
|
||||
}
|
||||
}
|
||||
|
||||
override fun enable(distro: WSLDistribution, ijentId: IjentId) {
|
||||
fun enable(distro: WSLDistribution, ijentId: IjentId) {
|
||||
val ijentFsProvider = TracingFileSystemProvider(IjentNioFileSystemProvider.getInstance())
|
||||
try {
|
||||
ijentFsProvider.newFileSystem(ijentId.uri, null)
|
||||
@@ -110,7 +97,7 @@ internal class DefaultIjentWslNioFsToggleStrategy(
|
||||
}
|
||||
}
|
||||
|
||||
override fun disable(distro: WSLDistribution) {
|
||||
fun disable(distro: WSLDistribution) {
|
||||
ownFileSystems.compute(distro) { _, ownFs, actualFs ->
|
||||
val actualIjentWslFsProvider = actualFs?.provider()?.unwrapIjentWslNioFileSystemProvider()
|
||||
if (actualIjentWslFsProvider != null) {
|
||||
|
||||
@@ -35,35 +35,35 @@ class IjentWslNioFsToggler(@VisibleForTesting val coroutineScope: CoroutineScope
|
||||
}
|
||||
|
||||
fun enable(distro: WSLDistribution, ijentId: IjentId) {
|
||||
strategy.enable(distro, ijentId)
|
||||
strategy?.enable(distro, ijentId)
|
||||
}
|
||||
|
||||
// TODO Disable when IJent exits.
|
||||
fun disable(distro: WSLDistribution) {
|
||||
strategy.disable(distro)
|
||||
strategy?.disable(distro)
|
||||
}
|
||||
|
||||
private val strategy = run {
|
||||
val defaultProvider = FileSystems.getDefault().provider()
|
||||
when {
|
||||
!WslIjentAvailabilityService.Companion.getInstance().useIjentForWslNioFileSystem() -> FallbackIjentWslNioFsToggleStrategy
|
||||
!WslIjentAvailabilityService.Companion.getInstance().useIjentForWslNioFileSystem() -> null
|
||||
|
||||
defaultProvider.javaClass.name == MultiRoutingFileSystemProvider::class.java.name -> {
|
||||
DefaultIjentWslNioFsToggleStrategy(defaultProvider, coroutineScope)
|
||||
IjentWslNioFsToggleStrategy(defaultProvider, coroutineScope)
|
||||
}
|
||||
|
||||
else -> {
|
||||
logger<IjentWslNioFsToggler>().warn(
|
||||
"The default filesystem ${FileSystems.getDefault()} is not ${MultiRoutingFileSystemProvider::class.java}"
|
||||
)
|
||||
FallbackIjentWslNioFsToggleStrategy
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
strategy.initialize()
|
||||
strategy?.initialize()
|
||||
}
|
||||
|
||||
val isInitialized: Boolean get() = strategy.isInitialized
|
||||
val isInitialized: Boolean get() = strategy?.isInitialized ?: false
|
||||
}
|
||||
Reference in New Issue
Block a user