Skip to content

Commit

Permalink
Merge branch 'main' into prevent-undo-from-querying
Browse files Browse the repository at this point in the history
  • Loading branch information
dingfeli authored Nov 21, 2024
2 parents 7e141c1 + 028e27b commit 1864fab
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 71 deletions.
42 changes: 21 additions & 21 deletions plugin/codegen-resources/definitions/commonDefinitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6223,26 +6223,6 @@
}
]
},
{
"name": "eclipse_executeCommand",
"description": "Emitted whenever a registered Eclipse command is executed",
"passive": true,
"metadata": [
{
"type": "command"
},
{
"type": "duration"
},
{
"type": "result"
},
{
"type": "reason",
"required": false
}
]
},
{
"name": "rds_createConnectionConfiguration",
"description": "Called when creating a new database connection configuration to for a RDS database. In Datagrip we do not get this infromation if it is created directly, so this is only counts actions.",
Expand Down Expand Up @@ -6968,6 +6948,26 @@
],
"passive": true
},
{
"name": "toolkit_execute",
"description": "Emitted whenever a registered command is executed",
"passive": true,
"metadata": [
{
"type": "command"
},
{
"type": "duration"
},
{
"type": "result"
},
{
"type": "reason",
"required": false
}
]
},
{
"name": "toolkit_featureState",
"description": "Represents the current enabled state of a feature. Used to track user journey through a feature. Emitted after feature-specific operations of interest in the Toolkit.",
Expand Down Expand Up @@ -7221,4 +7221,4 @@
]
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import software.aws.toolkits.eclipse.amazonq.chat.models.SendToPromptParams;
import software.aws.toolkits.eclipse.amazonq.chat.models.TriggerType;
import software.aws.toolkits.eclipse.amazonq.plugin.Activator;
import software.aws.toolkits.eclipse.amazonq.telemetry.EclipseTelemetryProvider;
import software.aws.toolkits.eclipse.amazonq.telemetry.ToolkitTelemetryProvider;
import software.aws.toolkits.eclipse.amazonq.util.QEclipseEditorUtils;
import software.aws.toolkits.eclipse.amazonq.views.ViewVisibilityManager;
import software.aws.toolkits.telemetry.TelemetryDefinitions.Result;
Expand All @@ -39,7 +39,7 @@ protected final void executeGenericCommand(final String genericCommandVerb) {
getSelectedText().ifPresentOrElse(
selection -> {
sendGenericCommand(selection, genericCommandVerb);
emitExecuteCommand(genericCommandVerb, start, Result.SUCCEEDED, "");
emitExecuteCommand(genericCommandVerb, start, Result.SUCCEEDED, null);
},
() -> {
Activator.getLogger().info("No text was retrieved when fetching selected text");
Expand All @@ -59,7 +59,7 @@ protected final void executeSendToPromptCommand() {
getSelectedText().ifPresentOrElse(
selection -> {
sendToPromptCommand(selection);
emitExecuteCommand("sendToPrompt", start, Result.SUCCEEDED, "");
emitExecuteCommand("sendToPrompt", start, Result.SUCCEEDED, null);
},
() -> {
Activator.getLogger().info("No text was retrieved when fetching selected text");
Expand Down Expand Up @@ -112,8 +112,8 @@ public void run() {
}
private void emitExecuteCommand(final String command, final Instant start, final Result result, final String reason) {
double duration = Duration.between(start, Instant.now()).toMillis();
var params = new EclipseTelemetryProvider.Params(command, duration, result, reason);
EclipseTelemetryProvider.emitExecuteCommandMetric(params);
var params = new ToolkitTelemetryProvider.ExecuteParams(command, duration, result, reason);
ToolkitTelemetryProvider.emitExecuteCommandMetric(params);
return;
}
}
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ private ToolkitTelemetryProvider() {
//prevent instantiation
}

public static void emitExecuteCommandMetric(final ExecuteParams params) {
var metadata = ToolkitTelemetry.ExecuteEvent()
.command(params.command())
.duration(params.duration())
.result(params.result())
.reason(params.reason())
.passive(false)
.createTime(Instant.now())
.value(1.0)
.build();
Activator.getTelemetryService().emitMetric(metadata);
}

public static void emitOpenModuleEventMetric(final String module, final String source, final String failureReason) {
Result result = Result.SUCCEEDED;
boolean isPassive = (!source.equals("ellipsesMenu") && !source.equals("statusBar") && !source.equals("shortcut"));
Expand Down Expand Up @@ -57,5 +70,5 @@ private static String mapModuleId(final String viewId) {
return page;
}
}

public record ExecuteParams(String command, double duration, Result result, String reason) { };
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ public void beforeRemoval() {
currentOffset);
int lineNumber = doc.getLineOfOffset(expandedCurrentOffset);
int startLineOffset = doc.getLineOffset(lineNumber);
int invocationOffset = session.getInvocationOffset();
int curLineInDoc = widget.getLineAtOffset(invocationOffset);
int curLineInDoc = widget.getLineAtOffset(currentOffset);
int lineIdx = expandedCurrentOffset - startLineOffset;
String contentInLine = widget.getLine(curLineInDoc) + widget.getLineDelimiter();
String currentRightCtx = "\n";
Expand Down Expand Up @@ -323,9 +322,13 @@ public void documentChanged(final DocumentEvent event) {
boolean isOutOfBounds = distanceTraversed + input.length() >= currentSuggestion.length()
|| distanceTraversed < 0;
if (isOutOfBounds || !isInputAMatch(currentSuggestion, distanceTraversed, input)) {
distanceTraversed++;
session.transitionToDecisionMade();
distanceTraversed += input.length();
event.getDocument().removeDocumentListener(this);
StyledText widget = session.getViewer().getTextWidget();
int caretLine = widget.getLineAtOffset(widget.getCaretOffset());
int linesOfInput = input.split(widget.getLineDelimiter()).length;
int lineToUnsetIndent = caretLine + linesOfInput;
session.transitionToDecisionMade(lineToUnsetIndent);
Display.getCurrent().asyncExec(() -> {
if (session.isActive()) {
session.end();
Expand Down

0 comments on commit 1864fab

Please sign in to comment.