-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor logging system and adjust FUSEvent handling, fix IDEA-347208 (…
…#102) The logging system has been refactored to log events using a new PackageSearchFUSEvent sealed interface, to handle logging more uniformly across the code. Furthermore, the sharing behavior of selectedModulesFlow in PackageListViewModel has been adjusted for better performance and readability. These changes help improve the organization and readability of the code while maintaining its functionality.
- Loading branch information
Showing
10 changed files
with
234 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
plugin/src/main/kotlin/com/jetbrains/packagesearch/plugin/fus/PackageSearchFUSEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.jetbrains.packagesearch.plugin.fus | ||
|
||
import com.jetbrains.packagesearch.plugin.core.data.PackageSearchModule | ||
import org.jetbrains.packagesearch.api.v3.ApiRepository | ||
|
||
sealed interface PackageSearchFUSEvent { | ||
data class PackageInstalled(val packageIdentifier: String, val targetModule: PackageSearchModule) : | ||
PackageSearchFUSEvent | ||
|
||
data class PackageRemoved( | ||
val packageIdentifier: String, | ||
val packageVersion: String?, | ||
val targetModule: PackageSearchModule, | ||
) : PackageSearchFUSEvent | ||
|
||
data class PackageVersionChanged( | ||
val packageIdentifier: String, | ||
val packageFromVersion: String?, | ||
val packageTargetVersion: String, | ||
val targetModule: PackageSearchModule, | ||
) : PackageSearchFUSEvent | ||
|
||
data class PackageVariantChanged(val packageIdentifier: String, val targetModule: PackageSearchModule) : | ||
PackageSearchFUSEvent | ||
|
||
data class PackageScopeChanged( | ||
val packageIdentifier: String, | ||
val scopeFrom: String?, | ||
val scopeTo: String?, | ||
val targetModule: PackageSearchModule, | ||
) : PackageSearchFUSEvent | ||
|
||
data class RepositoryAdded(val model: ApiRepository) : PackageSearchFUSEvent | ||
data class RepositoryRemoved(val model: ApiRepository) : PackageSearchFUSEvent | ||
data object PreferencesRestoreDefaults : PackageSearchFUSEvent | ||
data class TargetModulesSelected(val targetModules: List<PackageSearchModule>) : PackageSearchFUSEvent | ||
data class PackageSelected(val isInstalled: Boolean) : PackageSearchFUSEvent | ||
data class DetailsLinkClick(val type: FUSGroupIds.DetailsLinkTypes) : PackageSearchFUSEvent | ||
data class OnlyStableToggle(val state: Boolean) : PackageSearchFUSEvent | ||
data class SearchRequest(val query: String) : PackageSearchFUSEvent | ||
data object SearchQueryClear : PackageSearchFUSEvent | ||
data object UpgradeAll : PackageSearchFUSEvent | ||
data object InfoPanelOpened : PackageSearchFUSEvent | ||
data class GoToSource(val module: PackageSearchModule, val packageId: String) : PackageSearchFUSEvent | ||
data class HeaderAttributesClick(val isSearchHeader: Boolean) : PackageSearchFUSEvent | ||
data object HeaderVariantsClick : PackageSearchFUSEvent | ||
} |
32 changes: 32 additions & 0 deletions
32
...in/src/main/kotlin/com/jetbrains/packagesearch/plugin/services/PackageSearchFUSService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.jetbrains.packagesearch.plugin.services | ||
|
||
import com.intellij.openapi.components.Service | ||
import com.intellij.openapi.components.Service.Level | ||
import com.jetbrains.packagesearch.plugin.fus.PackageSearchFUSEvent | ||
import com.jetbrains.packagesearch.plugin.fus.log | ||
import com.jetbrains.packagesearch.plugin.utils.logWarn | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.channels.Channel | ||
import kotlinx.coroutines.flow.consumeAsFlow | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
import kotlinx.coroutines.flow.retry | ||
|
||
@Service(Level.APP) | ||
class PackageSearchFUSService(coroutineScope: CoroutineScope) { | ||
private val eventsChannel: Channel<PackageSearchFUSEvent> = Channel(capacity = Channel.UNLIMITED) | ||
|
||
init { | ||
eventsChannel.consumeAsFlow() | ||
.onEach { it.log() } | ||
.retry { | ||
logWarn("${this::class.qualifiedName}#eventReportingJob", it) { "Failed to log FUS" } | ||
true | ||
} | ||
.launchIn(coroutineScope) | ||
} | ||
|
||
fun logEvent(event: PackageSearchFUSEvent) { | ||
eventsChannel.trySend(event) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.