@@ -19,21 +19,16 @@ import com.intellij.openapi.actionSystem.ActionManager
1919import com.intellij.openapi.actionSystem.AnAction
2020import com.intellij.openapi.components.service
2121import com.intellij.openapi.diagnostic.thisLogger
22- import com.intellij.openapi.editor.ScrollType
23- import com.intellij.openapi.fileEditor.FileDocumentManager
22+ import com.intellij.openapi.editor.Editor
2423import com.intellij.openapi.fileEditor.FileEditorManager
2524import com.intellij.openapi.fileEditor.OpenFileDescriptor
2625import com.intellij.openapi.project.DumbService
2726import com.intellij.openapi.project.Project
2827import com.intellij.openapi.ui.ComboBox
29- import com.intellij.openapi.ui.MessageType
30- import com.intellij.openapi.ui.popup.Balloon
31- import com.intellij.openapi.ui.popup.JBPopupFactory
3228import com.intellij.openapi.vfs.VirtualFileManager
3329import com.intellij.openapi.wm.ToolWindow
3430import com.intellij.openapi.wm.ToolWindowFactory
3531import com.intellij.ui.ScrollPaneFactory
36- import com.intellij.ui.awt.RelativePoint
3732import com.intellij.ui.components.JBPanel
3833import com.intellij.ui.components.JBTabbedPane
3934import com.intellij.ui.content.ContentFactory
@@ -551,6 +546,7 @@ class SarifViewerWindowFactory : ToolWindowFactory {
551546 leaf.address.split(" :" )[1 ].toInt(),
552547 0 ,
553548 leaf.level,
549+ leaf.ruleId,
554550 leaf.ruleDescription
555551 )
556552
@@ -578,9 +574,16 @@ class SarifViewerWindowFactory : ToolWindowFactory {
578574 lineNumber : Int ,
579575 columnNumber : Int = 0,
580576 level : String = "",
581- ruleDescription : String = ""
577+ rule : String = "",
578+ description : String = ""
582579 ) {
583580
581+ val editor: Editor = FileEditorManager .getInstance(project).selectedTextEditor ? : return
582+ val inlayModel = editor.inlayModel
583+
584+ inlayModel.getBlockElementsInRange(0 , editor.document.textLength).filter { it.renderer is MyCustomInlayRenderer }
585+ .forEach { it.dispose() }
586+
584587 VirtualFileManager .getInstance().findFileByNioPath(Path .of(" ${project.basePath} /$path " ))
585588 ?.let { virtualFile ->
586589 FileEditorManager .getInstance(project).openTextEditor(
@@ -592,36 +595,21 @@ class SarifViewerWindowFactory : ToolWindowFactory {
592595 ),
593596 true // request focus to editor
594597 )
595- FileDocumentManager .getInstance().getDocument(virtualFile)?.let { document ->
596- if (ruleDescription.isNotEmpty()) {
597- val lineStartOffset = document.getLineStartOffset(lineNumber - 1 )
598- val lineEndOffset = document.getLineEndOffset(lineNumber - 1 )
599- val editor = FileEditorManager .getInstance(project).selectedTextEditor ? : return
600- editor.caretModel.moveToOffset(lineStartOffset)
601- editor.scrollingModel.scrollToCaret(ScrollType .CENTER )
602- editor.selectionModel.setSelection(lineStartOffset, lineEndOffset)
603-
604- val messageType = when (level) {
605- " error" -> MessageType .ERROR
606- " warning" -> MessageType .WARNING
607- else -> MessageType .INFO
608- }
598+ val editor: Editor = FileEditorManager .getInstance(project).selectedTextEditor ? : return
599+ val inlayModel = editor.inlayModel
609600
610- // add a balloon on the selection
611- val balloon = JBPopupFactory .getInstance().createHtmlTextBalloonBuilder(
612- ruleDescription,
613- messageType,
614- null
615- ).createBalloon()
616- balloon.show(
617- RelativePoint (
618- editor.contentComponent,
619- editor.visualPositionToXY(editor.caretModel.visualPosition)
620- ), Balloon .Position .above
621- )
622- }
623- }
601+ val offset = editor.document.getLineStartOffset(lineNumber - 1 )
624602
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+ }
625613 }
626614 }
627615
0 commit comments