diff --git a/src/main/java/org/sonarlint/intellij/actions/SonarLintToolWindow.java b/src/main/java/org/sonarlint/intellij/actions/SonarLintToolWindow.java index 93908963e..a63cca3b0 100644 --- a/src/main/java/org/sonarlint/intellij/actions/SonarLintToolWindow.java +++ b/src/main/java/org/sonarlint/intellij/actions/SonarLintToolWindow.java @@ -54,6 +54,8 @@ import org.sonarlint.intellij.finding.issue.vulnerabilities.TaintVulnerabilitiesCache; import org.sonarlint.intellij.messages.ProjectBindingListener; import org.sonarlint.intellij.messages.ProjectBindingListenerKt; +import org.sonarlint.intellij.notifications.IncludeResolvedIssueAction; +import org.sonarlint.intellij.notifications.SonarLintProjectNotifications; import org.sonarlint.intellij.ui.CurrentFilePanel; import org.sonarlint.intellij.ui.ReportPanel; import org.sonarlint.intellij.ui.SecurityHotspotsPanel; @@ -382,7 +384,15 @@ public void trySelectIssue(ShowFinding showFinding) { var content = contentManager.findContent(SonarLintToolWindowFactory.CURRENT_FILE_TAB_TITLE); if (content != null) { var currentFilePanel = (CurrentFilePanel) content.getComponent(); - var issue = currentFilePanel.doesIssueExist(showFinding.getFindingKey()); + var issue = currentFilePanel.doesIssueExistFiltered(showFinding.getFindingKey()); + + if (issue == null && currentFilePanel.doesIssueExist(showFinding.getFindingKey())) { + getService(project, SonarLintProjectNotifications.class).notifyUnableToOpenFinding( + "Issue", "The Issue could not be opened since it is resolved.", + new IncludeResolvedIssueAction() + ); + } + currentFilePanel.trySelectFilteredIssue(issue, showFinding); } } diff --git a/src/main/java/org/sonarlint/intellij/notifications/IncludeResolvedIssueAction.kt b/src/main/java/org/sonarlint/intellij/notifications/IncludeResolvedIssueAction.kt new file mode 100644 index 000000000..bd25617c1 --- /dev/null +++ b/src/main/java/org/sonarlint/intellij/notifications/IncludeResolvedIssueAction.kt @@ -0,0 +1,15 @@ +package org.sonarlint.intellij.notifications + +import com.intellij.notification.Notification +import com.intellij.notification.NotificationAction +import com.intellij.openapi.actionSystem.AnActionEvent +import org.sonarlint.intellij.util.SonarLintActions + +class IncludeResolvedIssueAction() : NotificationAction("Include Resolved Issues") { + override fun actionPerformed(e: AnActionEvent, notification: Notification) { + e.project?.let { + SonarLintActions.getInstance().includeResolvedIssuesAction().setSelected(e, true) + } + notification.expire() + } +} diff --git a/src/main/java/org/sonarlint/intellij/ui/CurrentFilePanel.java b/src/main/java/org/sonarlint/intellij/ui/CurrentFilePanel.java index c994a7ed0..634520371 100644 --- a/src/main/java/org/sonarlint/intellij/ui/CurrentFilePanel.java +++ b/src/main/java/org/sonarlint/intellij/ui/CurrentFilePanel.java @@ -193,7 +193,7 @@ private static void populateSubTree(Tree tree, IssueTreeModelBuilder treeBuilder } @CheckForNull - public LiveIssue doesIssueExist(String issueKey) { + public LiveIssue doesIssueExistFiltered(String issueKey) { var issue = treeBuilder.findIssueByKey(issueKey); if (issue.isEmpty()) { issue = oldTreeBuilder.findIssueByKey(issueKey); @@ -201,6 +201,10 @@ public LiveIssue doesIssueExist(String issueKey) { return issue.orElse(null); } + public boolean doesIssueExist(String issueKey) { + return treeBuilder.doesIssueExists(issueKey) || oldTreeBuilder.doesIssueExists(issueKey); + } + public void trySelectFilteredIssue(@Nullable LiveIssue issue, ShowFinding showFinding) { updateOnSelect(issue, showFinding); } diff --git a/src/main/java/org/sonarlint/intellij/ui/tree/IssueTreeModelBuilder.java b/src/main/java/org/sonarlint/intellij/ui/tree/IssueTreeModelBuilder.java index 5391c3efb..b11a8cd0b 100644 --- a/src/main/java/org/sonarlint/intellij/ui/tree/IssueTreeModelBuilder.java +++ b/src/main/java/org/sonarlint/intellij/ui/tree/IssueTreeModelBuilder.java @@ -237,6 +237,21 @@ public Optional findIssueByKey(String issueKey) { return Optional.empty(); } + public boolean doesIssueExists(String issueKey) { + var virtualFile = index.getAllFiles().stream().findFirst(); + if (virtualFile.isPresent()) { + var foundIssue = latestIssues.get(virtualFile.get()).stream().filter(issue -> { + if (issue.getServerKey() != null) { + return issue.getServerKey().equals(issueKey); + } + return false; + }).findFirst(); + + return foundIssue.isPresent(); + } + return false; + } + private static class FileNodeComparator implements Comparator { @Override public int compare(FileNode o1, FileNode o2) { int c = o1.file().getName().compareTo(o2.file().getName());