Skip to content

Commit

Permalink
Merge branch 'main' into breedloj/telemetryTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
breedloj authored Oct 1, 2024
2 parents 31e2f72 + 5023db0 commit d1c9849
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

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

import java.util.Map;
import org.eclipse.lsp4j.DidChangeConfigurationParams;
import software.aws.toolkits.eclipse.amazonq.exception.AmazonQPluginException;
import software.aws.toolkits.eclipse.amazonq.providers.LspProvider;
import software.aws.toolkits.eclipse.amazonq.util.PluginLogger;

public final class CustomizationUtil {

private CustomizationUtil() {
// to avoid initiation
}

public static void triggerChangeConfigurationNotification(final Map<String, Object> settings) {
try {
PluginLogger.info("Sending configuration update notification to Amazon Q LSP server");
LspProvider.getAmazonQServer()
.thenAccept(server -> server.getWorkspaceService().didChangeConfiguration(new DidChangeConfigurationParams(settings)));
} catch (Exception e) {
PluginLogger.error("Error occurred while sending change configuration notification to Amazon Q LSP server", e);
throw new AmazonQPluginException(e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@

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

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

import org.eclipse.lsp4e.LanguageClientImpl;
import org.eclipse.lsp4j.ConfigurationParams;

import software.aws.toolkits.eclipse.amazonq.configuration.PluginStore;
import software.aws.toolkits.eclipse.amazonq.lsp.model.ConnectionMetadata;
import software.aws.toolkits.eclipse.amazonq.lsp.model.SsoProfileData;
import software.aws.toolkits.eclipse.amazonq.util.Constants;

@SuppressWarnings("restriction")
public class AmazonQLspClientImpl extends LanguageClientImpl implements AmazonQLspClient {
Expand All @@ -23,4 +30,23 @@ public final CompletableFuture<ConnectionMetadata> getConnectionMetadata() {
return CompletableFuture.completedFuture(metadata);
}

@Override
public final CompletableFuture<List<Object>> configuration(final ConfigurationParams configurationParams) {
if (configurationParams.getItems().size() == 0) {
return CompletableFuture.completedFuture(null);
}
List<Object> output = new ArrayList<>();
configurationParams.getItems().forEach(item -> {
if (item.getSection().equals(Constants.LSP_CONFIGURATION_KEY)) {
String customizationArn = PluginStore.get(Constants.CUSTOMIZATION_STORAGE_INTERNAL_KEY);
Map<String, String> customization = new HashMap<>();
customization.put(Constants.LSP_CUSTOMIZATION_CONFIGURATION_KEY, customizationArn);
output.add(customization);
} else {
output.add(null);
}
});
return CompletableFuture.completedFuture(output);
}

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

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

public final class Constants {

private Constants() {
// to avoid initiation
}

public static final String CUSTOMIZATION_STORAGE_INTERNAL_KEY = "aws.q.customization.eclipse";
public static final String LSP_CUSTOMIZATION_CONFIGURATION_KEY = "customization";
public static final String LSP_CONFIGURATION_KEY = "aws.q";

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

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

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
Expand All @@ -22,13 +24,15 @@
import org.eclipse.swt.widgets.Shell;
import software.amazon.awssdk.utils.StringUtils;
import software.aws.toolkits.eclipse.amazonq.configuration.PluginStore;
import software.aws.toolkits.eclipse.amazonq.customization.CustomizationUtil;
import software.aws.toolkits.eclipse.amazonq.util.Constants;
import software.aws.toolkits.eclipse.amazonq.util.PluginLogger;
import software.aws.toolkits.eclipse.amazonq.util.ThreadingUtils;
import software.aws.toolkits.eclipse.amazonq.views.model.Customization;

public final class CustomizationDialog extends Dialog {

private static final String TITLE = "Amazon Q Customization";
public static final String CUSTOMIZATION_STORAGE_INTERNAL_KEY = "aws.q.customization.eclipse";
private Composite container;
private Combo combo;
private Font magnifiedFont;
Expand Down Expand Up @@ -110,10 +114,14 @@ protected void createButtonsForButtonBar(final Composite parent) {
protected void okPressed() {
PluginLogger.info(String.format("Select pressed with responseSelection:%s and selectedArn:%s", this.responseSelection, this.selectedCustomisationArn));
if (this.responseSelection.equals(ResponseSelection.AMAZON_Q_FOUNDATION_DEFAULT)) {
PluginStore.remove(CUSTOMIZATION_STORAGE_INTERNAL_KEY);
PluginStore.remove(Constants.CUSTOMIZATION_STORAGE_INTERNAL_KEY);
} else {
// TODO: Add the logic to trigger notification to LSP server regarding change of configuration
PluginStore.put(CUSTOMIZATION_STORAGE_INTERNAL_KEY, this.selectedCustomisationArn);
PluginStore.put(Constants.CUSTOMIZATION_STORAGE_INTERNAL_KEY, this.selectedCustomisationArn);
Map<String, Object> updatedSettings = new HashMap<>();
Map<String, String> internalMap = new HashMap<>();
internalMap.put(Constants.LSP_CUSTOMIZATION_CONFIGURATION_KEY, this.selectedCustomisationArn);
updatedSettings.put(Constants.LSP_CONFIGURATION_KEY, internalMap);
ThreadingUtils.executeAsyncTask(() -> CustomizationUtil.triggerChangeConfigurationNotification(updatedSettings));
}
super.okPressed();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import software.amazon.awssdk.utils.StringUtils;
import software.aws.toolkits.eclipse.amazonq.configuration.PluginStore;
import software.aws.toolkits.eclipse.amazonq.util.AuthStatusChangedListener;
import software.aws.toolkits.eclipse.amazonq.util.Constants;
import software.aws.toolkits.eclipse.amazonq.views.CustomizationDialog;
import software.aws.toolkits.eclipse.amazonq.views.CustomizationDialog.ResponseSelection;
import software.aws.toolkits.eclipse.amazonq.views.model.Customization;
Expand Down Expand Up @@ -65,7 +66,7 @@ public void widgetSelected(final SelectionEvent e) {
CustomizationDialog dialog = new CustomizationDialog(shell);
// TODO: This mock will be replaced by an actual call to LSP
dialog.setCustomisationResponse(getCustomizations());
String storedCustomizationArn = PluginStore.get(CustomizationDialog.CUSTOMIZATION_STORAGE_INTERNAL_KEY);
String storedCustomizationArn = PluginStore.get(Constants.CUSTOMIZATION_STORAGE_INTERNAL_KEY);
if (StringUtils.isBlank(storedCustomizationArn)) {
dialog.setResponseSelection(ResponseSelection.AMAZON_Q_FOUNDATION_DEFAULT);
dialog.setSelectedCustomizationArn(null);
Expand Down

0 comments on commit d1c9849

Please sign in to comment.