From b99f825790d64f19992773ccc70fdae681c30b9a Mon Sep 17 00:00:00 2001 From: Chris Lemaire Date: Tue, 20 May 2025 12:02:06 +0200 Subject: [PATCH] [gh/gl] Fix review-in-editor not starting (IJPL-186195, IJPL-187199, IJPL-181783) #IJPL-187199 Fixed #IJPL-186195 Fixed Cause of which is a threading exception on loading `.getContent()` (cherry picked from commit eec980bbaf107e2caa4f08c5150e74b773e0593b) IJ-CR-163488 GitOrigin-RevId: 263439b1b91f620222c5d27739485231164173fd --- .../ui/editor/GHPRReviewFileEditorViewModel.kt | 9 ++++++--- .../GitLabMergeRequestEditorReviewFileViewModel.kt | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) 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 d01af4452783..6cfce8663b53 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 @@ -18,7 +18,9 @@ import com.intellij.platform.util.coroutines.childScope import git4idea.changes.GitTextFilePatchWithHistory import git4idea.changes.createVcsChange import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.* +import kotlinx.coroutines.withContext import org.jetbrains.plugins.github.api.data.GHUser import org.jetbrains.plugins.github.api.data.pullrequest.GHPullRequestReviewThread import org.jetbrains.plugins.github.api.data.pullrequest.isVisible @@ -65,9 +67,9 @@ internal class GHPRReviewFileEditorViewModelImpl( private val diffData: GitTextFilePatchWithHistory, private val threadsVms: GHPRThreadsViewModels, private val discussionsViewOption: StateFlow, - private val showDiff: (change: RefComparisonChange, lineIdx: Int?) -> Unit + private val showDiff: (change: RefComparisonChange, lineIdx: Int?) -> Unit, ) : GHPRReviewFileEditorViewModel { - private val cs = parentCs.childScope(javaClass.name) + private val cs = parentCs.childScope(javaClass.name, Dispatchers.Default) override val iconProvider: GHAvatarIconsProvider = dataContext.avatarIconsProvider override val currentUser: GHUser = dataContext.securityService.currentUser @@ -83,7 +85,8 @@ internal class GHPRReviewFileEditorViewModelImpl( }?.onFailure { LOG.warn("Couldn't load head content for $change", it) } - }.stateIn(cs, SharingStarted.Lazily, ComputedResult.loading()) + }.flowOn(Dispatchers.IO) + .stateIn(cs, SharingStarted.Lazily, ComputedResult.loading()) override val changedRanges: List = diffData.patch.hunks.withoutContext().toList() diff --git a/plugins/gitlab/gitlab-core/src/org/jetbrains/plugins/gitlab/mergerequest/ui/editor/GitLabMergeRequestEditorReviewFileViewModel.kt b/plugins/gitlab/gitlab-core/src/org/jetbrains/plugins/gitlab/mergerequest/ui/editor/GitLabMergeRequestEditorReviewFileViewModel.kt index d71102c679b9..55f171d6cf8c 100644 --- a/plugins/gitlab/gitlab-core/src/org/jetbrains/plugins/gitlab/mergerequest/ui/editor/GitLabMergeRequestEditorReviewFileViewModel.kt +++ b/plugins/gitlab/gitlab-core/src/org/jetbrains/plugins/gitlab/mergerequest/ui/editor/GitLabMergeRequestEditorReviewFileViewModel.kt @@ -23,6 +23,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.* +import kotlinx.coroutines.withContext import org.jetbrains.plugins.gitlab.api.dto.GitLabUserDTO import org.jetbrains.plugins.gitlab.mergerequest.data.GitLabMergeRequest import org.jetbrains.plugins.gitlab.mergerequest.data.GitLabMergeRequestNewDiscussionPosition @@ -76,7 +77,8 @@ internal class GitLabMergeRequestEditorReviewFileViewModelImpl( }.let { emit(it) } - }.stateIn(cs, SharingStarted.Lazily, ComputedResult.loading()) + }.flowOn(Dispatchers.IO) + .stateIn(cs, SharingStarted.Lazily, ComputedResult.loading()) override val changedRanges: List = diffData.patch.hunks.withoutContext().toList()