Skip to content

Commit 723a958

Browse files
authored
Merge pull request #116 from advanced-security/115-error-when-clicking-on-path-rows-sometimes
fix: don't focus on a path row when it's not defined
2 parents 2fb3207 + 6df98ea commit 723a958

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/main/kotlin/com/github/adrienpessu/sarifviewer/toolWindow/SarifViewerWindowFactory.kt

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import com.intellij.ui.components.JBPanel
3535
import com.intellij.ui.components.JBTabbedPane
3636
import com.intellij.ui.content.ContentFactory
3737
import com.intellij.ui.table.JBTable
38+
import com.jetbrains.rd.util.printlnError
3839
import git4idea.GitLocalBranch
3940
import git4idea.repo.GitRepository
4041
import git4idea.repo.GitRepositoryChangeListener
@@ -473,7 +474,12 @@ class SarifViewerWindowFactory : ToolWindowFactory {
473474
defaultTableModel.addRow(arrayOf<Any>("Rule's name", currentLeaf!!.ruleName))
474475
defaultTableModel.addRow(arrayOf<Any>("Rule's description", currentLeaf!!.ruleDescription))
475476
defaultTableModel.addRow(arrayOf<Any>("Location", currentLeaf!!.location))
476-
defaultTableModel.addRow(arrayOf<Any>("GitHub alert number", currentLeaf!!.githubAlertNumber))
477+
defaultTableModel.addRow(
478+
arrayOf<Any>(
479+
"GitHub alert number",
480+
currentLeaf!!.githubAlertNumber
481+
)
482+
)
477483
defaultTableModel.addRow(
478484
arrayOf<Any>(
479485
"GitHub alert url",
@@ -537,8 +543,11 @@ class SarifViewerWindowFactory : ToolWindowFactory {
537543
tableSteps.addMouseListener(object : MouseAdapter() {
538544
override fun mouseClicked(e: MouseEvent) {
539545
val row = tableInfos.rowAtPoint(e.point)
540-
val path = currentLeaf!!.steps[row].split(":")
541-
openFile(project, path[0], path[1].toInt(), path[2].toInt())
546+
// When the row can't be found, the method returns -1
547+
if (row != -1) {
548+
val path = currentLeaf!!.steps[row].split(":")
549+
openFile(project, path[0], path[1].toInt(), path[2].toInt())
550+
}
542551
}
543552
})
544553

@@ -585,7 +594,8 @@ class SarifViewerWindowFactory : ToolWindowFactory {
585594
val editor: Editor = FileEditorManager.getInstance(project).selectedTextEditor ?: return
586595
val inlayModel = editor.inlayModel
587596

588-
inlayModel.getBlockElementsInRange(0, editor.document.textLength).filter { it.renderer is MyCustomInlayRenderer }
597+
inlayModel.getBlockElementsInRange(0, editor.document.textLength)
598+
.filter { it.renderer is MyCustomInlayRenderer }
589599
.forEach { it.dispose() }
590600

591601
val virtualFile =
@@ -619,11 +629,12 @@ class SarifViewerWindowFactory : ToolWindowFactory {
619629
// display error message
620630
Notifications.Bus.notify(
621631
Notification(
622-
"Sarif viewer",
623-
"File not found",
624-
"Can't find the file ${project.basePath}/$path",
625-
NotificationType.WARNING
626-
), project)
632+
"Sarif viewer",
633+
"File not found",
634+
"Can't find the file ${project.basePath}/$path",
635+
NotificationType.WARNING
636+
), project
637+
)
627638
}
628639
}
629640

0 commit comments

Comments
 (0)