Skip to content

Commit b6c4c3e

Browse files
feat: allow users to cancel scans from the browser window
1 parent 2e78463 commit b6c4c3e

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
import java.nio.file.Paths;
66
import java.util.concurrent.CompletableFuture;
77

8+
import org.eclipse.core.commands.ExecutionException;
9+
import org.eclipse.core.commands.NotEnabledException;
10+
import org.eclipse.core.commands.NotHandledException;
11+
import org.eclipse.core.commands.common.CommandException;
12+
import org.eclipse.core.commands.common.NotDefinedException;
813
import org.eclipse.jface.viewers.TreeNode;
914
import org.eclipse.lsp4e.LSPEclipseUtils;
1015
import org.eclipse.lsp4j.Location;
@@ -18,13 +23,17 @@
1823
import org.eclipse.swt.browser.ProgressEvent;
1924
import org.eclipse.swt.program.Program;
2025
import org.eclipse.swt.widgets.Display;
26+
import org.eclipse.ui.PlatformUI;
27+
import org.eclipse.ui.handlers.IHandlerService;
28+
2129
import com.google.gson.Gson;
2230

2331
import io.snyk.eclipse.plugin.html.BaseHtmlProvider;
2432
import io.snyk.eclipse.plugin.html.HtmlProviderFactory;
2533
import io.snyk.eclipse.plugin.html.StaticPageHtmlProvider;
2634
import io.snyk.eclipse.plugin.preferences.Preferences;
2735
import io.snyk.eclipse.plugin.utils.SnykLogger;
36+
import io.snyk.eclipse.plugin.views.snyktoolview.handlers.IHandlerCommands;
2837
import io.snyk.eclipse.plugin.wizards.SnykWizard;
2938

3039
@SuppressWarnings("restriction")
@@ -77,7 +86,15 @@ public Object function(Object[] arguments) {
7786
new BrowserFunction(browser, "stopScan") {
7887
@Override
7988
public Object function(Object[] arguments) {
80-
//TODO Implement this!
89+
90+
IHandlerService handlerService =
91+
(IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
92+
try {
93+
handlerService.executeCommand(IHandlerCommands.STOP_SCAN, null);
94+
} catch (CommandException e) {
95+
SnykLogger.logError(e);
96+
}
97+
8198
return null;
8299
}
83100
};

plugin/src/main/java/io/snyk/eclipse/plugin/wizards/SnykWizard.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected IStatus run(IProgressMonitor monitor) {
9797

9898
public static Object createAndLaunch() {
9999
SnykWizard wizard = new SnykWizard();
100-
WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(),wizard);
100+
WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(), wizard);
101101
dialog.setBlockOnOpen(true);
102102
dialog.open();
103103
return null;

plugin/src/main/java/io/snyk/languageserver/protocolextension/SnykExtendedLanguageClient.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import io.snyk.eclipse.plugin.views.snyktoolview.IssueTreeNode;
7777
import io.snyk.eclipse.plugin.views.snyktoolview.ProductTreeNode;
7878
import io.snyk.eclipse.plugin.views.snyktoolview.SnykToolView;
79+
import io.snyk.eclipse.plugin.views.snyktoolview.handlers.IHandlerCommands;
7980
import io.snyk.eclipse.plugin.wizards.SnykWizard;
8081
import io.snyk.languageserver.CommandHandler;
8182
import io.snyk.languageserver.FeatureFlagConstants;
@@ -207,12 +208,6 @@ public void triggerScan(Path projectPath) {
207208
});
208209
}
209210

210-
public void stopScan() {
211-
CompletableFuture.runAsync(() -> {
212-
executeCommand("STOP_SCAN", new ArrayList<>());
213-
});
214-
}
215-
216211
private CompletableFuture<Object> executeCommand(String cmd, List<Object> args) {
217212
synchronized (chSyncObject) {
218213
if (commandHandler == null) {

0 commit comments

Comments
 (0)