Skip to content

Commit eed768d

Browse files
ackeShawkyZ
andauthored
feat: new setting for consistent ignores [IDE-714] (#221)
* feat: prepending the treenodes for ignores and AI Fix with identifier * fix: added space after ignore tag * feat: add a call to read feature flags, and call that function to read snykCodeConsistentIgnores * fix: expand treeviewer to show all issues. * fix: wip remvoe ignores filters if needed * fix: rename file * fix: call featureflag service after auth and settings persistence * fix: notifyProgress if param is null * feat: taskprocessor for sending tasks after ls init * fix: tests use current pref * feat: filter issues based on ignore preferences * fix: remove commands if ff for ignores are false * fix: adding the handlers and commands for filters * fix: adding an asyncExec on the ui updates --------- Co-authored-by: Abdelrahman Shawki Hassan <shawki.hassan@snyk.io>
1 parent 8ba9294 commit eed768d

23 files changed

Lines changed: 535 additions & 191 deletions

plugin/plugin.xml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,21 @@
145145
id="io.snyk.eclipse.plugin.commands.snykFilterFixableIssues"
146146
name="AI Fixable">
147147
</command>
148+
<command
149+
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.EnableAllAiFixHandler"
150+
id="io.snyk.eclipse.plugin.snykShowAllSeverities"
151+
name="Show All Severities">
152+
</command>
153+
<command
154+
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.EnableAllProductHandler"
155+
id="io.snyk.eclipse.plugin.command.snykShowAllProducts"
156+
name="Show All Products">
157+
</command>
158+
<command
159+
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.EnableAllIssuesHandler"
160+
id="io.snyk.eclipse.plugin.command.snykShowAllIssuesStatus"
161+
name="Show All Issues">
162+
</command>
148163
</extension>
149164
<extension point="org.eclipse.ui.menus">
150165
<menuContribution
@@ -273,6 +288,12 @@
273288
name="io.snyk.eclipse.plugin.separator.allSeverities"
274289
visible="true">
275290
</separator>
291+
<command
292+
commandId="io.snyk.eclipse.plugin.snykShowAllSeverities"
293+
icon="icons/enabled.png"
294+
style="push"
295+
tooltip="Show Issues of all Severities">
296+
</command>
276297
</menu>
277298
<menu
278299
id="io.snyk.eclipse.plugin.views.snyktoolview.filterProductTypeMenu"
@@ -305,6 +326,12 @@
305326
name="io.snyk.eclipse.plugin.separator.allProducts"
306327
visible="true">
307328
</separator>
329+
<command
330+
commandId="io.snyk.eclipse.plugin.command.snykShowAllProducts"
331+
icon="icons/enabled.png"
332+
style="push"
333+
tooltip="Scan All Products">
334+
</command>
308335
</menu>
309336
<menu
310337
id="io.snyk.eclipse.plugin.views.snyktoolview.filterIgnoreMenu"
@@ -313,7 +340,7 @@
313340
commandId="io.snyk.eclipse.plugin.commands.snykShowOpenIgnored"
314341
icon="icons/enabled.png"
315342
style="push"
316-
tooltip="Hide Ignored">
343+
tooltip="Show Open Issues">
317344
</command>
318345
<command
319346
commandId="io.snyk.eclipse.plugin.commands.snykShowIgnored"
@@ -328,8 +355,15 @@
328355
tooltip="Show Only Net New Issues">
329356
</command>
330357
<separator
331-
name="io.snyk.eclipse.plugin.separator.allIssues">
358+
name="io.snyk.eclipse.plugin.separator.allIssues"
359+
visible="true">
332360
</separator>
361+
<command
362+
commandId="io.snyk.eclipse.plugin.command.snykShowAllIssuesStatus"
363+
icon="icons/enabled.png"
364+
style="push"
365+
tooltip="Show all issues">
366+
</command>
333367
</menu>
334368
<menu
335369
id="io.snyk.eclipse.plugin.views.snyktoolview.filtersMenu"

plugin/src/main/java/io/snyk/eclipse/plugin/analytics/AbstractAnalyticsEvent.java renamed to plugin/src/main/java/io/snyk/eclipse/plugin/analytics/AbstractTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package io.snyk.eclipse.plugin.analytics;
22

3-
public interface AbstractAnalyticsEvent {
3+
public interface AbstractTask {
44

55
}

plugin/src/main/java/io/snyk/eclipse/plugin/analytics/AnalyticsEvent.java renamed to plugin/src/main/java/io/snyk/eclipse/plugin/analytics/AnalyticsEventTask.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
1010

11-
public class AnalyticsEvent implements AbstractAnalyticsEvent {
11+
public class AnalyticsEventTask implements AbstractTask {
1212
private final String interactionType;
1313
private final List<String> category;
1414
private final String status;
@@ -19,7 +19,7 @@ public class AnalyticsEvent implements AbstractAnalyticsEvent {
1919
private final List<Object> errors;
2020
private final Map<String, Object> extension;
2121

22-
public AnalyticsEvent(String interactionType, List<String> category, String status, String targetId, long timestampMs, long durationMs, Map<String, Object> results, List<Object> errors, Map<String, Object> extension) {
22+
public AnalyticsEventTask(String interactionType, List<String> category, String status, String targetId, long timestampMs, long durationMs, Map<String, Object> results, List<Object> errors, Map<String, Object> extension) {
2323
this.interactionType = interactionType;
2424
this.category = category;
2525
this.status = status != null ? status : "success";
@@ -32,7 +32,7 @@ public AnalyticsEvent(String interactionType, List<String> category, String stat
3232
this.extension.put("device_id", Preferences.getInstance().getPref(Preferences.DEVICE_ID));
3333
}
3434

35-
public AnalyticsEvent(String interactionType, List<String> category) {
35+
public AnalyticsEventTask(String interactionType, List<String> category) {
3636
this(interactionType, category, null, null, 0, 0, null, null, null);
3737
}
3838

plugin/src/main/java/io/snyk/eclipse/plugin/analytics/AnalyticsSender.java

Lines changed: 0 additions & 65 deletions
This file was deleted.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package io.snyk.eclipse.plugin.analytics;
2+
3+
import java.util.LinkedList;
4+
import java.util.concurrent.CompletableFuture;
5+
import java.util.concurrent.ConcurrentLinkedQueue;
6+
import java.util.function.Consumer;
7+
8+
import org.apache.commons.lang3.tuple.Pair;
9+
10+
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
11+
import io.snyk.eclipse.plugin.utils.SnykLogger;
12+
import io.snyk.languageserver.protocolextension.SnykExtendedLanguageClient;
13+
14+
/*
15+
* Process Tasks after Language Server is initialized a valid token exists
16+
*/
17+
public class TaskProcessor {
18+
// left = taskToExecute, right = callback function
19+
private final ConcurrentLinkedQueue<Pair<Consumer<SnykExtendedLanguageClient>, Consumer<Void>>> taskQueue = new ConcurrentLinkedQueue<>();
20+
21+
private TaskProcessor() {
22+
CompletableFuture.runAsync(() -> { start(); });
23+
}
24+
25+
private static TaskProcessor instance;
26+
27+
public static TaskProcessor getInstance() {
28+
if (instance == null) {
29+
synchronized (TaskProcessor.class) {
30+
if (instance == null) {
31+
instance = new TaskProcessor();
32+
}
33+
}
34+
}
35+
return instance;
36+
}
37+
38+
private void start() {
39+
while (true) {
40+
String authToken = Preferences.getInstance().getAuthToken();
41+
var lc = SnykExtendedLanguageClient.getInstance();
42+
if (taskQueue.isEmpty() || authToken == null || authToken.isBlank() || lc == null) {
43+
try {
44+
Thread.sleep(1000);
45+
} catch (InterruptedException e) {
46+
Thread.currentThread().interrupt();
47+
}
48+
continue;
49+
}
50+
LinkedList<Pair<Consumer<SnykExtendedLanguageClient>, Consumer<Void>>> copyForSending
51+
= new LinkedList<>(taskQueue);
52+
53+
for (Pair<Consumer<SnykExtendedLanguageClient>, Consumer<Void>> event : copyForSending) {
54+
try {
55+
// Execute the task with the language client
56+
event.getLeft().accept(lc);
57+
// Execute the callback
58+
if(event.getRight() != null) {
59+
event.getRight().accept(null);
60+
}
61+
} catch (Exception e) {
62+
SnykLogger.logError(e);
63+
} finally {
64+
taskQueue.remove(event);
65+
}
66+
}
67+
}
68+
}
69+
70+
public void registerTask(Consumer<SnykExtendedLanguageClient> task, Consumer<Void> callback) {
71+
var pair = Pair.of(task, callback);
72+
taskQueue.add(pair);
73+
}
74+
}

plugin/src/main/java/io/snyk/eclipse/plugin/properties/PreferencesPage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ public boolean performOk() {
127127
snykView.disableRunAbortActions();
128128
snykView.toggleRunActionEnablement();
129129
disableSnykCodeIfOrgDisabled();
130-
131130
new LsConfigurationUpdater().configurationChanged();
131+
SnykExtendedLanguageClient.getInstance().refreshFeatureFlags();
132+
132133
return superOK;
133134
}
134135

plugin/src/main/java/io/snyk/eclipse/plugin/properties/preferences/Preferences.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public static synchronized Preferences getInstance(PreferenceStore store) {
5555
public static final String FILTER_IGNORES_SHOW_IGNORED_ISSUES = "FILTER_IGNORES_IGNORED_ISSUES";
5656
public static final String FILTER_FIXABLE_ISSUES = "FILTER_FIXABLE_ISSUES";
5757

58+
// Feature flags
59+
public static final String IS_GLOBAL_IGNORES_FEATURE_ENABLED = "IS_GLOBAL_IGNORES_FEATURE_ENABLED";
60+
5861
// This is a bit confusing - CLI takes DISABLE as env variable, but we ask for
5962
// ENABLE, so we need to revert it
6063
// when populating the environment
@@ -98,16 +101,16 @@ public static synchronized Preferences getInstance(PreferenceStore store) {
98101
store(FILTER_CRITICAL, "false");
99102
}
100103
if (getPref(FILTER_DELTA_NEW_ISSUES) == null) {
101-
store(FILTER_DELTA_NEW_ISSUES, "false");
104+
store(FILTER_DELTA_NEW_ISSUES, "false");
102105
}
103106
if (getPref(FILTER_IGNORES_SHOW_OPEN_ISSUES) == null) {
104-
store(FILTER_IGNORES_SHOW_OPEN_ISSUES, "true");
107+
store(FILTER_IGNORES_SHOW_OPEN_ISSUES, "true");
105108
}
106109
if (getPref(FILTER_IGNORES_SHOW_IGNORED_ISSUES) == null) {
107-
store(FILTER_IGNORES_SHOW_IGNORED_ISSUES, "true");
110+
store(FILTER_IGNORES_SHOW_IGNORED_ISSUES, "true");
108111
}
109112
if (getPref(FILTER_FIXABLE_ISSUES) == null) {
110-
store(FILTER_FIXABLE_ISSUES, "false");
113+
store(FILTER_FIXABLE_ISSUES, "false");
111114
}
112115

113116
if (getPref(SEND_ERROR_REPORTS) == null) {
@@ -125,6 +128,9 @@ public static synchronized Preferences getInstance(PreferenceStore store) {
125128
if (getPref(LSP_VERSION) == null) {
126129
store(LSP_VERSION, "1");
127130
}
131+
if (getPref(IS_GLOBAL_IGNORES_FEATURE_ENABLED) == null) {
132+
store(IS_GLOBAL_IGNORES_FEATURE_ENABLED, "false");
133+
}
128134

129135
String token = SystemUtils.getEnvironmentVariable(EnvironmentConstants.ENV_SNYK_TOKEN, "");
130136
if (getPref(AUTH_TOKEN_KEY) == null && !"".equals(token)) {

plugin/src/main/java/io/snyk/languageserver/protocolextension/FileTreeNode.java renamed to plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/FileTreeNode.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.snyk.languageserver.protocolextension;
1+
package io.snyk.eclipse.plugin.views.snyktoolview;
22

33
import java.nio.file.Path;
44
import java.nio.file.Paths;
@@ -8,8 +8,6 @@
88
import org.eclipse.swt.graphics.Image;
99
import org.eclipse.ui.model.WorkbenchLabelProvider;
1010

11-
import io.snyk.eclipse.plugin.views.snyktoolview.BaseTreeNode;
12-
1311
public class FileTreeNode extends BaseTreeNode {
1412
private Path path;
1513

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package io.snyk.eclipse.plugin.views.snyktoolview;
22

3-
import io.snyk.languageserver.protocolextension.FileTreeNode;
4-
5-
import org.eclipse.jface.resource.ImageDescriptor;
63
import org.eclipse.jface.viewers.TreeViewer;
74

85

@@ -15,7 +12,7 @@ public interface ISnykToolView {
1512
String CONGRATS_NO_ISSUES_FOUND = "✅ Congrats! No issues found!";
1613
String NO_FIXABLE_ISSUES = "There are no issues automatically fixable.";
1714
String IGNORED_ISSUES_FILTERED_BUT_AVAILABLE = "Adjust your Issue View Options to see ignored issues.";
18-
String OPEN_ISSUES_FILTERED_BUT_AVAILABLE = "Adjust your Issue View Options to open issues.";
15+
String OPEN_ISSUES_FILTERED_BUT_AVAILABLE = "Adjust your Issue View Options to see open issues.";
1916

2017
String NODE_TEXT_SCANNING = "Scanning...";
2118
String NODE_TEXT_NO_ISSUES_FOUND = "No issues found";
@@ -98,4 +95,6 @@ static String getPlural(long count) {
9895
}
9996

10097
abstract TreeViewer getTreeViewer();
98+
99+
abstract void toggleIgnoresButtons();
101100
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package io.snyk.eclipse.plugin.views.snyktoolview;
22

3-
import org.eclipse.core.resources.ResourcesPlugin;
43
import org.eclipse.jface.resource.ImageDescriptor;
5-
import org.eclipse.swt.graphics.Image;
6-
import org.eclipse.ui.model.WorkbenchLabelProvider;
74

85
import io.snyk.eclipse.plugin.domain.ProductConstants;
96
import io.snyk.eclipse.plugin.utils.SnykIcons;
@@ -29,7 +26,7 @@ public String getDetails() {
2926

3027
@Override
3128
public ImageDescriptor getImageDescriptor() {
32-
switch(getIssue().severity()) {
29+
switch (getIssue().severity()) {
3330
case ProductConstants.SEVERITY_CRITICAL:
3431
return SnykIcons.SEVERITY_CRITICAL;
3532
case ProductConstants.SEVERITY_HIGH:
@@ -50,6 +47,5 @@ public Issue getIssue() {
5047
public void setIssue(Issue issue) {
5148
this.issue = issue;
5249
}
53-
54-
50+
5551
}

0 commit comments

Comments
 (0)