Skip to content

Commit 18f68ef

Browse files
authored
Merge branch 'main' into fix/IDE-897_new_severity_icons
2 parents ce8ae1d + 5745769 commit 18f68ef

File tree

13 files changed

+61
-40
lines changed

13 files changed

+61
-40
lines changed

.github/workflows/resource-check.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Static Resource Checking
22
on:
33
push:
4-
branches: [ master ]
4+
branches: [ main, master ]
55
pull_request:
66

77
jobs:
@@ -14,7 +14,7 @@ jobs:
1414
- name: Check Static Resources
1515
run: |
1616
declare -A resources
17-
# Add each resource as a key, value pair, mapping the local resource to the reference file (which should be stored in the lanaguage server repository). For example:
17+
# Add each resource as a key, value pair, mapping the local resource to the reference file (which should be stored in the language server repository). For example:
1818
# resources["<path_to_local_file>"]="<url_of_reference_file>"
1919
resources["plugin/src/main/resources/ui/html/ScanSummaryInit.html"]="https://raw.githubusercontent.com/snyk/snyk-ls/refs/heads/main/shared_ide_resources/ui/html/ScanSummaryInit.html"
2020
for key in ${!resources[@]}; do

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
- added support for DeepCode AI Fixes
88
- new severity icons
99

10+
### Fixes
11+
- fixes open & ignored issue filtering toggles
12+
1013
## [3.0.0]
1114
### Changes
1215
- process api URL from hasAuthenticated message

plugin/src/main/java/io/snyk/eclipse/plugin/html/BaseHtmlProvider.java

+23-11
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public String replaceCssVariables(String html) {
103103
htmlStyled = htmlStyled.replace("<style nonce=\"ideNonce\" data-ide-style></style>", css);
104104
htmlStyled = htmlStyled.replace("var(--default-font)",
105105
" ui-sans-serif, \"SF Pro Text\", \"Segoe UI\", \"Ubuntu\", Tahoma, Geneva, Verdana, sans-serif;");
106-
htmlStyled = htmlStyled.replace("var(--main-font-size)", getScaledFontSize());
106+
htmlStyled = htmlStyled.replace("var(--main-font-size)", getRelativeFontSize(getDefaultFontSize()));
107107

108108
// Replace CSS variables with actual color values
109109
htmlStyled = htmlStyled.replace("var(--text-color)",
@@ -137,19 +137,31 @@ public String replaceCssVariables(String html) {
137137
return htmlStyled;
138138
}
139139

140-
private String getScaledFontSize() {
141-
int defaultHeight;
140+
@SuppressWarnings("PMD.EmptyCatchBlock")
141+
private int getDefaultFontSize() {
142+
int fontSize = 13;
142143
try {
143-
defaultHeight = getCurrentTheme().getFontRegistry().getFontData(JFaceResources.TEXT_FONT)[0].getHeight();
144+
fontSize = getCurrentTheme().getFontRegistry().getFontData(JFaceResources.TEXT_FONT)[0].getHeight();
144145
} catch (IllegalStateException e) {
145-
defaultHeight = 13;
146+
// TODO improve the logic here. Expected only in unit tests.
146147
}
147-
// Language server HTML assumes a base font size of 10px. The default Eclipse
148-
// font size is 17px (13pt), so we
149-
// apply a scaling factor here. This ensures that HTML fonts scale correctly if
150-
// the user changes the text size.
151-
int scaledHeight = (int) (defaultHeight / 1.7);
152-
return scaledHeight + "pt";
148+
return fontSize;
149+
}
150+
151+
// Utility function to scale Eclipse fonts appropriately for use in HTML elements that have been designed with
152+
// px values in mind.
153+
private String getRelativeFontSize(int inputFontSizePt) {
154+
// Target size is the base size for which the HTML element was designed.
155+
int targetSizePx = 10;
156+
int startingFontSizePt = inputFontSizePt > 0 ? inputFontSizePt : getDefaultFontSize();
157+
158+
// FontRegistry uses pt sizes, not px, so we convert here, using standard web values from
159+
// https://www.w3.org/TR/css3-values/#absolute-lengths
160+
double pxToPtMultiplier = 72.0 / 96.0;
161+
double targetSizePt = targetSizePx * pxToPtMultiplier;
162+
163+
// CSS allows 3 decimal places of precision for calculations.
164+
return String.format("%.3frem", targetSizePt / startingFontSizePt);
153165
}
154166

155167
public String getColorAsHex(String colorKey, String defaultColor) {

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/TreeViewerFilter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private boolean isIssueVisible(IssueTreeNode issueNode) {
4848
}
4949

5050
for (var filter : this.filters.values()) {
51-
if (!filter.test(issue)) {
51+
if (filter.test(issue)) {
5252
return false;
5353
}
5454
}

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/filters/BaseFilter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public void applyFilter() {
2323
boolean booleanPref = this.preferences.getBooleanPref(this.filterName);
2424

2525
if (booleanPref) {
26-
this.filterManager.removeTreeFilter(this.filterName);
26+
this.filterManager.removeTreeFilter(this.filterName); // Showing "a thing" removes it from being filtered out.
2727
} else {
28-
this.filterManager.addTreeFilter(this.filterName, predicate);
28+
this.filterManager.addTreeFilter(this.filterName, predicate); // Hiding (unchecking) "a thing" adds a filter to filter it out.
2929
}
3030
}
31-
}
31+
}

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/filters/FixableFilter.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
import io.snyk.languageserver.protocolextension.messageObjects.scanResults.Issue;
99

1010
public class FixableFilter extends BaseFilter {
11-
private static final Predicate<Issue> predicate = issue -> issue.hasFix();
11+
private static final Predicate<Issue> predicate = issue -> !issue.hasFix(); // Inverse predicate, see below.
1212

1313
public FixableFilter(TreeFilterManager tfm) {
1414
super(FILTER_SHOW_ONLY_FIXABLE, predicate, tfm);
1515
}
1616

1717
@Override
1818
public void applyFilter() {
19-
// this is inverse to the other filters, so we need to overwrite the BaseFilter logic
19+
// This is inverse to the other filters, so we need to overwrite the BaseFilter logic.
20+
// Deselecting show fixable issues should not hide fixable issues and show all issues.
21+
// Therefore when deactivated we cannot have a filter added, so the logic is flipped.
2022
boolean booleanPref = preferences.getBooleanPref(this.filterName);
2123

2224
if (booleanPref) {

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/filters/IgnoresIgnoredIssuesFilter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ public IgnoresIgnoredIssuesFilter(TreeFilterManager tfm) {
1414
super(FILTER_IGNORES_SHOW_IGNORED_ISSUES, predicate, tfm);
1515
}
1616

17-
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package io.snyk.eclipse.plugin.views.snyktoolview.filters;
22

3-
import static io.snyk.eclipse.plugin.preferences.Preferences.FILTER_IGNORES_SHOW_IGNORED_ISSUES;
3+
import static io.snyk.eclipse.plugin.preferences.Preferences.FILTER_IGNORES_SHOW_OPEN_ISSUES;
44

55
import java.util.function.Predicate;
66

77
import io.snyk.eclipse.plugin.views.snyktoolview.TreeFilterManager;
88
import io.snyk.languageserver.protocolextension.messageObjects.scanResults.Issue;
99

10-
public class IgnoresOpenIssuesFilter extends BaseFilter {
10+
public class IgnoresOpenIssuesFilter extends BaseFilter {
1111
private static final Predicate<Issue> predicate = issue -> !issue.isIgnored();
1212

1313
public IgnoresOpenIssuesFilter(TreeFilterManager tfm) {
14-
super(FILTER_IGNORES_SHOW_IGNORED_ISSUES, predicate, tfm);
14+
super(FILTER_IGNORES_SHOW_OPEN_ISSUES, predicate, tfm);
1515
}
16-
}
16+
}

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/filters/ProductFilter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public ProductFilter(TreeFilterManager tfm, String filterName) {
2222
@SuppressWarnings("rawtypes")
2323
private static Predicate getPredicate(String filterName) {
2424
String filterableIssueType = preferenceToProductConstants.get(filterName);
25-
Predicate<Issue> predicate = issue -> !issue.filterableIssueType().equals(filterableIssueType);
25+
Predicate<Issue> predicate = issue -> issue.filterableIssueType().equals(filterableIssueType);
2626
return predicate;
2727
}
28-
}
28+
}

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/filters/SeverityFilter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public SeverityFilter(TreeFilterManager tfm, String preferenceKey) {
2121
@SuppressWarnings("rawtypes")
2222
private static Predicate getPredicate(String preferenceKey) {
2323
String severityCondition = preferenceToProductConstants.get(preferenceKey);
24-
Predicate<Issue> predicate = issue -> !issue.severity().equals(severityCondition);
24+
Predicate<Issue> predicate = issue -> issue.severity().equals(severityCondition);
2525
return predicate;
26-
}
27-
}
26+
}
27+
}

plugin/src/main/java/io/snyk/languageserver/SnykIssueCache.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public void clearAll() {
5656
* @param path The file path for which issues should be removed
5757
*/
5858
public void removeAllIssuesForPath(String path) {
59-
codeSecurityIssues.clear();
60-
codeQualityIssues.clear();
59+
codeSecurityIssues.remove(path);
60+
codeQualityIssues.remove(path);
6161
ossIssues.remove(path);
6262
iacIssues.remove(path);
6363
}

plugin/src/main/resources/ui/html/ScanSummaryInit.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
to { transform: rotate(360deg); }
3232
}
3333

34-
.snx-h1 { font-size: 2rem; font-weight: 600; margin: .8rem 0; }
34+
.snx-h1 { font-size: 1.6rem; font-weight: 400; margin: .4rem 0; }
3535

3636
.snx-status { display:flex; align-items:center; padding: .4rem 1.2rem; background-color: rgba(255,255,255,.1); border-radius: 1rem; }
3737

tests/src/test/java/io/snyk/eclipse/plugin/views/snyktoolview/TreeViewerFilterTest.java

+12-8
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ void testSelect_IssueTreeNodeWithMatchingFilter() {
4343
Issue issue = mock(Issue.class);
4444
when(issueNode.getIssue()).thenReturn(issue);
4545

46-
Predicate<Issue> predicate = i -> true; // Always matches
46+
Predicate<Issue> predicate = i -> true; // Always matches, so filtered out.
4747
filter.putFilterPredicate("test", predicate);
4848

49-
assertTrue(filter.select(mockViewer, null, issueNode));
49+
assertFalse(filter.select(mockViewer, null, issueNode));
5050
}
5151

5252
@Test
@@ -55,10 +55,10 @@ void testSelect_IssueTreeNodeWithNonMatchingFilter() {
5555
Issue issue = mock(Issue.class);
5656
when(issueNode.getIssue()).thenReturn(issue);
5757

58-
Predicate<Issue> predicate = i -> false; // Never matches
58+
Predicate<Issue> predicate = i -> false; // Never matches, so not filtered out.
5959
filter.putFilterPredicate("test", predicate);
6060

61-
assertFalse(filter.select(mockViewer, null, issueNode));
61+
assertTrue(filter.select(mockViewer, null, issueNode));
6262
}
6363

6464
@Test
@@ -85,13 +85,17 @@ void testSelect_FileTreeNodeWithNoVisibleChildren() {
8585

8686
@Test
8787
void testRemoveFilterPredicate() {
88-
Predicate<Issue> predicate = i -> false;
88+
IssueTreeNode issueNode = mock(IssueTreeNode.class);
89+
Issue issue = mock(Issue.class);
90+
when(issueNode.getIssue()).thenReturn(issue);
91+
92+
Predicate<Issue> predicate = i -> true; // Always matches, so filtered out.
8993
filter.putFilterPredicate("test", predicate);
9094

91-
assertTrue(filter.select(mockViewer, null, mock(IssueTreeNode.class)));
95+
assertFalse(filter.select(mockViewer, null, issueNode));
9296

9397
filter.removeFilterPredicate("test");
9498

95-
assertTrue(filter.select(mockViewer, null, mock(IssueTreeNode.class)));
99+
assertTrue(filter.select(mockViewer, null, issueNode));
96100
}
97-
}
101+
}

0 commit comments

Comments
 (0)