Skip to content

Commit

Permalink
Consolidate events into their own package (#385)
Browse files Browse the repository at this point in the history
* Refactor asset provider to handle JS asset setup

* Move events to their own package

* Move progress listener for flicker bug out of asset providers
  • Loading branch information
taldekar authored Feb 27, 2025
1 parent a4a0a5c commit eeb5664
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.eclipse.amazonq.lsp.manager;
package software.aws.toolkits.eclipse.amazonq.broker.events;

public enum LspState {
public enum AmazonQLspState {

ACTIVE, FAILED, PENDING;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.eclipse.amazonq.views.router;
package software.aws.toolkits.eclipse.amazonq.broker.events;

public enum AmazonQViewType {
TOOLKIT_LOGIN_VIEW, CHAT_VIEW, DEPENDENCY_MISSING_VIEW, RE_AUTHENTICATE_VIEW, CHAT_ASSET_MISSING_VIEW,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.eclipse.amazonq.providers.browser;
package software.aws.toolkits.eclipse.amazonq.broker.events;

public enum BrowserCompatibilityState {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.eclipse.amazonq.providers.assets;
package software.aws.toolkits.eclipse.amazonq.broker.events;

public enum ChatWebViewAssetState {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.eclipse.amazonq.providers.assets;
package software.aws.toolkits.eclipse.amazonq.broker.events;

public enum ToolkitLoginWebViewAssetState {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.eclipse.amazonq.broker.events;

import software.aws.toolkits.eclipse.amazonq.lsp.auth.model.AuthState;

public record ViewRouterPluginState(AuthState authState, AmazonQLspState lspState, BrowserCompatibilityState browserCompatibilityState,
ChatWebViewAssetState chatWebViewAssetState, ToolkitLoginWebViewAssetState toolkitLoginWebViewAssetState) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import software.aws.toolkits.eclipse.amazonq.broker.events.AmazonQLspState;
import software.aws.toolkits.eclipse.amazonq.chat.ChatCommunicationManager;
import software.aws.toolkits.eclipse.amazonq.chat.models.ChatUIInboundCommand;
import software.aws.toolkits.eclipse.amazonq.chat.models.GenericCommandParams;
import software.aws.toolkits.eclipse.amazonq.chat.models.SendToPromptParams;
import software.aws.toolkits.eclipse.amazonq.chat.models.TriggerType;
import software.aws.toolkits.eclipse.amazonq.lsp.auth.model.AuthState;
import software.aws.toolkits.eclipse.amazonq.lsp.manager.LspState;
import software.aws.toolkits.eclipse.amazonq.plugin.Activator;
import software.aws.toolkits.eclipse.amazonq.telemetry.ToolkitTelemetryProvider;
import software.aws.toolkits.eclipse.amazonq.telemetry.metadata.ExceptionMetadata;
Expand All @@ -29,14 +29,14 @@
public abstract class AbstractQChatEditorActionsHandler extends AbstractHandler {

private final Observable<AuthState> authStateObservable;
private final Observable<LspState> lspStateObservable;
private final Observable<AmazonQLspState> lspStateObservable;

private record PluginState(AuthState authState, LspState lspState) {
private record PluginState(AuthState authState, AmazonQLspState lspState) {
}

public AbstractQChatEditorActionsHandler() {
authStateObservable = Activator.getEventBroker().ofObservable(AuthState.class);
lspStateObservable = Activator.getEventBroker().ofObservable(LspState.class);
lspStateObservable = Activator.getEventBroker().ofObservable(AmazonQLspState.class);
}

public final PluginState getState() {
Expand All @@ -48,7 +48,7 @@ public final PluginState getState() {
public final boolean isEnabled() {
try {
PluginState pluginState = getState();
return pluginState.authState.isLoggedIn() && !(pluginState.lspState == LspState.FAILED);
return pluginState.authState.isLoggedIn() && !(pluginState.lspState == AmazonQLspState.FAILED);
} catch (Exception e) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import java.util.Map;

import software.amazon.awssdk.utils.StringUtils;
import software.aws.toolkits.eclipse.amazonq.broker.events.AmazonQLspState;
import software.aws.toolkits.eclipse.amazonq.lsp.encryption.DefaultLspEncryptionManager;
import software.aws.toolkits.eclipse.amazonq.lsp.manager.LspManager;
import software.aws.toolkits.eclipse.amazonq.lsp.manager.LspState;
import software.aws.toolkits.eclipse.amazonq.lsp.manager.fetcher.RecordLspSetupArgs;
import software.aws.toolkits.eclipse.amazonq.plugin.Activator;
import software.aws.toolkits.eclipse.amazonq.preferences.AmazonQPreferencePage;
Expand Down Expand Up @@ -43,7 +43,7 @@ public QLspConnectionProvider() throws IOException {
commands.add("--set-credentials-encryption-key");
setCommands(commands);
} catch (Exception e) {
Activator.getEventBroker().post(LspState.class, LspState.FAILED);
Activator.getEventBroker().post(AmazonQLspState.class, AmazonQLspState.FAILED);
throw(e);
}

Expand Down Expand Up @@ -78,12 +78,12 @@ public final void start() throws IOException {

lspEncryption.initializeEncryptedCommunication(serverStdIn);
} catch (Exception e) {
Activator.getEventBroker().post(LspState.class, LspState.FAILED);
Activator.getEventBroker().post(AmazonQLspState.class, AmazonQLspState.FAILED);
emitInitFailure(ExceptionMetadata.scrubException(e));
Activator.getLogger().error("Error occured while initializing communication with Amazon Q Lsp Server", e);
}
} catch (Exception e) {
Activator.getEventBroker().post(LspState.class, LspState.FAILED);
Activator.getEventBroker().post(AmazonQLspState.class, AmazonQLspState.FAILED);
emitInitFailure(ExceptionMetadata.scrubException(e));
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;

import software.aws.toolkits.eclipse.amazonq.broker.events.ChatWebViewAssetState;
import software.aws.toolkits.eclipse.amazonq.chat.ChatCommunicationManager;
import software.aws.toolkits.eclipse.amazonq.chat.ChatTheme;
import software.aws.toolkits.eclipse.amazonq.configuration.PluginStoreKeys;
Expand Down Expand Up @@ -102,7 +103,7 @@ public void completed(final ProgressEvent event) {
}

@Override
public Optional<String> getContent() {
protected Optional<String> getContent() {
Optional<String> content = resolveContent();
Activator.getEventBroker().post(ChatWebViewAssetState.class,
content.isPresent() ? ChatWebViewAssetState.RESOLVED : ChatWebViewAssetState.DEPENDENCY_MISSING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.BrowserFunction;

import software.aws.toolkits.eclipse.amazonq.broker.events.ToolkitLoginWebViewAssetState;
import software.aws.toolkits.eclipse.amazonq.plugin.Activator;
import software.aws.toolkits.eclipse.amazonq.telemetry.UiTelemetryProvider;
import software.aws.toolkits.eclipse.amazonq.util.PluginUtils;
Expand Down Expand Up @@ -60,7 +61,7 @@ public Object function(final Object[] arguments) {
}

@Override
public Optional<String> getContent() {
protected Optional<String> getContent() {
Optional<String> content = resolveContent();
Activator.getEventBroker().post(ToolkitLoginWebViewAssetState.class,
content.isPresent() ? ToolkitLoginWebViewAssetState.RESOLVED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import software.aws.toolkits.eclipse.amazonq.broker.events.BrowserCompatibilityState;
import software.aws.toolkits.eclipse.amazonq.plugin.Activator;
import software.aws.toolkits.eclipse.amazonq.util.PluginPlatform;
import software.aws.toolkits.eclipse.amazonq.util.PluginUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import org.eclipse.lsp4j.services.LanguageServer;

import software.aws.toolkits.eclipse.amazonq.broker.events.AmazonQLspState;
import software.aws.toolkits.eclipse.amazonq.lsp.AmazonQLspServer;
import software.aws.toolkits.eclipse.amazonq.lsp.manager.LspState;
import software.aws.toolkits.eclipse.amazonq.lsp.manager.fetcher.RecordLspSetupArgs;
import software.aws.toolkits.eclipse.amazonq.plugin.Activator;
import software.aws.toolkits.eclipse.amazonq.telemetry.LanguageServerTelemetryProvider;
Expand Down Expand Up @@ -54,7 +54,7 @@ public void setAmazonQServer(final LanguageServer server) {
future.complete(server);
}
emitInitializeMetric();
Activator.getEventBroker().post(LspState.class, LspState.ACTIVE);
Activator.getEventBroker().post(AmazonQLspState.class, AmazonQLspState.ACTIVE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import org.eclipse.ui.part.ViewPart;

import software.aws.toolkits.eclipse.amazonq.broker.api.EventObserver;
import software.aws.toolkits.eclipse.amazonq.broker.events.AmazonQViewType;
import software.aws.toolkits.eclipse.amazonq.plugin.Activator;
import software.aws.toolkits.eclipse.amazonq.views.router.AmazonQViewType;


public final class AmazonQViewContainer extends ViewPart implements EventObserver<AmazonQViewType> {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import software.aws.toolkits.eclipse.amazonq.broker.api.EventObserver;
import software.aws.toolkits.eclipse.amazonq.broker.events.AmazonQViewType;
import software.aws.toolkits.eclipse.amazonq.broker.events.BrowserCompatibilityState;
import software.aws.toolkits.eclipse.amazonq.broker.events.ChatWebViewAssetState;
import software.aws.toolkits.eclipse.amazonq.broker.events.AmazonQLspState;
import software.aws.toolkits.eclipse.amazonq.broker.events.ViewRouterPluginState;
import software.aws.toolkits.eclipse.amazonq.broker.events.ToolkitLoginWebViewAssetState;
import software.aws.toolkits.eclipse.amazonq.lsp.auth.model.AuthState;
import software.aws.toolkits.eclipse.amazonq.lsp.manager.LspState;
import software.aws.toolkits.eclipse.amazonq.plugin.Activator;
import software.aws.toolkits.eclipse.amazonq.providers.assets.ChatWebViewAssetState;
import software.aws.toolkits.eclipse.amazonq.providers.assets.ToolkitLoginWebViewAssetState;
import software.aws.toolkits.eclipse.amazonq.providers.browser.BrowserCompatibilityState;

/**
* Routes to appropriate views based on the plugin's combined state by evaluating conditions in priority order:
Expand All @@ -23,7 +25,7 @@
* Observes changes in all states and automatically updates the active view when any state changes.
* Broadcasts view transitions through the event broker system.
*/
public final class ViewRouter implements EventObserver<PluginState> {
public final class ViewRouter implements EventObserver<ViewRouterPluginState> {

private AmazonQViewType activeView;

Expand All @@ -43,7 +45,7 @@ private ViewRouter(final Builder builder) {
}

if (builder.lspStateObservable == null) {
builder.lspStateObservable = Activator.getEventBroker().ofObservable(LspState.class);
builder.lspStateObservable = Activator.getEventBroker().ofObservable(AmazonQLspState.class);
}

if (builder.browserCompatibilityStateObservable == null) {
Expand All @@ -68,7 +70,7 @@ private ViewRouter(final Builder builder) {
*/
Observable.combineLatest(builder.authStateObservable, builder.lspStateObservable,
builder.browserCompatibilityStateObservable, builder.chatWebViewAssetStateObservable,
builder.toolkitLoginWebViewAssetStateObservable, PluginState::new)
builder.toolkitLoginWebViewAssetStateObservable, ViewRouterPluginState::new)
.observeOn(Schedulers.computation()).subscribe(this::onEvent);
}

Expand All @@ -82,7 +84,7 @@ public static Builder builder() {
* @param pluginState Current combined state of the plugin
*/
@Override
public void onEvent(final PluginState pluginState) {
public void onEvent(final ViewRouterPluginState pluginState) {
refreshActiveView(pluginState);
}

Expand All @@ -98,12 +100,12 @@ public void onEvent(final PluginState pluginState) {
*
* @param pluginState Current combined state of the plugin
*/
private void refreshActiveView(final PluginState pluginState) {
private void refreshActiveView(final ViewRouterPluginState pluginState) {
AmazonQViewType newActiveView;

if (pluginState.browserCompatibilityState() == BrowserCompatibilityState.DEPENDENCY_MISSING) {
newActiveView = AmazonQViewType.DEPENDENCY_MISSING_VIEW;
} else if (pluginState.lspState() == LspState.FAILED) {
} else if (pluginState.lspState() == AmazonQLspState.FAILED) {
newActiveView = AmazonQViewType.LSP_STARTUP_FAILED_VIEW;
} else if (pluginState.chatWebViewAssetState() == ChatWebViewAssetState.DEPENDENCY_MISSING
|| pluginState.toolkitLoginWebViewAssetState() == ToolkitLoginWebViewAssetState.DEPENDENCY_MISSING) {
Expand Down Expand Up @@ -142,7 +144,7 @@ private void notifyActiveViewChange() {
public static final class Builder {

private Observable<AuthState> authStateObservable;
private Observable<LspState> lspStateObservable;
private Observable<AmazonQLspState> lspStateObservable;
private Observable<BrowserCompatibilityState> browserCompatibilityStateObservable;
private Observable<ChatWebViewAssetState> chatWebViewAssetStateObservable;
private Observable<ToolkitLoginWebViewAssetState> toolkitLoginWebViewAssetStateObservable;
Expand All @@ -152,7 +154,7 @@ public Builder withAuthStateObservable(final Observable<AuthState> authStateObse
return this;
}

public Builder withLspStateObservable(final Observable<LspState> lspStateObservable) {
public Builder withLspStateObservable(final Observable<AmazonQLspState> lspStateObservable) {
this.lspStateObservable = lspStateObservable;
return this;
}
Expand Down
Loading

0 comments on commit eeb5664

Please sign in to comment.