|
3 | 3 | import io.snyk.eclipse.plugin.properties.preferences.Preferences;
|
4 | 4 | import io.snyk.eclipse.plugin.utils.SnykLogger;
|
5 | 5 | import io.snyk.eclipse.plugin.views.SnykView;
|
| 6 | +import io.snyk.eclipse.plugin.wizards.SnykWizard; |
6 | 7 | import io.snyk.languageserver.LsRuntimeEnvironment;
|
7 | 8 | import io.snyk.languageserver.SnykLanguageServer;
|
8 | 9 | import io.snyk.languageserver.download.HttpClientFactory;
|
|
18 | 19 | import org.eclipse.core.runtime.Platform;
|
19 | 20 | import org.eclipse.core.runtime.Status;
|
20 | 21 | import org.eclipse.core.runtime.jobs.Job;
|
| 22 | +import org.eclipse.jface.wizard.WizardDialog; |
21 | 23 | import org.eclipse.ui.IStartup;
|
22 | 24 | import org.eclipse.ui.IWorkbench;
|
23 | 25 | import org.eclipse.ui.IWorkbenchWindow;
|
@@ -52,21 +54,31 @@ public void earlyStartup() {
|
52 | 54 | Job initJob = new Job("Downloading latest Language Server release...") {
|
53 | 55 | @Override
|
54 | 56 | protected IStatus run(IProgressMonitor monitor) {
|
55 |
| - try { |
56 |
| - logger.info("LS: Checking for needed download"); |
57 |
| - if (downloadLS()) { |
58 |
| - logger.info("LS: Need to download"); |
59 |
| - downloading = true; |
60 |
| - monitor.subTask("Starting download of Snyk Language Server"); |
61 |
| - download(monitor); |
| 57 | + PlatformUI.getWorkbench().getDisplay().asyncExec(() -> { |
| 58 | + try { |
| 59 | + logger.info("LS: Checking for needed download"); |
| 60 | + if (downloadLS()) { |
| 61 | + logger.info("LS: Need to download"); |
| 62 | + downloading = true; |
| 63 | + monitor.subTask("Starting download of Snyk Language Server"); |
| 64 | + download(monitor); |
| 65 | + } |
| 66 | + |
| 67 | + monitor.subTask("Starting Snyk Language Server..."); |
| 68 | + SnykLanguageServer.InitializeServer(); |
| 69 | + } catch (Exception exception) { |
| 70 | + logError(exception); |
62 | 71 | }
|
63 |
| - |
64 |
| - monitor.subTask("Starting Snyk Language Server..."); |
65 |
| - SnykLanguageServer.InitializeServer(); |
66 |
| - } catch (Exception exception) { |
67 |
| - logError(exception); |
68 |
| - } |
69 |
| - downloading = false; |
| 72 | + downloading = false; |
| 73 | + |
| 74 | + if (Preferences.getInstance().getAuthToken().isBlank()) { |
| 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 | + |
70 | 82 | return Status.OK_STATUS;
|
71 | 83 | }
|
72 | 84 | };
|
@@ -109,7 +121,8 @@ private boolean downloadLS() {
|
109 | 121 | Instant lastModified = basicFileAttributes.lastModifiedTime().toInstant();
|
110 | 122 | boolean needsUpdate = lastModified.isBefore(Instant.now().minus(4, ChronoUnit.DAYS))
|
111 | 123 | || !Preferences.getInstance().getLspVersion().equals(LsBinaries.REQUIRED_LS_PROTOCOL_VERSION);
|
112 |
| - logger.info(String.format("LS: Needs update? %s. Required LSP version=%s, actual version=%s", needsUpdate, LsBinaries.REQUIRED_LS_PROTOCOL_VERSION, Preferences.getInstance().getLspVersion())); |
| 124 | + logger.info(String.format("LS: Needs update? %s. Required LSP version=%s, actual version=%s", needsUpdate, |
| 125 | + LsBinaries.REQUIRED_LS_PROTOCOL_VERSION, Preferences.getInstance().getLspVersion())); |
113 | 126 | return needsUpdate;
|
114 | 127 | } catch (IOException e) {
|
115 | 128 | SnykLogger.logError(e);
|
|
0 commit comments