Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup dead code in webviews #34

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion plugin/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ bin.includes = plugin.xml,\
icons/,\
target/classes/,\
webview/build/,\
lsp/,\
target/dependency/,\
auth/
jre.compilation.profile = JavaSE-17
Binary file removed plugin/lsp/token-standalone-macos
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,9 @@

package software.aws.toolkits.eclipse.amazonq.views;

import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.BrowserFunction;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.dialogs.PreferencesUtil;

import jakarta.inject.Inject;
import software.aws.toolkits.eclipse.amazonq.lsp.manager.LspConstants;
import software.aws.toolkits.eclipse.amazonq.util.AuthUtils;
import software.aws.toolkits.eclipse.amazonq.util.PluginLogger;
Expand All @@ -26,9 +17,6 @@ public class AmazonQChatWebview extends AmazonQView {

public static final String ID = "software.aws.toolkits.eclipse.amazonq.views.AmazonQChatWebview";

@Inject
private Shell shell;
private Browser browser;
private AmazonQCommonActions amazonQCommonActions;

private final ViewCommandParser commandParser;
Expand All @@ -42,16 +30,13 @@ public AmazonQChatWebview() {
@Override
public final void createPartControl(final Composite parent) {
setupAmazonQView(parent, true);
browser = getBrowser();
var browser = getBrowser();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the variable type be Browser instead of var?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type inference is supported as of Java 10+ - another thing I would like to do consistently and add a check for if possible.

amazonQCommonActions = getAmazonQCommonActions();

AuthUtils.isLoggedIn().thenAcceptAsync(isLoggedIn -> {
handleAuthStatusChange(isLoggedIn);
}, ThreadingUtils::executeAsyncTask);

BrowserFunction prefsFunction = new OpenPreferenceFunction(browser, "openEclipsePreferences", this::openPreferences);
browser.addDisposeListener(e -> prefsFunction.dispose());

new BrowserFunction(browser, "ideCommand") {
@Override
public Object function(final Object[] arguments) {
Expand All @@ -68,26 +53,6 @@ public Object function(final Object[] arguments) {
};
}

private class OpenPreferenceFunction extends BrowserFunction {
private Runnable function;

OpenPreferenceFunction(final Browser browser, final String name, final Runnable function) {
super(browser, name);
this.function = function;
}

@Override
public Object function(final Object[] arguments) {
function.run();
return getName() + " executed!";
}
}

private void openPreferences() {
PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(shell, null, null, null);
dialog.open();
}

private String getContent() {
String jsFile = PluginUtils.getAwsDirectory(LspConstants.LSP_SUBDIRECTORY).resolve("amazonq-ui.js").toString();
return String.format("<!DOCTYPE html>\n"
Expand Down Expand Up @@ -135,21 +100,9 @@ private String generateJS(final String jsEntrypoint) {
+ " </script>", jsEntrypoint);
}

@Override
public final void selectionChanged(final IWorkbenchPart part, final ISelection selection) {
if (selection.isEmpty()) {
return;
}
if (selection instanceof IStructuredSelection) {
browser.execute("setSelection(\"" + part.getTitle() + "::"
+ ((IStructuredSelection) selection).getFirstElement().getClass().getSimpleName() + "\");");
} else {
browser.execute("setSelection(\"Something was selected in part " + part.getTitle() + "\");");
}
}

@Override
protected final void handleAuthStatusChange(final boolean isLoggedIn) {
var browser = getBrowser();
Display.getDefault().asyncExec(() -> {
amazonQCommonActions.updateActionVisibility(isLoggedIn, getViewSite());
if (!isLoggedIn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

package software.aws.toolkits.eclipse.amazonq.views;


import java.util.Set;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
Expand All @@ -21,7 +19,7 @@
import software.aws.toolkits.eclipse.amazonq.util.PluginLogger;
import software.aws.toolkits.eclipse.amazonq.views.actions.AmazonQCommonActions;

public abstract class AmazonQView extends ViewPart implements ISelectionListener {
public abstract class AmazonQView extends ViewPart {

private static final Set<String> AMAZON_Q_VIEWS = Set.of(
ToolkitLoginWebview.ID,
Expand Down Expand Up @@ -77,7 +75,6 @@ protected final void setupAmazonQView(final Composite parent, final boolean isLo
setupBrowser(parent);
setupActions(browser, isLoggedIn);
setupAuthStatusListeners();
setupSelectionListener();
}

private void setupBrowser(final Composite parent) {
Expand All @@ -99,10 +96,6 @@ private void setupAuthStatusListeners() {
AuthUtils.addAuthStatusChangeListener(amazonQCommonActions.getFeedbackDialogContributionAction());
}

private void setupSelectionListener() {
getSite().getPage().addSelectionListener(this);
}

@Override
public final void setFocus() {
browser.setFocus();
Expand All @@ -117,7 +110,6 @@ public final void setFocus() {
@Override
public void dispose() {
AuthUtils.removeAuthStatusChangeListener(authStatusChangedListener);
getSite().getPage().removeSelectionListener(this);
super.dispose();
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,9 @@
import java.io.IOException;
import java.net.URL;

import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.BrowserFunction;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.dialogs.PreferencesUtil;

import jakarta.inject.Inject;
import software.aws.toolkits.eclipse.amazonq.util.AuthUtils;
import software.aws.toolkits.eclipse.amazonq.util.PluginUtils;
import software.aws.toolkits.eclipse.amazonq.util.ThreadingUtils;
Expand All @@ -27,9 +18,6 @@ public final class ToolkitLoginWebview extends AmazonQView {

public static final String ID = "software.aws.toolkits.eclipse.amazonq.views.ToolkitLoginWebview";

@Inject
private Shell shell;
private Browser browser;
private AmazonQCommonActions amazonQCommonActions;

private final ViewCommandParser commandParser;
Expand All @@ -43,17 +31,13 @@ public ToolkitLoginWebview() {
@Override
public void createPartControl(final Composite parent) {
setupAmazonQView(parent, true);
browser = getBrowser();
var browser = getBrowser();
amazonQCommonActions = getAmazonQCommonActions();

AuthUtils.isLoggedIn().thenAcceptAsync(isLoggedIn -> {
handleAuthStatusChange(isLoggedIn);
}, ThreadingUtils::executeAsyncTask);

BrowserFunction prefsFunction = new OpenPreferenceFunction(browser, "openEclipsePreferences", this::openPreferences);
browser.addDisposeListener(e -> prefsFunction.dispose());


new BrowserFunction(browser, ViewConstants.COMMAND_FUNCTION_NAME) {
@Override
public Object function(final Object[] arguments) {
Expand All @@ -65,6 +49,7 @@ public Object function(final Object[] arguments) {
}

protected void handleAuthStatusChange(final boolean isLoggedIn) {
var browser = getBrowser();
Display.getDefault().asyncExec(() -> {
amazonQCommonActions.updateActionVisibility(isLoggedIn, getViewSite());
if (!isLoggedIn) {
Expand All @@ -76,27 +61,6 @@ protected void handleAuthStatusChange(final boolean isLoggedIn) {
});
}


private class OpenPreferenceFunction extends BrowserFunction {
private Runnable function;

OpenPreferenceFunction(final Browser browser, final String name, final Runnable function) {
super(browser, name);
this.function = function;
}

@Override
public Object function(final Object[] arguments) {
function.run();
return getName() + " executed!";
}
}

private void openPreferences() {
PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(shell, null, null, null);
dialog.open();
}

private String getContent() {
try {
URL jsFile = PluginUtils.getResource("webview/build/assets/js/getStart.js");
Expand Down Expand Up @@ -125,16 +89,4 @@ private String getContent() {
}
}

@Override
public void selectionChanged(final IWorkbenchPart part, final ISelection selection) {
if (selection.isEmpty()) {
return;
}
if (selection instanceof IStructuredSelection) {
browser.execute("setSelection(\"" + part.getTitle() + "::"
+ ((IStructuredSelection) selection).getFirstElement().getClass().getSimpleName() + "\");");
} else {
browser.execute("setSelection(\"Something was selected in part " + part.getTitle() + "\");");
}
}
}