[gl/gh] Add logging for toggling comments/discussions visibility in code reviews

#IJPL-227088 Fixed

GitOrigin-RevId: 4a6b9b8ba88dd66af599d4907eb6da907e7c7809
This commit is contained in:
Bartosz Janusz
2026-01-15 18:46:09 +00:00
committed by intellij-monorepo-bot
parent f7f585c8ae
commit fc0ff807b9
8 changed files with 38 additions and 10 deletions
@@ -26,7 +26,7 @@ import java.util.*
// TODO: Fix or replace a whole bunch of these statistics as they're no longer being collected since generalizing to Collab Tools
internal object GHPRStatisticsCollector : CounterUsagesCollector() {
private val COUNTERS_GROUP = EventLogGroup("vcs.github.pullrequest.counters", 11)
private val COUNTERS_GROUP = EventLogGroup("vcs.github.pullrequest.counters", 12)
private val LOG = logger<GHPRStatisticsCollector>()
@@ -45,9 +45,13 @@ internal object GHPRStatisticsCollector : CounterUsagesCollector() {
}
//endregion
//region: Multiline comments
private val COMMENTS_RESIZED_EVENT = COUNTERS_GROUP.registerEvent("comments.resized", "The user resized range of a new comment by dragging its outline across the text")
private val MULTILINE_COMMENTS_CREATED = COUNTERS_GROUP.registerEvent("multiline.comments.created", "The user created a new comment that spans multiple lines")
//region: Comments
private val COMMENTS_RESIZED_EVENT = COUNTERS_GROUP.registerEvent("comments.resized",
"The user resized range of a new comment by dragging its outline across the text")
private val MULTILINE_COMMENTS_CREATED = COUNTERS_GROUP.registerEvent("multiline.comments.created",
"The user created a new comment that spans multiple lines")
private val TOGGLED_COMMENTS_EVENT = COUNTERS_GROUP.registerEvent("comments.toggled",
"The user toggled visibility of comments on given line in code review")
fun logResizedComments(project: Project) {
COMMENTS_RESIZED_EVENT.log(project)
}
@@ -55,6 +59,10 @@ internal object GHPRStatisticsCollector : CounterUsagesCollector() {
fun logMultilineCommentsCreated(project: Project) {
MULTILINE_COMMENTS_CREATED.log(project)
}
fun logToggledComments(project: Project) {
TOGGLED_COMMENTS_EVENT.log(project)
}
//endregion
//region: Filters
@@ -19,6 +19,7 @@ import com.intellij.diff.util.Range
import com.intellij.diff.util.Side
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.platform.util.coroutines.childScope
import com.intellij.util.cancelOnDispose
import com.intellij.util.concurrency.annotations.RequiresEdt
@@ -28,6 +29,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import org.jetbrains.plugins.github.ai.GHPRAICommentViewModel
import org.jetbrains.plugins.github.pullrequest.GHPRStatisticsCollector
import org.jetbrains.plugins.github.pullrequest.ui.comment.GHPRCompactReviewThreadViewModel
import org.jetbrains.plugins.github.pullrequest.ui.comment.GHPRReviewCommentLocation
import org.jetbrains.plugins.github.pullrequest.ui.comment.lineLocation
@@ -52,7 +54,7 @@ internal class GHPRReviewDiffExtension : DiffExtension() {
}
@Service(Service.Level.PROJECT)
private class InlaysController(parentCs: CoroutineScope) {
private class InlaysController(private val project: Project, parentCs: CoroutineScope) {
private val cs = parentCs.childScope(javaClass.name, Dispatchers.Main)
fun installInlays(reviewVm: GHPRDiffViewModel, change: RefComparisonChange, viewer: DiffViewerBase) {
@@ -71,7 +73,7 @@ internal class GHPRReviewDiffExtension : DiffExtension() {
viewer.showCodeReview { editor, _, locationToLine, lineToLocation, lineToUnified ->
coroutineScope {
val cs = this
val model = DiffEditorModel(cs, reviewVm, changeVm, locationToLine, lineToLocation) {
val model = DiffEditorModel(cs, project, reviewVm, changeVm, locationToLine, lineToLocation) {
val (leftLine, rightLine) = lineToUnified(it)
UnifiedCodeReviewItemPosition(change, leftLine, rightLine)
}
@@ -98,6 +100,7 @@ internal interface GHPRReviewDiffEditorModel : CodeReviewEditorModel<GHPREditorM
private class DiffEditorModel(
cs: CoroutineScope,
private val project: Project,
private val reviewVm: GHPRDiffViewModel,
private val diffVm: GHPRDiffReviewViewModel,
private val locationToLine: (DiffLineLocation) -> Int?,
@@ -195,6 +198,7 @@ private class DiffEditorModel(
override fun toggleComments(lineIdx: Int) {
inlays.value.asSequence().filter { it.line.value == lineIdx }.filterIsInstance<Hideable>().syncOrToggleAll()
GHPRStatisticsCollector.logToggledComments(project)
}
override val canNavigate: Boolean get() = diffVm.canNavigate
@@ -11,6 +11,7 @@ import com.intellij.diff.util.LineRange
import com.intellij.diff.util.Range
import com.intellij.diff.util.Side
import com.intellij.openapi.Disposable
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
import com.intellij.platform.util.coroutines.childScope
import com.intellij.util.cancelOnDispose
@@ -22,12 +23,14 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import org.jetbrains.plugins.github.pullrequest.GHPRStatisticsCollector
import org.jetbrains.plugins.github.pullrequest.config.GithubPullRequestsProjectUISettings
import org.jetbrains.plugins.github.pullrequest.ui.comment.GHPRReviewCommentLocation
import java.util.*
internal class GHPRReviewFileEditorModel internal constructor(
private val cs: CoroutineScope,
private val project: Project,
private val settings: GithubPullRequestsProjectUISettings,
private val fileVm: GHPRReviewFileEditorViewModel,
private val changesModel: MutableCodeReviewEditorGutterChangesModel = MutableCodeReviewEditorGutterChangesModel(),
@@ -90,6 +93,7 @@ internal class GHPRReviewFileEditorModel internal constructor(
override fun toggleComments(lineIdx: Int) {
inlays.value.asSequence().filter { it.line.value == lineIdx }.filterIsInstance<Hideable>().syncOrToggleAll()
GHPRStatisticsCollector.logToggledComments(project)
}
override fun getBaseContent(lines: LineRange): String? = fileVm.getBaseContent(lines)
@@ -99,7 +99,7 @@ private suspend fun showReview(project: Project, settings: GithubPullRequestsPro
withContext(Dispatchers.Main.immediate) {
val reviewHeadContent = fileVm.originalContent.mapNotNull { it?.result?.getOrThrow() }.first()
val cs = this
val model = GHPRReviewFileEditorModel(cs, settings, fileVm) showEditor@{ changeToShow, lineIdx ->
val model = GHPRReviewFileEditorModel(cs, project, settings, fileVm) showEditor@{ changeToShow, lineIdx ->
val file = changeToShow.filePathAfter?.virtualFile ?: return@showEditor
val fileOpenDescriptor = OpenFileDescriptor(project, file, lineIdx, 0)
FileEditorManager.getInstance(project).openFileEditor(fileOpenDescriptor, true)
@@ -80,7 +80,7 @@ class GitLabMergeRequestDiffExtension : DiffExtension() {
viewer.showCodeReview(
modelFactory = { _, _, locationToLine, lineToLocations, lineToUnified ->
DiffEditorModel(this, changeVm, locationToLine, lineToLocations) {
DiffEditorModel(this, project, changeVm, locationToLine, lineToLocations) {
val (leftLine, rightLine) = lineToUnified(it)
UnifiedCodeReviewItemPosition(change, leftLine, rightLine)
}
@@ -116,6 +116,7 @@ internal interface GitLabReviewDiffEditorModel : CodeReviewEditorModel<GitLabMer
private class DiffEditorModel(
cs: CoroutineScope,
private val project: Project,
private val diffReviewVm: GitLabMergeRequestDiffReviewViewModel,
private val locationToLine: (DiffLineLocation) -> Int?,
private val lineToLocation: (Int) -> DiffLineLocation?,
@@ -158,6 +159,7 @@ private class DiffEditorModel(
override fun toggleComments(lineIdx: Int) {
inlays.value.asSequence().filter { it.line.value == lineIdx }.filterIsInstance<Hideable>().syncOrToggleAll()
GitLabStatistics.logToggledComments(project)
}
override val canNavigate: Boolean get() = diffReviewVm.isCumulativeChange
@@ -112,7 +112,7 @@ internal class GitLabMergeRequestEditorReviewController(private val project: Pro
val preferences = project.serviceAsync<GitLabMergeRequestsPreferences>()
val reviewHeadContent = fileVm.headContent.mapNotNull { it?.result?.getOrThrow() }.first()
val model = GitLabMergeRequestEditorReviewUIModel(this, preferences, fileVm) showEditor@{ changeToShow, lineIdx ->
val model = GitLabMergeRequestEditorReviewUIModel(this, project, preferences, fileVm) showEditor@{ changeToShow, lineIdx ->
val file = changeToShow.filePathAfter?.virtualFile ?: return@showEditor
val fileOpenDescriptor = OpenFileDescriptor(project, file, lineIdx, 0)
FileEditorManager.getInstance(project).openFileEditor(fileOpenDescriptor, true)
@@ -7,6 +7,7 @@ import com.intellij.collaboration.util.*
import com.intellij.diff.util.LineRange
import com.intellij.diff.util.Range
import com.intellij.openapi.Disposable
import com.intellij.openapi.project.Project
import com.intellij.util.cancelOnDispose
import com.intellij.util.concurrency.annotations.RequiresEdt
import kotlinx.coroutines.CoroutineScope
@@ -15,12 +16,14 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import org.jetbrains.plugins.gitlab.mergerequest.GitLabMergeRequestsPreferences
import org.jetbrains.plugins.gitlab.util.GitLabStatistics
/**
* A wrapper over [GitLabMergeRequestEditorReviewFileViewModel] to encapsulate LST integration
*/
internal class GitLabMergeRequestEditorReviewUIModel internal constructor(
private val cs: CoroutineScope,
private val project: Project,
private val preferences: GitLabMergeRequestsPreferences,
private val fileVm: GitLabMergeRequestEditorReviewFileViewModel,
private val changesModel: MutableCodeReviewEditorGutterChangesModel = MutableCodeReviewEditorGutterChangesModel(),
@@ -88,6 +91,7 @@ internal class GitLabMergeRequestEditorReviewUIModel internal constructor(
override fun toggleComments(lineIdx: Int) {
inlays.value.asSequence().filter { it.line.value == lineIdx }.filterIsInstance<Hideable>().syncOrToggleAll()
GitLabStatistics.logToggledComments(project)
}
fun cancelNewDiscussion(originalLine: Int) {
@@ -102,7 +102,7 @@ object GitLabStatistics {
//endregion
//region Counters
private val COUNTERS_GROUP = EventLogGroup("vcs.gitlab.counters", version = 28)
private val COUNTERS_GROUP = EventLogGroup("vcs.gitlab.counters", version = 29)
/**
* Server metadata was fetched
@@ -297,6 +297,12 @@ object GitLabStatistics {
fun logFileUploadActionExecuted(project: Project): Unit = PROJECT_FILE_UPLOAD.log(project)
private val DISCUSSIONS_TOGGLED = COUNTERS_GROUP.registerEvent("comments.toggled",
"The user toggled visibility of discussions on given line in code review")
fun logToggledComments(project: Project) {
DISCUSSIONS_TOGGLED.log(project)
}
/**
* GitLab tool window tab <type> was opened from <place>