Skip to content

Commit

Permalink
Use UpToDateLineNumberProviderImpl to calculate current line
Browse files Browse the repository at this point in the history
  • Loading branch information
shiraji committed Mar 20, 2024
1 parent ad1000b commit c7c1645
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.vcs.ProjectLevelVcsManager
import com.intellij.openapi.vcs.VcsException
import com.intellij.openapi.vcs.impl.UpToDateLineNumberProviderImpl
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.util.ui.UIUtil
import git4idea.GitRevisionNumber
Expand Down Expand Up @@ -167,8 +168,15 @@ class ListPullRequestToggleAction : ToggleAction() {
}

ApplicationManager.getApplication().invokeLater {
val provider =
ListPullRequestTextAnnotationGutterProvider(map, virtualFile, fileAnnotation, model, repository)
val upToDateLineNumberProvider = UpToDateLineNumberProviderImpl(editor.document, project)
val provider = ListPullRequestTextAnnotationGutterProvider(
map,
virtualFile,
fileAnnotation,
model,
repository,
upToDateLineNumberProvider
)
editor.gutter.registerTextAnnotation(provider, provider)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ import git4idea.repo.GitRepository
import java.awt.Color
import java.awt.Cursor

class ListPullRequestTextAnnotationGutterProvider constructor(
class ListPullRequestTextAnnotationGutterProvider(
private val gitHashesMap: HashMap<String, GitPullRequestInfo>,
val virtualFile: VirtualFile,
private val fileAnnotation: FileAnnotation,
private val model: FindPullRequestModel,
private val repository: GitRepository
private val repository: GitRepository,
private val upToDateLineNumberProvider: UpToDateLineNumberProviderImpl,
) : TextAnnotationGutterProvider, EditorGutterAction {

override fun getPopupActions(line: Int, editor: Editor?): MutableList<AnAction> {
Expand All @@ -36,7 +37,6 @@ class ListPullRequestTextAnnotationGutterProvider constructor(
}

override fun getLineText(line: Int, editor: Editor?): String? {
val upToDateLineNumberProvider = UpToDateLineNumberProviderImpl(editor?.document, editor?.project)
val currentLine = upToDateLineNumberProvider.getLineNumber(line)
if (currentLine < 0) return ""
val hash = fileAnnotation.getLineRevisionNumber(currentLine)?.asString() ?: ""
Expand All @@ -62,7 +62,8 @@ class ListPullRequestTextAnnotationGutterProvider constructor(
override fun doAction(lineNum: Int) {
object : Task.Backgroundable(fileAnnotation.project, "Opening Pull Request...") {
override fun run(indicator: ProgressIndicator) {
val hash = fileAnnotation.getLineRevisionNumber(lineNum)?.asString() ?: ""
val currentLine = upToDateLineNumberProvider.getLineNumber(lineNum)
val hash = fileAnnotation.getLineRevisionNumber(currentLine)?.asString() ?: ""
val gitPullRequestInfo = gitHashesMap[hash] ?: return
val hostingService = gitPullRequestInfo.hostingServices ?: return
val webRepoUrl = model.createWebRepoUrl(repository) ?: return
Expand Down

0 comments on commit c7c1645

Please sign in to comment.