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

Fetch customizations from LSP server #43

Merged
merged 5 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@

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

import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

import org.eclipse.lsp4j.DidChangeConfigurationParams;

import software.amazon.awssdk.utils.StringUtils;
import software.aws.toolkits.eclipse.amazonq.exception.AmazonQPluginException;
import software.aws.toolkits.eclipse.amazonq.lsp.model.GetConfigurationFromServerParams;
import software.aws.toolkits.eclipse.amazonq.providers.LspProvider;
import software.aws.toolkits.eclipse.amazonq.util.PluginLogger;
import software.aws.toolkits.eclipse.amazonq.views.model.Customization;

public final class CustomizationUtil {

Expand All @@ -26,4 +34,17 @@ public static void triggerChangeConfigurationNotification(final Map<String, Obje
}
}

public static CompletableFuture<List<Customization>> listCustomizations() {
GetConfigurationFromServerParams params = new GetConfigurationFromServerParams();
params.setSection("aws.q");
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry not too familiar with the params yet. Where are these sections defined? I don't see them in the high level manifests / plugin.xml.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see.

return LspProvider.getAmazonQServer()
.thenCompose(server -> server.getConfigurationFromServer(params))
.thenApply(customizations -> customizations.stream()
.filter(customization -> customization != null && StringUtils.isNotBlank(customization.getName()))
.collect(Collectors.toList()))
.exceptionally(throwable -> {
PluginLogger.error("Error occurred while fetching the list of customizations", throwable);
throw new AmazonQPluginException(throwable);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

import java.util.List;
import java.util.concurrent.CompletableFuture;

import org.eclipse.lsp4j.jsonrpc.messages.ResponseMessage;
Expand All @@ -12,9 +13,11 @@
import software.aws.toolkits.eclipse.amazonq.chat.models.ChatRequestParams;
import software.aws.toolkits.eclipse.amazonq.chat.models.ChatResult;
import software.aws.toolkits.eclipse.amazonq.chat.models.GenericTabParams;
import software.aws.toolkits.eclipse.amazonq.lsp.model.GetConfigurationFromServerParams;
import software.aws.toolkits.eclipse.amazonq.lsp.model.InlineCompletionParams;
import software.aws.toolkits.eclipse.amazonq.lsp.model.InlineCompletionResponse;
import software.aws.toolkits.eclipse.amazonq.lsp.model.UpdateCredentialsPayload;
import software.aws.toolkits.eclipse.amazonq.views.model.Customization;

public interface AmazonQLspServer extends LanguageServer {

Expand All @@ -33,4 +36,6 @@ public interface AmazonQLspServer extends LanguageServer {
@JsonRequest("aws/credentials/token/update")
CompletableFuture<ResponseMessage> updateTokenCredentials(UpdateCredentialsPayload payload);

@JsonRequest("aws/getConfigurationFromServer")
CompletableFuture<List<Customization>> getConfigurationFromServer(GetConfigurationFromServerParams params);
}
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.lsp.model;

public class GetConfigurationFromServerParams {
private String section;

public final String getSection() {
return this.section;
}

public final void setSection(final String section) {
this.section = section;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ 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(Constants.CUSTOMIZATION_STORAGE_INTERNAL_KEY);
} else {
} else if (this.selectedCustomisationArn != null) {
PluginStore.put(Constants.CUSTOMIZATION_STORAGE_INTERNAL_KEY, this.selectedCustomisationArn);
Map<String, Object> updatedSettings = new HashMap<>();
Map<String, String> internalMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;

import org.eclipse.jface.action.ContributionItem;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
Expand All @@ -17,8 +19,11 @@
import jakarta.inject.Inject;
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.exception.AmazonQPluginException;
import software.aws.toolkits.eclipse.amazonq.util.AuthStatusChangedListener;
import software.aws.toolkits.eclipse.amazonq.util.Constants;
import software.aws.toolkits.eclipse.amazonq.util.PluginLogger;
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 @@ -50,9 +55,12 @@ public void onAuthStatusChanged(final boolean isLoggedIn) {

private List<Customization> getCustomizations() {
List<Customization> customizations = new ArrayList<>();
customizations.add(new Customization("customization-arn-1", "Customization 1", "Code Whisperer customization 1"));
customizations.add(new Customization("customization-arn-2", "Customization 2", "Code Whisperer customization 2"));
customizations.add(new Customization("customization-arn-3", "Customization 3", "Code Whisperer customization 3"));
try {
customizations = CustomizationUtil.listCustomizations().get();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any way to make this populate asynchronously? This would block the UI thread, no?

Copy link
Contributor Author

@pras0131 pras0131 Oct 4, 2024

Choose a reason for hiding this comment

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

nice catch! I updated the code to fetch the customizations async and not block the UI thread to open the dialog.

} catch (InterruptedException | ExecutionException e) {
PluginLogger.error("Error occurred in getCustomizations", e);
throw new AmazonQPluginException(e);
}
return customizations;
}

Expand All @@ -64,7 +72,6 @@ public void fill(final Menu menu, final int index) {
@Override
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());
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: customisation -> customization. keep it consistent

String storedCustomizationArn = PluginStore.get(Constants.CUSTOMIZATION_STORAGE_INTERNAL_KEY);
if (StringUtils.isBlank(storedCustomizationArn)) {
Expand Down