Skip to content

Commit cfcb0c5

Browse files
committed
fix: handle enable/disable of tree filters
1 parent e9ad7c2 commit cfcb0c5

4 files changed

Lines changed: 212 additions & 170 deletions

File tree

plugin/plugin.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
<command
149149
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.snykFilterFixableIssuesHandler"
150150
id="io.snyk.eclipse.plugin.commands.snykFilterFixableIssues"
151-
name="Show Fixable Issues">
151+
name="AI Fixable">
152152
</command>
153153
</extension>
154154
<extension point="org.eclipse.ui.menus">
@@ -247,16 +247,6 @@
247247
<menuContribution
248248
allPopups="false"
249249
locationURI="menu:io.snyk.eclipse.plugin.views.snyktoolview">
250-
<menu
251-
id="io.snyk.eclipse.plugin.views.snyktoolview.filtersMenu"
252-
label="Fixablility">
253-
<command
254-
commandId="io.snyk.eclipse.plugin.commands.snykFilterFixableIssues"
255-
icon="icons/enabled.png"
256-
style="push"
257-
tooltip="Show only issues with AIFix or Fix suggestions">
258-
</command>
259-
</menu>
260250
<menu
261251
id="io.snyk.eclipse.plugin.views.snyktoolview.filterSeverityMenu"
262252
label="Severity">
@@ -351,6 +341,16 @@
351341
name="io.snyk.eclipse.plugin.separator.allIssues">
352342
</separator>
353343
</menu>
344+
<menu
345+
id="io.snyk.eclipse.plugin.views.snyktoolview.filtersMenu"
346+
label="Code AI Fixability">
347+
<command
348+
commandId="io.snyk.eclipse.plugin.commands.snykFilterFixableIssues"
349+
icon="icons/enabled.png"
350+
style="push"
351+
tooltip="Show only issues with AIFix or Fix suggestions">
352+
</command>
353+
</menu>
354354
</menuContribution>
355355
<menuContribution
356356
locationURI="popup:io.snyk.eclipse.plugin.views.snyktoolview#PopupTreeMenu">

plugin/src/main/java/io/snyk/eclipse/plugin/SnykStartup.java

Lines changed: 149 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717
import org.eclipse.core.runtime.Status;
1818
import org.eclipse.core.runtime.jobs.Job;
1919
import org.eclipse.jface.wizard.WizardDialog;
20-
import org.eclipse.lsp4e.LanguageServersRegistry;
21-
import org.eclipse.lsp4e.LanguageServiceAccessor;
2220
import org.eclipse.ui.IStartup;
2321
import org.eclipse.ui.IWorkbench;
22+
import org.eclipse.ui.IWorkbenchPage;
2423
import org.eclipse.ui.IWorkbenchWindow;
2524
import org.eclipse.ui.PartInitException;
2625
import org.eclipse.ui.PlatformUI;
2726

2827
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
2928
import io.snyk.eclipse.plugin.utils.SnykLogger;
3029
import io.snyk.eclipse.plugin.views.SnykView;
30+
import io.snyk.eclipse.plugin.views.snyktoolview.ISnykToolView;
31+
import io.snyk.eclipse.plugin.views.snyktoolview.SnykToolView;
3132
import io.snyk.eclipse.plugin.wizards.SnykWizard;
3233
import io.snyk.languageserver.LsRuntimeEnvironment;
3334
import io.snyk.languageserver.SnykLanguageServer;
@@ -36,134 +37,150 @@
3637
import io.snyk.languageserver.download.LsDownloader;
3738

3839
public class SnykStartup implements IStartup {
39-
private static LsRuntimeEnvironment runtimeEnvironment;
40-
private SnykView snykView = null;
41-
private static boolean downloading = true;
42-
private static ILog logger;
43-
44-
private static SnykStartup instance;
45-
46-
@Override
47-
public void earlyStartup() {
48-
instance = this;
49-
if (logger == null) {
50-
logger = Platform.getLog(getClass());
51-
}
52-
runtimeEnvironment = new LsRuntimeEnvironment();
53-
Job initJob = new Job("Downloading latest CLI release...") {
54-
@Override
55-
protected IStatus run(IProgressMonitor monitor) {
56-
try {
57-
logger.info("LS: Checking for needed download");
58-
if (downloadLS()) {
59-
monitor.beginTask("Downloading CLI", 100);
60-
logger.info("LS: Need to download");
61-
downloading = true;
62-
download(monitor);
63-
}
64-
} catch (Exception exception) {
65-
logError(exception);
66-
}
67-
downloading = false;
68-
monitor.subTask("Starting Snyk CLI in Language Server mode...");
69-
startLanguageServer();
70-
71-
PlatformUI.getWorkbench().getDisplay().syncExec(() -> {
72-
Preferences prefs = Preferences.getInstance();
73-
if (prefs.getAuthToken().isBlank() && !prefs.isTest()) {
74-
monitor.subTask("Starting Snyk Wizard to configure initial settings...");
75-
SnykWizard wizard = new SnykWizard();
76-
WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), wizard);
77-
dialog.setBlockOnOpen(true);
78-
dialog.open();
79-
}
80-
});
81-
monitor.done();
82-
83-
return Status.OK_STATUS;
84-
}
85-
86-
private void startLanguageServer() {
87-
try {
88-
SnykLanguageServer.startSnykLanguageServer();
89-
} catch (RuntimeException e) {
90-
logError(e);
91-
}
92-
}
93-
};
94-
initJob.setPriority(Job.LONG);
95-
initJob.schedule();
96-
}
97-
98-
public static SnykView getSnykView() {
99-
if (instance.snykView == null) {
100-
IWorkbench workbench = PlatformUI.getWorkbench();
101-
102-
workbench.getDisplay().syncExec(() -> {
103-
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
104-
105-
if (workbenchWindow != null) {
106-
try {
107-
instance.snykView = SnykView.getInstance();
108-
} catch (PartInitException partInitException) {
109-
logError(partInitException);
110-
}
111-
}
112-
});
113-
}
114-
115-
return instance.snykView;
116-
}
117-
118-
private boolean downloadLS() {
119-
File lsFile = new File(Preferences.getInstance().getCliPath());
120-
logger.info("LS: Expecting file at " + lsFile.getAbsolutePath());
121-
if (!Preferences.getInstance().isManagedBinaries()) {
122-
logger.info("LS: Managed binaries disabled, skipping download");
123-
return false;
124-
}
125-
if (lsFile.exists()) {
126-
logger.info("LS: File already exists, checking for age " + lsFile.getAbsolutePath());
127-
try {
128-
BasicFileAttributes basicFileAttributes;
129-
basicFileAttributes = Files.readAttributes(lsFile.toPath(), BasicFileAttributes.class);
130-
Instant lastModified = basicFileAttributes.lastModifiedTime().toInstant();
131-
boolean needsUpdate = lastModified.isBefore(Instant.now().minus(4, ChronoUnit.DAYS))
132-
|| !Preferences.getInstance().getLspVersion().equals(LsBinaries.REQUIRED_LS_PROTOCOL_VERSION);
133-
logger.info(String.format("LS: Needs update? %s. Required LSP version=%s, actual version=%s", needsUpdate,
134-
LsBinaries.REQUIRED_LS_PROTOCOL_VERSION, Preferences.getInstance().getLspVersion()));
135-
return needsUpdate;
136-
} catch (IOException e) {
137-
SnykLogger.logError(e);
138-
return false;
139-
}
140-
}
141-
return true;
142-
}
143-
144-
static LsDownloader getLsDownloader() throws URISyntaxException {
145-
return new LsDownloader(HttpClientFactory.getInstance(), runtimeEnvironment, logger);
146-
}
147-
148-
@SuppressWarnings("ResultOfMethodCallIgnored")
149-
public static IStatus download(IProgressMonitor monitor) {
150-
final File lsFile = new File(Preferences.getInstance().getCliPath());
151-
try {
152-
LsDownloader lsDownloader = getLsDownloader();
153-
lsFile.getParentFile().mkdirs();
154-
lsDownloader.download(monitor);
155-
lsFile.setExecutable(true);
156-
} catch (RuntimeException | URISyntaxException e) {
157-
return Status.error("Download of Snyk Language Server failed", e);
158-
}
159-
return Status.OK_STATUS;
160-
}
161-
162-
public static boolean isDownloading() {
163-
return downloading;
164-
}
165-
166-
public void setLogger(ILog logger) {
167-
this.logger = logger;
168-
}
40+
private static LsRuntimeEnvironment runtimeEnvironment;
41+
private SnykView snykView = null;
42+
private static boolean downloading = true;
43+
private static ILog logger;
44+
45+
private static SnykStartup instance;
46+
47+
@Override
48+
public void earlyStartup() {
49+
instance = this;
50+
if (logger == null) {
51+
logger = Platform.getLog(getClass());
52+
}
53+
runtimeEnvironment = new LsRuntimeEnvironment();
54+
Job initJob = new Job("Downloading latest CLI release...") {
55+
@Override
56+
protected IStatus run(IProgressMonitor monitor) {
57+
try {
58+
logger.info("LS: Checking for needed download");
59+
if (downloadLS()) {
60+
monitor.beginTask("Downloading CLI", 100);
61+
logger.info("LS: Need to download");
62+
downloading = true;
63+
download(monitor);
64+
}
65+
} catch (Exception exception) {
66+
logError(exception);
67+
}
68+
downloading = false;
69+
monitor.subTask("Starting Snyk CLI in Language Server mode...");
70+
startLanguageServer();
71+
72+
PlatformUI.getWorkbench().getDisplay().syncExec(() -> {
73+
Preferences prefs = Preferences.getInstance();
74+
if (prefs.getAuthToken().isBlank() && !prefs.isTest()) {
75+
monitor.subTask("Starting Snyk Wizard to configure initial settings...");
76+
SnykWizard wizard = new SnykWizard();
77+
WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(),
78+
wizard);
79+
dialog.setBlockOnOpen(true);
80+
dialog.open();
81+
}
82+
});
83+
monitor.done();
84+
85+
return Status.OK_STATUS;
86+
}
87+
88+
private void startLanguageServer() {
89+
try {
90+
SnykLanguageServer.startSnykLanguageServer();
91+
} catch (RuntimeException e) {
92+
logError(e);
93+
}
94+
}
95+
};
96+
initJob.setPriority(Job.LONG);
97+
initJob.schedule();
98+
}
99+
100+
public static SnykView getSnykView() {
101+
if (instance.snykView == null) {
102+
IWorkbench workbench = PlatformUI.getWorkbench();
103+
104+
workbench.getDisplay().syncExec(() -> {
105+
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
106+
107+
if (workbenchWindow != null) {
108+
try {
109+
instance.snykView = SnykView.getInstance();
110+
} catch (PartInitException partInitException) {
111+
logError(partInitException);
112+
}
113+
}
114+
});
115+
}
116+
117+
return instance.snykView;
118+
}
119+
120+
public static ISnykToolView getView() {
121+
122+
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
123+
ISnykToolView toolView;
124+
try {
125+
toolView = (ISnykToolView) activePage.showView(SnykToolView.ID);
126+
} catch (PartInitException e) {
127+
SnykLogger.logError(e);
128+
return null;
129+
}
130+
return toolView;
131+
132+
}
133+
134+
private boolean downloadLS() {
135+
File lsFile = new File(Preferences.getInstance().getCliPath());
136+
logger.info("LS: Expecting file at " + lsFile.getAbsolutePath());
137+
if (!Preferences.getInstance().isManagedBinaries()) {
138+
logger.info("LS: Managed binaries disabled, skipping download");
139+
return false;
140+
}
141+
if (lsFile.exists()) {
142+
logger.info("LS: File already exists, checking for age " + lsFile.getAbsolutePath());
143+
try {
144+
BasicFileAttributes basicFileAttributes;
145+
basicFileAttributes = Files.readAttributes(lsFile.toPath(), BasicFileAttributes.class);
146+
Instant lastModified = basicFileAttributes.lastModifiedTime().toInstant();
147+
boolean needsUpdate = lastModified.isBefore(Instant.now().minus(4, ChronoUnit.DAYS))
148+
|| !Preferences.getInstance().getLspVersion().equals(LsBinaries.REQUIRED_LS_PROTOCOL_VERSION);
149+
logger.info(
150+
String.format("LS: Needs update? %s. Required LSP version=%s, actual version=%s", needsUpdate,
151+
LsBinaries.REQUIRED_LS_PROTOCOL_VERSION, Preferences.getInstance().getLspVersion()));
152+
return needsUpdate;
153+
} catch (IOException e) {
154+
SnykLogger.logError(e);
155+
return false;
156+
}
157+
}
158+
return true;
159+
}
160+
161+
static LsDownloader getLsDownloader() throws URISyntaxException {
162+
return new LsDownloader(HttpClientFactory.getInstance(), runtimeEnvironment, logger);
163+
}
164+
165+
@SuppressWarnings("ResultOfMethodCallIgnored")
166+
public static IStatus download(IProgressMonitor monitor) {
167+
final File lsFile = new File(Preferences.getInstance().getCliPath());
168+
try {
169+
LsDownloader lsDownloader = getLsDownloader();
170+
lsFile.getParentFile().mkdirs();
171+
lsDownloader.download(monitor);
172+
lsFile.setExecutable(true);
173+
} catch (RuntimeException | URISyntaxException e) {
174+
return Status.error("Download of Snyk Language Server failed", e);
175+
}
176+
return Status.OK_STATUS;
177+
}
178+
179+
public static boolean isDownloading() {
180+
return downloading;
181+
}
182+
183+
public void setLogger(ILog logger) {
184+
this.logger = logger;
185+
}
169186
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;
1+
package io.snyk.eclipse.plugin.views.snyktoolview;
22

33
import java.util.ArrayList;
44
import java.util.List;
5+
56
import org.eclipse.jface.viewers.ILabelProvider;
67
import org.eclipse.jface.viewers.TreeViewer;
78
import org.eclipse.jface.viewers.Viewer;

0 commit comments

Comments
 (0)