Skip to content

Commit

Permalink
IJPL-161967 IJent cleanup: make some IJent+WSL functions not suspendable
Browse files Browse the repository at this point in the history
This is done just to make `IjentWslFileSystemApplicationActivity` look not so threatening. It's a lightweight class, but it used some suspend functions. In fact, these functions could be non-suspendable. They are not suspendable anymore.

GitOrigin-RevId: 2d67e1641f7f480a3effef8f90fa6d29fe445f08
  • Loading branch information
vladimirlagunov authored and intellij-monorepo-bot committed Nov 20, 2024
1 parent 073d41b commit d8f3f16
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import java.util.concurrent.atomic.AtomicReference
* In order to solve this problem, IjentFileSystemApi MUST guarantee idempotency of every call.
*/
@Suppress("FunctionName")
suspend fun IjentFailSafeFileSystemPosixApi(
fun IjentFailSafeFileSystemPosixApi(
coroutineScope: CoroutineScope,
delegateFactory: suspend () -> IjentPosixApi,
): IjentFileSystemApi {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import com.intellij.platform.ijent.community.impl.nio.telemetry.TracingFileSyste
import com.intellij.util.containers.ContainerUtil
import com.intellij.util.containers.forEachGuaranteed
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.job
import kotlinx.coroutines.launch
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.annotations.VisibleForTesting
import java.net.URI
Expand All @@ -44,13 +42,11 @@ class IjentWslNioFsToggleStrategy(
}
}

suspend fun enableForAllWslDistributions() {
fun enableForAllWslDistributions() {
val listener = BiConsumer<Set<WSLDistribution>, Set<WSLDistribution>> { old, new ->
// TODO The code is race prone. Frequent creations and deletions of WSL containers may break the state.
for (distro in new - old) {
coroutineScope.launch {
handleWslDistributionAddition(distro)
}
handleWslDistributionAddition(distro)
}
for (distro in old - new) {
handleWslDistributionDeletion(distro)
Expand All @@ -63,16 +59,12 @@ class IjentWslNioFsToggleStrategy(
wslDistributionManager.removeWslDistributionsChangeListener(listener)
}

coroutineScope {
for (distro in wslDistributionManager.installedDistributions) {
launch {
handleWslDistributionAddition(distro)
}
}
for (distro in wslDistributionManager.installedDistributions) {
handleWslDistributionAddition(distro)
}
}

private suspend fun handleWslDistributionAddition(distro: WSLDistribution) {
private fun handleWslDistributionAddition(distro: WSLDistribution) {
enabledInDistros += distro
switchToIjentFs(distro)
}
Expand All @@ -88,7 +80,7 @@ class IjentWslNioFsToggleStrategy(
}
}

suspend fun switchToIjentFs(distro: WSLDistribution) {
fun switchToIjentFs(distro: WSLDistribution) {
val ijentFsProvider = TracingFileSystemProvider(IjentNioFileSystemProvider.getInstance())
try {
val ijentFs = IjentFailSafeFileSystemPosixApi(coroutineScope) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class IjentWslNioFsToggler(private val coroutineScope: CoroutineScope) {

val isAvailable: Boolean get() = strategy != null

suspend fun enableForAllWslDistributions() {
fun enableForAllWslDistributions() {
logErrorIfNotWindows()
strategy?.enableForAllWslDistributions()
}

@TestOnly
suspend fun switchToIjentFs(distro: WSLDistribution) {
fun switchToIjentFs(distro: WSLDistribution) {
logErrorIfNotWindows()
strategy ?: error("Not available")
strategy.switchToIjentFs(distro)
Expand Down

0 comments on commit d8f3f16

Please sign in to comment.