From c870ba977b099b19a607bc5b92be2d055d5310a4 Mon Sep 17 00:00:00 2001 From: Jonathan Breedlove Date: Thu, 21 Nov 2024 11:15:17 -0800 Subject: [PATCH] Add configuration for showing code references --- .../amazonq/lsp/AmazonQLspClientImpl.java | 4 ++ .../amazonq/lsp/auth/DefaultLoginService.java | 3 ++ .../AmazonQPreferenceInitializer.java | 1 + .../preferences/AmazonQPreferencePage.java | 45 +++++++++++++++---- .../eclipse/amazonq/util/Constants.java | 1 + 5 files changed, 46 insertions(+), 8 deletions(-) diff --git a/plugin/src/software/aws/toolkits/eclipse/amazonq/lsp/AmazonQLspClientImpl.java b/plugin/src/software/aws/toolkits/eclipse/amazonq/lsp/AmazonQLspClientImpl.java index 6bca6ee90..183d131b3 100644 --- a/plugin/src/software/aws/toolkits/eclipse/amazonq/lsp/AmazonQLspClientImpl.java +++ b/plugin/src/software/aws/toolkits/eclipse/amazonq/lsp/AmazonQLspClientImpl.java @@ -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; @@ -75,7 +76,10 @@ public final CompletableFuture> configuration(final ConfigurationPa } else if (item.getSection().equals(Constants.LSP_CW_CONFIGURATION_KEY)) { Map 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); } }); diff --git a/plugin/src/software/aws/toolkits/eclipse/amazonq/lsp/auth/DefaultLoginService.java b/plugin/src/software/aws/toolkits/eclipse/amazonq/lsp/auth/DefaultLoginService.java index d0b5b728c..52f78b277 100644 --- a/plugin/src/software/aws/toolkits/eclipse/amazonq/lsp/auth/DefaultLoginService.java +++ b/plugin/src/software/aws/toolkits/eclipse/amazonq/lsp/auth/DefaultLoginService.java @@ -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; @@ -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; /** @@ -165,6 +167,7 @@ CompletableFuture 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); diff --git a/plugin/src/software/aws/toolkits/eclipse/amazonq/preferences/AmazonQPreferenceInitializer.java b/plugin/src/software/aws/toolkits/eclipse/amazonq/preferences/AmazonQPreferenceInitializer.java index f5bdb1dc9..00aed9f5a 100644 --- a/plugin/src/software/aws/toolkits/eclipse/amazonq/preferences/AmazonQPreferenceInitializer.java +++ b/plugin/src/software/aws/toolkits/eclipse/amazonq/preferences/AmazonQPreferenceInitializer.java @@ -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 -> { diff --git a/plugin/src/software/aws/toolkits/eclipse/amazonq/preferences/AmazonQPreferencePage.java b/plugin/src/software/aws/toolkits/eclipse/amazonq/preferences/AmazonQPreferencePage.java index 97caaf710..333c04dd3 100644 --- a/plugin/src/software/aws/toolkits/eclipse/amazonq/preferences/AmazonQPreferencePage.java +++ b/plugin/src/software/aws/toolkits/eclipse/amazonq/preferences/AmazonQPreferencePage.java @@ -26,7 +26,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; @@ -49,7 +50,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(); @@ -64,14 +67,40 @@ 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); + + 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. \ + \nLearn more + """, 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)); @@ -104,10 +133,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 \ - Service Terms 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 Service Terms for more detail. """, 20, qDataSharingComposite); dataSharingLink.addSelectionListener(new SelectionAdapter() { @Override diff --git a/plugin/src/software/aws/toolkits/eclipse/amazonq/util/Constants.java b/plugin/src/software/aws/toolkits/eclipse/amazonq/util/Constants.java index 08a97250f..ebe0b9052 100644 --- a/plugin/src/software/aws/toolkits/eclipse/amazonq/util/Constants.java +++ b/plugin/src/software/aws/toolkits/eclipse/amazonq/util/Constants.java @@ -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)";