Skip to content

Commit

Permalink
SLI-1137 Warn user during Open in IDE for issues and propose to remov…
Browse files Browse the repository at this point in the history
…e filtering if issue is hidden
  • Loading branch information
eray-felek-sonarsource committed Nov 14, 2024
1 parent cd4ec3e commit 0aee77e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -382,7 +384,15 @@ public <T extends Finding> void trySelectIssue(ShowFinding<T> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,18 @@ 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);
}
return issue.orElse(null);
}

public boolean doesIssueExist(String issueKey) {
return treeBuilder.doesIssueExists(issueKey) || oldTreeBuilder.doesIssueExists(issueKey);
}

public <T extends Finding> void trySelectFilteredIssue(@Nullable LiveIssue issue, ShowFinding<T> showFinding) {
updateOnSelect(issue, showFinding);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,21 @@ public Optional<LiveIssue> 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<FileNode> {
@Override public int compare(FileNode o1, FileNode o2) {
int c = o1.file().getName().compareTo(o2.file().getName());
Expand Down

0 comments on commit 0aee77e

Please sign in to comment.