Skip to content

Commit 370e2f6

Browse files
committed
Merge branch 'main' of github.com:advanced-security/SARIF-viewer
2 parents 0e49fb5 + a234b01 commit 370e2f6

File tree

9 files changed

+63
-55
lines changed

9 files changed

+63
-55
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ jobs:
203203

204204
# Cache Plugin Verifier IDEs
205205
- name: Setup Plugin Verifier IDEs Cache
206-
uses: actions/cache@v3
206+
uses: actions/cache@v4
207207
with:
208208
path: ${{ needs.build.outputs.pluginVerifierHomeDir }}/ides
209209
key: plugin-verifier-${{ hashFiles('build/listProductsReleases.txt') }}

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ annotations = "24.1.0"
55
# plugins
66
kotlin = "1.9.22"
77
changelog = "2.2.0"
8-
gradleIntelliJPlugin = "1.16.1"
8+
gradleIntelliJPlugin = "1.17.0"
99
qodana = "0.1.13"
1010
kover = "0.7.5"
1111

src/main/kotlin/com/github/adrienpessu/sarifviewer/actions/OpenLocalAction.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import com.intellij.openapi.actionSystem.AnActionEvent
77
class OpenLocalAction : AnAction("Open local Sarif file") {
88

99
var myToolWindow: SarifViewerWindowFactory.MyToolWindow? = null
10-
set(value) {
11-
field = value
12-
}
1310

1411
override fun actionPerformed(e: AnActionEvent) {
1512
myToolWindow?.openLocalFile()

src/main/kotlin/com/github/adrienpessu/sarifviewer/actions/RefreshAction.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import com.intellij.openapi.actionSystem.AnActionEvent
77

88
class RefreshAction : AnAction("Refresh from GitHub") {
99
var myToolWindow: SarifViewerWindowFactory.MyToolWindow? = null
10-
set(value) {
11-
field = value
12-
}
1310

1411
override fun actionPerformed(e: AnActionEvent) {
1512
val gitHubInstance = myToolWindow?.github?: throw SarifViewerException.INVALID_REPOSITORY

src/main/kotlin/com/github/adrienpessu/sarifviewer/configurable/SettingComponent.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,26 @@ class SettingComponent {
3434
}
3535

3636
fun getGhTokenText(): String {
37-
return ghTokenText.getText()
37+
return ghTokenText.text
3838
}
3939

4040
fun setGhTokenText(newText: String) {
41-
ghTokenText.setText(newText)
41+
ghTokenText.text = newText
4242
}
4343

4444
fun getGhesHostnameText(): String {
45-
return ghesHostnameText.getText()
45+
return ghesHostnameText.text
4646
}
4747

4848
fun getGhesTokenText(): String {
49-
return ghesTokenText.getText()
49+
return ghesTokenText.text
5050
}
5151

5252
fun setGhesHostnameText(newText: String) {
53-
ghesHostnameText.setText(newText)
53+
ghesHostnameText.text = newText
5454
}
5555

5656
fun setGhesTokenText(newText: String) {
57-
ghesTokenText.setText(newText)
57+
ghesTokenText.text = newText
5858
}
5959
}

src/main/kotlin/com/github/adrienpessu/sarifviewer/configurable/Settings.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class Settings : Configurable, Configurable.NoScroll, Disposable {
3232

3333
override fun isModified(): Boolean =
3434
listOf(
35-
!mySettingsComponent!!.getGhTokenText().equals(SettingsState.instance.state.pat),
36-
!mySettingsComponent!!.getGhesHostnameText().equals(SettingsState.instance.state.ghesHostname),
37-
!mySettingsComponent!!.getGhesTokenText().equals(SettingsState.instance.state.ghesPat),
35+
mySettingsComponent!!.getGhTokenText() != SettingsState.instance.state.pat,
36+
mySettingsComponent!!.getGhesHostnameText() != SettingsState.instance.state.ghesHostname,
37+
mySettingsComponent!!.getGhesTokenText() != SettingsState.instance.state.ghesPat,
3838
).any()
3939

4040
override fun apply() {

src/main/kotlin/com/github/adrienpessu/sarifviewer/models/BranchItemComboBox.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ data class BranchItemComboBox(
88
val commit: String = "",
99
) {
1010
override fun toString(): String {
11-
if (prNumber == 0) {
12-
return head
11+
return if (prNumber == 0) {
12+
head
1313
} else {
14-
return "pr$prNumber ($prTitle)"
14+
"pr$prNumber ($prTitle)"
1515
}
1616
}
1717
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.github.adrienpessu.sarifviewer.toolWindow
2+
3+
import com.intellij.openapi.editor.EditorCustomElementRenderer
4+
import com.intellij.openapi.editor.Inlay
5+
import com.intellij.openapi.editor.impl.EditorImpl
6+
import com.intellij.openapi.editor.markup.TextAttributes
7+
import java.awt.Font
8+
import java.awt.Graphics
9+
import java.awt.Rectangle
10+
11+
class MyCustomInlayRenderer(private val text: String) : EditorCustomElementRenderer {
12+
13+
private val myFont = Font("Courrier new", Font.ITALIC, 12)
14+
override fun paint(inlay: Inlay<*>, g: Graphics, targetRegion: Rectangle, textAttributes: TextAttributes) {
15+
16+
(inlay.editor as EditorImpl).apply {
17+
g.font = myFont
18+
g.color = colorsScheme.defaultForeground
19+
g.drawString(text, targetRegion.x, targetRegion.y + ascent)
20+
}
21+
}
22+
23+
override fun calcWidthInPixels(inlay: Inlay<*>): Int {
24+
return (inlay.editor as EditorImpl).getFontMetrics(myFont.style).stringWidth(text)
25+
}
26+
}

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

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,16 @@ import com.intellij.openapi.actionSystem.ActionManager
1919
import com.intellij.openapi.actionSystem.AnAction
2020
import com.intellij.openapi.components.service
2121
import 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
2423
import com.intellij.openapi.fileEditor.FileEditorManager
2524
import com.intellij.openapi.fileEditor.OpenFileDescriptor
2625
import com.intellij.openapi.project.DumbService
2726
import com.intellij.openapi.project.Project
2827
import 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
3228
import com.intellij.openapi.vfs.VirtualFileManager
3329
import com.intellij.openapi.wm.ToolWindow
3430
import com.intellij.openapi.wm.ToolWindowFactory
3531
import com.intellij.ui.ScrollPaneFactory
36-
import com.intellij.ui.awt.RelativePoint
3732
import com.intellij.ui.components.JBPanel
3833
import com.intellij.ui.components.JBTabbedPane
3934
import 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

Comments
 (0)