Skip to content

Commit

Permalink
SLI-1661 Location numbers should be displayed in the editor
Browse files Browse the repository at this point in the history
  • Loading branch information
nquinquenel committed Oct 18, 2024
1 parent c69366a commit 4d12bfd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 50 deletions.
48 changes: 25 additions & 23 deletions src/main/java/org/sonarlint/intellij/editor/EditorDecorator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.intellij.codeInsight.daemon.impl.HighlightInfo
import com.intellij.codeInsight.daemon.impl.HighlightInfoType
import com.intellij.codeInsight.daemon.impl.UpdateHighlightersUtil
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.Service
import com.intellij.openapi.editor.Document
import com.intellij.openapi.editor.Editor
Expand Down Expand Up @@ -51,22 +52,15 @@ class EditorDecorator(private val project: Project) {
private var blinker: RangeBlinker? = null

fun removeHighlights() {
runOnUiThread(project) {
currentHighlightedDoc.forEach {
clearSecondaryLocationNumbers(it)
UpdateHighlightersUtil.setHighlightersToEditor(
project,
it,
0,
it.textLength,
emptyList(),
null,
HIGHLIGHT_GROUP_ID
)
}
currentHighlightedDoc.clear()
stopBlinking()
ApplicationManager.getApplication().assertIsDispatchThread()
currentHighlightedDoc.forEach {
clearSecondaryLocationNumbers(it)
UpdateHighlightersUtil.setHighlightersToEditor(
project, it, 0, it.textLength, emptyList(), null, HIGHLIGHT_GROUP_ID
)
}
currentHighlightedDoc.clear()
stopBlinking()
}

private fun stopBlinking() {
Expand Down Expand Up @@ -123,12 +117,14 @@ class EditorDecorator(private val project: Project) {
}

private fun updateHighlights(highlights: List<Highlight>) {
removeHighlights()
highlights.groupBy({ it.document }, { it.highlightInfo })
.forEach { (doc, hs) ->
highlightInDocument(hs, doc)
blinkLocations(hs, doc)
}
runOnUiThread(project) {
removeHighlights()
highlights.groupBy({ it.document }, { it.highlightInfo })
.forEach { (doc, hs) ->
highlightInDocument(hs, doc)
blinkLocations(hs, doc)
}
}
}

private fun highlightInDocument(highlights: List<HighlightInfo?>, document: Document) {
Expand All @@ -152,8 +148,14 @@ class EditorDecorator(private val project: Project) {
return
}
val marker = location.range!!
getEditors(marker.document)
.forEach { it.inlayModel.addInlineElement(marker.startOffset, SecondaryLocationIndexRenderer(location, index, selected)) }
runOnUiThread(project) {
getEditors(marker.document).forEach {
it.inlayModel.addInlineElement(
marker.startOffset,
SecondaryLocationIndexRenderer(location, index, selected)
)
}
}
}

private fun getEditors(document: Document): List<Editor> {
Expand Down
26 changes: 0 additions & 26 deletions src/main/java/org/sonarlint/intellij/ui/AbstractIssuesPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,6 @@ private void createFindingDetailsPanel() {
findingDetailsPanel = new FindingDetailsPanel(project, this, FindingKind.ISSUE);
}

private void issueTreeSelectionChanged() {
var selectedNodes = tree.getSelectedNodes(IssueNode.class, null);
if (selectedNodes.length > 0) {
var issue = selectedNodes[0].issue();
findingDetailsPanel.show(issue);
} else {
findingDetailsPanel.clear();
var highlighting = SonarLintUtils.getService(project, EditorDecorator.class);
highlighting.removeHighlights();
}
}

private void oldIssueTreeSelectionChanged() {
var selectedNodes = oldTree.getSelectedNodes(IssueNode.class, null);
if (selectedNodes.length > 0) {
var issue = selectedNodes[0].issue();
findingDetailsPanel.show(issue);
} else {
findingDetailsPanel.clear();
var highlighting = SonarLintUtils.getService(project, EditorDecorator.class);
highlighting.removeHighlights();
}
}

protected void setToolbar(Collection<AnAction> actions) {
if (mainToolbar != null) {
mainToolbar.setTargetComponent(null);
Expand All @@ -131,7 +107,6 @@ private void createIssuesTree() {
treeBuilder = new IssueTreeModelBuilder(project);
var model = treeBuilder.createModel(false);
tree = new IssueTree(project, model);
tree.addTreeSelectionListener(e -> issueTreeSelectionChanged());
tree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
Expand All @@ -148,7 +123,6 @@ private void createOldIssuesTree() {
oldTreeBuilder = new IssueTreeModelBuilder(project);
var model = oldTreeBuilder.createModel(true);
oldTree = new IssueTree(project, model);
oldTree.addTreeSelectionListener(e -> oldIssueTreeSelectionChanged());
oldTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ class TaintVulnerabilitiesPanel(private val project: Project) : SimpleToolWindow
} else {
issue.module?.let { module -> rulePanel.setSelectedFinding(module, issue, issue.getRuleKey(), issue.getRuleDescriptionContextKey()) }
?: rulePanel.clear()
highlighting.highlight(issue)
}
}
}
Expand Down

0 comments on commit 4d12bfd

Please sign in to comment.