Skip to content

Commit

Permalink
Add configuration for showing code references (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
breedloj authored Nov 21, 2024
1 parent ef66134 commit 028e27b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import software.amazon.awssdk.services.toolkittelemetry.model.Sentiment;
import software.aws.toolkits.eclipse.amazonq.chat.ChatCommunicationManager;
import software.aws.toolkits.eclipse.amazonq.lsp.auth.model.AuthState;
import software.aws.toolkits.eclipse.amazonq.lsp.auth.model.LoginType;
import software.aws.toolkits.eclipse.amazonq.lsp.auth.model.SsoTokenChangedKind;
import software.aws.toolkits.eclipse.amazonq.lsp.auth.model.SsoTokenChangedParams;
import software.aws.toolkits.eclipse.amazonq.lsp.model.ConnectionMetadata;
Expand Down Expand Up @@ -75,7 +76,10 @@ public final CompletableFuture<List<Object>> configuration(final ConfigurationPa
} else if (item.getSection().equals(Constants.LSP_CW_CONFIGURATION_KEY)) {
Map<String, Boolean> cwConfig = new HashMap<>();
boolean shareContentSetting = Activator.getDefault().getPreferenceStore().getBoolean(AmazonQPreferencePage.Q_DATA_SHARING);
boolean referencesEnabled = Activator.getDefault().getPreferenceStore().getBoolean(AmazonQPreferencePage.CODE_REFERENCE_OPT_IN)
&& Activator.getLoginService().getAuthState().loginType().equals(LoginType.BUILDER_ID);
cwConfig.put(Constants.LSP_CW_OPT_OUT_KEY, shareContentSetting);
cwConfig.put(Constants.LSP_CODE_REFERENCES_OPT_OUT_KEY, referencesEnabled);
output.add(cwConfig);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


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.lsp.auth.model.AuthState;
import software.aws.toolkits.eclipse.amazonq.lsp.auth.model.InvalidateSsoTokenParams;
Expand All @@ -18,6 +19,7 @@
import software.aws.toolkits.eclipse.amazonq.lsp.encryption.LspEncryptionManager;
import software.aws.toolkits.eclipse.amazonq.providers.LspProvider;
import software.aws.toolkits.eclipse.amazonq.util.AuthUtil;
import software.aws.toolkits.eclipse.amazonq.util.ThreadingUtils;
import software.aws.toolkits.eclipse.amazonq.plugin.Activator;

/**
Expand Down Expand Up @@ -165,6 +167,7 @@ CompletableFuture<Void> processLogin(final LoginType loginType, final LoginParam
.thenRun(() -> {
authStateManager.toLoggedIn(loginType, loginParams, ssoTokenId.get());
Activator.getLogger().info("Successfully logged in");
ThreadingUtils.executeAsyncTask(() -> CustomizationUtil.triggerChangeConfigurationNotification());
})
.exceptionally(throwable -> {
throw new AmazonQPluginException("Failed to process log in", throwable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class AmazonQPreferenceInitializer extends AbstractPreferenceInitializer
@Override
public final void initializeDefaultPreferences() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
store.setDefault(AmazonQPreferencePage.CODE_REFERENCE_OPT_IN, true);
store.setDefault(AmazonQPreferencePage.TELEMETRY_OPT_IN, true);
store.setDefault(AmazonQPreferencePage.Q_DATA_SHARING, true);
store.addPropertyChangeListener(event -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

import software.aws.toolkits.eclipse.amazonq.lsp.auth.model.LoginType;
import software.aws.toolkits.eclipse.amazonq.lsp.model.GetConfigurationFromServerParams;
import software.aws.toolkits.eclipse.amazonq.plugin.Activator;
import software.aws.toolkits.eclipse.amazonq.telemetry.AwsTelemetryProvider;
Expand All @@ -26,7 +27,8 @@

public class AmazonQPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
public static final String PREFERENCE_STORE_ID = "software.aws.toolkits.eclipse.preferences";
public static final String TELEMETRY_OPT_IN = "telemtryOptIn";
public static final String CODE_REFERENCE_OPT_IN = "codeReferenceOptIn";
public static final String TELEMETRY_OPT_IN = "telemetryOptIn";
public static final String Q_DATA_SHARING = "qDataSharing";

private boolean isTelemetryOptInChecked;
Expand All @@ -49,7 +51,9 @@ public final void init(final IWorkbench workbench) {
@Override
protected final void createFieldEditors() {
createHorizontalSeparator();
createDataSharingLabel();
createHeading("Inline Suggestions");
createCodeReferenceOptInField();
createHeading("Data Sharing");
createTelemetryOptInField();
createHorizontalSeparator();
createQDataSharingField();
Expand All @@ -64,14 +68,44 @@ private void createHorizontalSeparator() {
new Label(getFieldEditorParent(), SWT.HORIZONTAL);
}

private void createDataSharingLabel() {
private void createHeading(final String text) {
Label dataSharing = new Label(getFieldEditorParent(), SWT.NONE);
dataSharing.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.HEADER_FONT));
dataSharing.setText("Data Sharing");
dataSharing.setText(text);
dataSharing.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
new Label(getFieldEditorParent(), SWT.HORIZONTAL | SWT.SEPARATOR).setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
}

private void createCodeReferenceOptInField() {
Composite codeReferenceOptInComposite = new Composite(getFieldEditorParent(), SWT.NONE);
codeReferenceOptInComposite.setLayout(new GridLayout(2, false));
GridData telemetryOptInCompositeData = new GridData(SWT.FILL, SWT.CENTER, true, false);
telemetryOptInCompositeData.horizontalIndent = 20;
codeReferenceOptInComposite.setLayoutData(telemetryOptInCompositeData);

BooleanFieldEditor codeReferenceOptIn = new BooleanFieldEditor(CODE_REFERENCE_OPT_IN,
"Show inline code suggestions with code references", codeReferenceOptInComposite);
addField(codeReferenceOptIn);

if (Activator.getLoginService().getAuthState().loginType().equals(LoginType.IAM_IDENTITY_CENTER)) {
codeReferenceOptIn.setEnabled(false, codeReferenceOptInComposite);
}

Link codeReferenceLink = createLink("""
Amazon Q creates a code reference when you insert a code suggestion from Amazon Q that is similar to training data.\
\nWhen unchecked, Amazon Q will not show code suggestions that have code references. If you authenticate through IAM\
\nIdentity Center, this setting is controlled by your Amazon Q administrator. \
\n<a href=\"https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/code-reference.html\">Learn more</a>
""", 20, codeReferenceOptInComposite);
codeReferenceLink.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent event) {
UiTelemetryProvider.emitClickEventMetric("preferences_codeReferences");
PluginUtils.openWebpage(event.text);
}
});
}

private void createTelemetryOptInField() {
Composite telemetryOptInComposite = new Composite(getFieldEditorParent(), SWT.NONE);
telemetryOptInComposite.setLayout(new GridLayout(2, false));
Expand Down Expand Up @@ -104,10 +138,10 @@ private void createQDataSharingField() {
addField(qDataSharing);

Link dataSharingLink = createLink("""
When checked, your content processed by Amazon Q may be used for service improvement (except for content processed by the \
Amazon Q Developer Pro tier).\nUnchecking this box will cause AWS to delete any of your content used for that purpose. The \
information used to provide the Amazon Q service to you will not be affected.\nSee the \
<a href="https://aws.amazon.com/service-terms/">Service Terms</a> for more detail.
When checked, your content processed by Amazon Q may be used for service improvement (except for content processed\
\nby the Amazon Q Developer Pro tier). Unchecking this box will cause AWS to delete any of your content used for that\
\npurpose. The information used to provide the Amazon Q service to you will not be affected.\
\nSee the <a href="https://aws.amazon.com/service-terms/">Service Terms</a> for more detail.
""", 20, qDataSharingComposite);
dataSharingLink.addSelectionListener(new SelectionAdapter() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ private Constants() {
public static final String LSP_Q_CONFIGURATION_KEY = "aws.q";
public static final String LSP_CW_CONFIGURATION_KEY = "aws.codeWhisperer";
public static final String LSP_CW_OPT_OUT_KEY = "shareCodeWhispererContentWithAWS";
public static final String LSP_CODE_REFERENCES_OPT_OUT_KEY = "includeSuggestionsWithCodeReferences";
public static final String IDE_CUSTOMIZATION_NOTIFICATION_TITLE = "Amazon Q Customization";
public static final String IDE_CUSTOMIZATION_NOTIFICATION_BODY_TEMPLATE = "Amazon Q inline suggestions are now coming from the %s";
public static final String DEFAULT_Q_FOUNDATION_DISPLAY_NAME = "Amazon Q foundation (Default)";
Expand Down

0 comments on commit 028e27b

Please sign in to comment.