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

feat: select treenode on snyk showdocument [IDE-957] #260

Merged
merged 21 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.resource.FontRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
Expand Down Expand Up @@ -142,8 +141,10 @@ private String getScaledFontSize() {
} catch (IllegalStateException e) {
defaultHeight = 13;
}
// Language server HTML assumes a base font size of 10px. The default Eclipse font size is 17px (13pt), so we
// apply a scaling factor here. This ensures that HTML fonts scale correctly if the user changes the text size.
// Language server HTML assumes a base font size of 10px. The default Eclipse
// font size is 17px (13pt), so we
// apply a scaling factor here. This ensures that HTML fonts scale correctly if
// the user changes the text size.
int scaledHeight = (int) (defaultHeight / 1.7);
return scaledHeight + "pt";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.eclipse.jface.viewers.TreeViewer;

import io.snyk.languageserver.protocolextension.messageObjects.scanResults.Issue;

/**
* This interface captures the externally used methods with the tool window.
* Having it, should allow for easier testing of the business logic apart from
Expand Down Expand Up @@ -125,4 +127,6 @@ static String getPlural(long count) {
* @return
*/
abstract void disableDelta();

abstract void selectTreeNode(Issue issue);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeNode;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.lsp4e.LSPEclipseUtils;
Expand All @@ -42,6 +43,7 @@
import org.eclipse.ui.menus.CommandContributionItemParameter;
import org.eclipse.ui.part.ViewPart;

import io.snyk.eclipse.plugin.domain.ProductConstants;
import io.snyk.eclipse.plugin.preferences.Preferences;
import io.snyk.eclipse.plugin.properties.FolderConfigs;
import io.snyk.eclipse.plugin.utils.ResourceUtils;
Expand Down Expand Up @@ -477,4 +479,31 @@ protected void outputCommandResult(Object result) {
}
}

@Override
public void selectTreeNode(Issue issue) {
ProductTreeNode productNode = getProductNode(ProductConstants.DISPLAYED_CODE_SECURITY, issue.filePath());
selectTreenodeForIssue((TreeNode) productNode, issue);
}

private void selectTreenodeForIssue(TreeNode currentParent, Issue issue) {
for (Object child : currentParent.getChildren()) {
TreeNode childNode = (TreeNode) child;

if (childNode instanceof IssueTreeNode && ((IssueTreeNode) childNode).getIssue().id().equals(issue.id())) {
updateSelection((IssueTreeNode) childNode);
return; // Exit the function as we've found a match
}

if (childNode.getChildren() != null && childNode.getChildren().length != 0) {
selectTreenodeForIssue(childNode, issue);
}
}
}

private void updateSelection(IssueTreeNode issueTreeNode) {
Display.getDefault().asyncExec(() -> {
IStructuredSelection selection = new StructuredSelection(issueTreeNode);
treeViewer.setSelection(selection, true);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ private LsConstants() {
public static final String SNYK_PUBLISH_DIAGNOSTICS_316 = "$/snyk.publishDiagnostics316";
public static final String SNYK_FOLDER_CONFIG = "$/snyk.folderConfigs";
public static final String SNYK_SCAN_SUMMARY = "$/snyk.scanSummary";
public static final String SNYK_SHOW_DOCUMENT = "$/snyk.showDocument";
}
Loading
Loading