Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLI-1661 Location numbers should be displayed in the editor #1207

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading