@@ -13,8 +13,10 @@ import com.github.adrienpessu.sarifviewer.models.Leaf
13
13
import com.github.adrienpessu.sarifviewer.models.View
14
14
import com.github.adrienpessu.sarifviewer.services.SarifService
15
15
import com.github.adrienpessu.sarifviewer.utils.GitHubInstance
16
+ import com.intellij.notification.Notification
16
17
import com.intellij.notification.NotificationGroupManager
17
18
import com.intellij.notification.NotificationType
19
+ import com.intellij.notification.Notifications
18
20
import com.intellij.openapi.actionSystem.ActionManager
19
21
import com.intellij.openapi.actionSystem.AnAction
20
22
import com.intellij.openapi.components.service
@@ -113,6 +115,7 @@ class SarifViewerWindowFactory : ToolWindowFactory {
113
115
private var disableComboBoxEvent = false
114
116
private var currentView = View .RULE
115
117
private var cacheSarif: SarifSchema210 ? = null
118
+ private var currentLeaf: Leaf ? = null
116
119
117
120
fun getContent () = JBPanel <JBPanel <* >>().apply {
118
121
@@ -442,13 +445,13 @@ class SarifViewerWindowFactory : ToolWindowFactory {
442
445
if (e != null && e.isAddedPath) {
443
446
val leaves = map[e.path.parentPath.lastPathComponent.toString().split(" " ).first()]
444
447
if (! leaves.isNullOrEmpty()) {
445
- val leaf = try {
448
+ currentLeaf = try {
446
449
leaves.first { it.address == ((e.path.lastPathComponent as DefaultMutableTreeNode ).userObject as Leaf ).address }
447
450
} catch (e: Exception ) {
448
451
leaves.first()
449
452
}
450
453
451
- val githubAlertUrl = leaf .githubAlertUrl
454
+ val githubAlertUrl = currentLeaf !! .githubAlertUrl
452
455
.replace(" api." , " " )
453
456
.replace(" api/v3/" , " " )
454
457
.replace(" repos/" , " " )
@@ -465,12 +468,12 @@ class SarifViewerWindowFactory : ToolWindowFactory {
465
468
tableInfos.model = defaultTableModel
466
469
467
470
// Add some data
468
- defaultTableModel.addRow(arrayOf<Any >(" Name" , leaf .leafName))
469
- defaultTableModel.addRow(arrayOf<Any >(" Level" , leaf .level))
470
- defaultTableModel.addRow(arrayOf<Any >(" Rule's name" , leaf .ruleName))
471
- defaultTableModel.addRow(arrayOf<Any >(" Rule's description" , leaf .ruleDescription))
472
- defaultTableModel.addRow(arrayOf<Any >(" Location" , leaf .location))
473
- defaultTableModel.addRow(arrayOf<Any >(" GitHub alert number" , leaf .githubAlertNumber))
471
+ defaultTableModel.addRow(arrayOf<Any >(" Name" , currentLeaf !! .leafName))
472
+ defaultTableModel.addRow(arrayOf<Any >(" Level" , currentLeaf !! .level))
473
+ defaultTableModel.addRow(arrayOf<Any >(" Rule's name" , currentLeaf !! .ruleName))
474
+ defaultTableModel.addRow(arrayOf<Any >(" Rule's description" , currentLeaf !! .ruleDescription))
475
+ defaultTableModel.addRow(arrayOf<Any >(" Location" , currentLeaf !! .location))
476
+ defaultTableModel.addRow(arrayOf<Any >(" GitHub alert number" , currentLeaf !! .githubAlertNumber))
474
477
defaultTableModel.addRow(
475
478
arrayOf<Any >(
476
479
" GitHub alert url" ,
@@ -527,27 +530,27 @@ class SarifViewerWindowFactory : ToolWindowFactory {
527
530
528
531
tableSteps.model = DefaultTableModel (arrayOf<Any >(" Path" ), 0 )
529
532
530
- leaf .steps.forEachIndexed { index, step ->
533
+ currentLeaf !! .steps.forEachIndexed { index, step ->
531
534
(tableSteps.model as DefaultTableModel ).addRow(arrayOf<Any >(" $index $step " ))
532
535
}
533
536
534
537
tableSteps.addMouseListener(object : MouseAdapter () {
535
538
override fun mouseClicked (e : MouseEvent ) {
536
539
val row = tableInfos.rowAtPoint(e.point)
537
- val path = leaf .steps[row].split(" :" )
540
+ val path = currentLeaf !! .steps[row].split(" :" )
538
541
openFile(project, path[0 ], path[1 ].toInt())
539
542
}
540
543
})
541
544
542
545
details.isVisible = true
543
546
openFile(
544
547
project,
545
- leaf .location,
546
- leaf .address.split(" :" )[1 ].toInt(),
548
+ currentLeaf !! .location,
549
+ currentLeaf !! .address.split(" :" )[1 ].toInt(),
547
550
0 ,
548
- leaf .level,
549
- leaf .ruleId,
550
- leaf .ruleDescription
551
+ currentLeaf !! .level,
552
+ currentLeaf !! .ruleId,
553
+ currentLeaf !! .ruleDescription
551
554
)
552
555
553
556
splitPane.setDividerLocation(0.5 )
@@ -584,33 +587,43 @@ class SarifViewerWindowFactory : ToolWindowFactory {
584
587
inlayModel.getBlockElementsInRange(0 , editor.document.textLength).filter { it.renderer is MyCustomInlayRenderer }
585
588
.forEach { it.dispose() }
586
589
587
- VirtualFileManager .getInstance().findFileByNioPath( Path .of( " ${project.basePath} / $path " ))
588
- ?. let { virtualFile ->
589
- FileEditorManager .getInstance(project).openTextEditor(
590
- OpenFileDescriptor (
591
- project,
592
- virtualFile ,
593
- lineNumber - 1 ,
594
- columnNumber
595
- ),
596
- true // request focus to editor
597
- )
598
- val editor : Editor = FileEditorManager .getInstance(project).selectedTextEditor ? : return
599
- val inlayModel = editor.inlayModel
600
-
601
- val offset = editor.document.getLineStartOffset(lineNumber - 1 )
602
-
603
- val icon = when (level) {
604
- " error " -> " 🛑 "
605
- " warning " -> " ⚠️ "
606
- " note " -> " 📝 "
607
- else -> " "
608
- }
609
- val description = " $icon $rule : $description "
610
- if ( description.isNotEmpty()) {
611
- inlayModel.addBlockElement(offset, true , true , 1 , MyCustomInlayRenderer ( description))
612
- }
590
+ val virtualFile =
591
+ VirtualFileManager .getInstance().findFileByNioPath( Path .of( " ${project.basePath} / $path " ))
592
+ if (virtualFile != null ) {
593
+ FileEditorManager .getInstance(project).openTextEditor (
594
+ OpenFileDescriptor (
595
+ project ,
596
+ virtualFile ,
597
+ lineNumber - 1 ,
598
+ columnNumber
599
+ ),
600
+ true // request focus to editor
601
+ )
602
+ val editor : Editor = FileEditorManager .getInstance(project).selectedTextEditor ? : return
603
+ val inlayModel = editor.inlayModel
604
+
605
+ val offset = editor.document.getLineStartOffset(lineNumber - 1 )
606
+
607
+ val icon = when (level) {
608
+ " error " -> " 🛑 "
609
+ " warning " -> " ⚠️ "
610
+ " note " -> " 📝 "
611
+ else -> " "
612
+ }
613
+ val description = " $icon $rule : $ description"
614
+ if ( description.isNotEmpty()) {
615
+ inlayModel.addBlockElement(offset, true , true , 1 , MyCustomInlayRenderer (description))
613
616
}
617
+ } else {
618
+ // display error message
619
+ Notifications .Bus .notify(
620
+ Notification (
621
+ " Sarif viewer" ,
622
+ " File not found" ,
623
+ " Can't find the file ${project.basePath} /$path " ,
624
+ NotificationType .WARNING
625
+ ), project)
626
+ }
614
627
}
615
628
616
629
private fun clearJSplitPane () {
0 commit comments