1515import org .eclipse .jface .wizard .WizardDialog ;
1616import org .eclipse .lsp4e .LanguageClientImpl ;
1717import org .eclipse .lsp4j .ExecuteCommandParams ;
18- import org .eclipse .lsp4j .MessageParams ;
19- import org .eclipse .lsp4j .MessageType ;
2018import org .eclipse .lsp4j .ProgressParams ;
2119import org .eclipse .lsp4j .WorkDoneProgressCreateParams ;
2220import org .eclipse .lsp4j .jsonrpc .services .JsonNotification ;
2624import org .eclipse .ui .IWorkbenchWindow ;
2725import org .eclipse .ui .PlatformUI ;
2826
29- import com .fasterxml .jackson .core .JsonProcessingException ;
3027import com .fasterxml .jackson .databind .DeserializationFeature ;
3128import com .fasterxml .jackson .databind .ObjectMapper ;
3229
3633import io .snyk .eclipse .plugin .views .SnykView ;
3734import io .snyk .eclipse .plugin .wizards .SnykWizard ;
3835import io .snyk .languageserver .protocolextension .messageObjects .HasAuthenticatedParam ;
39- import io .snyk .languageserver .protocolextension .messageObjects .OAuthToken ;
4036import io .snyk .languageserver .protocolextension .messageObjects .SnykIsAvailableCliParams ;
4137import io .snyk .languageserver .protocolextension .messageObjects .SnykTrustedFoldersParams ;
4238
4541public class SnykExtendedLanguageClient extends LanguageClientImpl {
4642 private final ProgressManager progressMgr = new ProgressManager ();
4743 private static SnykExtendedLanguageClient instance = null ;
48- private final ObjectMapper om = new ObjectMapper ();
44+ // we overwrite the super-class field, so we can mock it
4945
50- @ SuppressWarnings ("unused" ) // used in lsp4e language server instantiation
5146 public SnykExtendedLanguageClient () {
5247 super ();
5348 instance = this ;
5449 }
55-
50+
5651 public static SnykExtendedLanguageClient getInstance () {
5752 return instance ; // we leave instantiation to LSP4e, no lazy construction here
5853 }
@@ -122,12 +117,27 @@ public boolean getSastEnabled() {
122117 @ JsonNotification (value = "$/snyk.hasAuthenticated" )
123118 public void hasAuthenticated (HasAuthenticatedParam param ) {
124119 var prefs = Preferences .getInstance ();
125- prefs .store (Preferences .AUTH_TOKEN_KEY , param .getToken ());
126- triggerScan (null );
127-
128- if (!param .getToken ().isBlank ()) {
129- showAuthenticatedMessage ();
130- enableSnykViewRunActions ();
120+
121+ var oldToken = prefs .getAuthToken ();
122+ var oldApi = prefs .getEndpoint ();
123+
124+ if (param .getApiUrl () != null && !param .getApiUrl ().isBlank () && !param .getApiUrl ().equals (oldApi )) {
125+ prefs .store (Preferences .ENDPOINT_KEY , param .getApiUrl ());
126+ }
127+
128+ String newToken = param .getToken ();
129+ boolean differentToken = newToken != oldToken ;
130+
131+ if (differentToken ) {
132+ prefs .store (Preferences .AUTH_TOKEN_KEY , newToken );
133+ }
134+
135+ if (!newToken .isBlank () && PlatformUI .isWorkbenchRunning ()) {
136+ enableSnykViewRunActions ();
137+ }
138+
139+ if (differentToken && !newToken .isBlank ()) {
140+ triggerScan (null );
131141 }
132142 }
133143
@@ -175,13 +185,6 @@ private void enableSnykViewRunActions() {
175185 });
176186 }
177187
178- private void showAuthenticatedMessage () {
179- MessageParams messageParams = new MessageParams ();
180- messageParams .setType (MessageType .Info );
181- messageParams .setMessage ("The authentication token has been stored in Snyk Preferences." );
182- super .showMessage (messageParams );
183- }
184-
185188 private void runForProject (String projectName ) {
186189 SnykView snykView = SnykStartup .getSnykView ();
187190 if (snykView != null ) {
@@ -197,6 +200,8 @@ private void executeCommand(@NonNull String command, List<Object> arguments) {
197200 SnykLogger .logError (e );
198201 }
199202 }
203+
204+
200205
201206 /**
202207 * Refresh the token using language server. Waits up to 2s for the token change.
0 commit comments