diff --git a/plugins/github/github-core/src/org/jetbrains/plugins/github/pullrequest/GHPRStatisticsCollector.kt b/plugins/github/github-core/src/org/jetbrains/plugins/github/pullrequest/GHPRStatisticsCollector.kt index 93bb2715e0ba..4995d6f28905 100644 --- a/plugins/github/github-core/src/org/jetbrains/plugins/github/pullrequest/GHPRStatisticsCollector.kt +++ b/plugins/github/github-core/src/org/jetbrains/plugins/github/pullrequest/GHPRStatisticsCollector.kt @@ -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", 10) + private val COUNTERS_GROUP = EventLogGroup("vcs.github.pullrequest.counters", 11) private val LOG = logger() @@ -45,6 +45,18 @@ 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") + fun logResizedComments(project: Project) { + COMMENTS_RESIZED_EVENT.log(project) + } + + fun logMultilineCommentsCreated(project: Project) { + MULTILINE_COMMENTS_CREATED.log(project) + } + //endregion + //region: Filters private val FILTER_SEARCH_PRESENT = EventFields.Boolean("has_search") private val FILTER_STATE_PRESENT = EventFields.Boolean("has_state") diff --git a/plugins/github/github-core/src/org/jetbrains/plugins/github/pullrequest/ui/diff/GHPRDiffReviewViewModel.kt b/plugins/github/github-core/src/org/jetbrains/plugins/github/pullrequest/ui/diff/GHPRDiffReviewViewModel.kt index 4b0cce40de90..7ecf4eb656f7 100644 --- a/plugins/github/github-core/src/org/jetbrains/plugins/github/pullrequest/ui/diff/GHPRDiffReviewViewModel.kt +++ b/plugins/github/github-core/src/org/jetbrains/plugins/github/pullrequest/ui/diff/GHPRDiffReviewViewModel.kt @@ -27,6 +27,7 @@ import kotlinx.coroutines.launch import org.jetbrains.plugins.github.ai.GHPRAICommentViewModel import org.jetbrains.plugins.github.ai.GHPRAIReviewExtension import org.jetbrains.plugins.github.api.data.pullrequest.isViewed +import org.jetbrains.plugins.github.pullrequest.GHPRStatisticsCollector import org.jetbrains.plugins.github.pullrequest.data.GHPRDataContext import org.jetbrains.plugins.github.pullrequest.data.provider.GHPRDataProvider import org.jetbrains.plugins.github.pullrequest.data.provider.viewedStateComputationState @@ -59,7 +60,7 @@ interface GHPRDiffReviewViewModel { } internal class GHPRDiffReviewViewModelImpl( - project: Project, + private val project: Project, parentCs: CoroutineScope, private val dataContext: GHPRDataContext, private val dataProvider: GHPRDataProvider, @@ -133,13 +134,16 @@ internal class GHPRDiffReviewViewModelImpl( threadsVms.cancelNewComment(change, side, lineIdx) - override fun updateCommentLines(oldLineRange: LineRange, newLineRange: LineRange) = - threadsVms.newComments.value.firstOrNull { + override fun updateCommentLines(oldLineRange: LineRange, newLineRange: LineRange) { + val newComment = threadsVms.newComments.value.firstOrNull { when (val loc = it.position.value.location) { is GHPRReviewCommentLocation.SingleLine -> loc.lineIdx == oldLineRange.end is GHPRReviewCommentLocation.MultiLine -> loc.startLineIdx == oldLineRange.start && loc.lineIdx == oldLineRange.end } - }?.updateLineRange(newLineRange) ?: Unit + } ?: return + newComment.updateLineRange(newLineRange) + GHPRStatisticsCollector.logResizedComments(project) + } override val isViewedState: StateFlow> = dataProvider.viewedStateData.viewedStateComputationState diff --git a/plugins/github/github-core/src/org/jetbrains/plugins/github/pullrequest/ui/editor/GHPRReviewFileEditorViewModel.kt b/plugins/github/github-core/src/org/jetbrains/plugins/github/pullrequest/ui/editor/GHPRReviewFileEditorViewModel.kt index 61ec55522bce..f23c1557da13 100644 --- a/plugins/github/github-core/src/org/jetbrains/plugins/github/pullrequest/ui/editor/GHPRReviewFileEditorViewModel.kt +++ b/plugins/github/github-core/src/org/jetbrains/plugins/github/pullrequest/ui/editor/GHPRReviewFileEditorViewModel.kt @@ -24,6 +24,7 @@ import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch import org.jetbrains.plugins.github.api.data.GHUser import org.jetbrains.plugins.github.api.data.pullrequest.isViewed +import org.jetbrains.plugins.github.pullrequest.GHPRStatisticsCollector import org.jetbrains.plugins.github.pullrequest.data.GHPRDataContext import org.jetbrains.plugins.github.pullrequest.data.provider.GHPRDataProvider import org.jetbrains.plugins.github.pullrequest.data.provider.viewedStateComputationState @@ -80,7 +81,7 @@ interface GHPRReviewFileEditorViewModel { private val LOG = logger() internal class GHPRReviewFileEditorViewModelImpl( - project: Project, + private val project: Project, parentCs: CoroutineScope, private val dataContext: GHPRDataContext, private val dataProvider: GHPRDataProvider, @@ -205,14 +206,16 @@ internal class GHPRReviewFileEditorViewModelImpl( } } - override fun updateCommentLines(oldLineRange: LineRange, newLineRange: LineRange) = - threadsVm.newComments.value.firstOrNull { + override fun updateCommentLines(oldLineRange: LineRange, newLineRange: LineRange) { + val newComment = threadsVm.newComments.value.firstOrNull { when (val loc = it.position.value.location) { is GHPRReviewCommentLocation.SingleLine -> loc.lineIdx == oldLineRange.end is GHPRReviewCommentLocation.MultiLine -> loc.startLineIdx == oldLineRange.start && loc.lineIdx == oldLineRange.end } - }?.updateLineRange(newLineRange) ?: Unit - + } ?: return + newComment.updateLineRange(newLineRange) + GHPRStatisticsCollector.logResizedComments(project) + } override fun cancelNewComment(lineIdx: Int) = threadsVm.cancelNewComment(change, Side.RIGHT, lineIdx) diff --git a/plugins/github/github-core/src/org/jetbrains/plugins/github/pullrequest/ui/editor/GHPRReviewNewCommentEditorViewModel.kt b/plugins/github/github-core/src/org/jetbrains/plugins/github/pullrequest/ui/editor/GHPRReviewNewCommentEditorViewModel.kt index 5c264a2a0dbb..9cbaa779cdf3 100644 --- a/plugins/github/github-core/src/org/jetbrains/plugins/github/pullrequest/ui/editor/GHPRReviewNewCommentEditorViewModel.kt +++ b/plugins/github/github-core/src/org/jetbrains/plugins/github/pullrequest/ui/editor/GHPRReviewNewCommentEditorViewModel.kt @@ -22,6 +22,7 @@ import kotlinx.coroutines.flow.combine import org.jetbrains.plugins.github.api.data.GHActor import org.jetbrains.plugins.github.api.data.GHPullRequestReviewEvent import org.jetbrains.plugins.github.api.data.request.GHPullRequestDraftReviewThread +import org.jetbrains.plugins.github.pullrequest.GHPRStatisticsCollector import org.jetbrains.plugins.github.pullrequest.config.GithubPullRequestsProjectUISettings import org.jetbrains.plugins.github.pullrequest.data.GHPullRequestPendingReview import org.jetbrains.plugins.github.pullrequest.data.provider.GHPRDataProvider @@ -135,6 +136,9 @@ internal class GHPRReviewNewCommentEditorViewModelImpl( if (isCumulative) { val startLine = location.asSafely()?.startLineIdx?.inc() ?: line reviewDataProvider.createThread(reviewId, it, line, location.side, startLine, filePath) + if (startLine < line) { + GHPRStatisticsCollector.logMultilineCommentsCreated(project) + } } else { val commitSha = position.value.change.revisionNumberAfter.asString()