diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/service/CodeWhispererService.kt b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/service/CodeWhispererService.kt index faad851920d..1ef7b51f9b1 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/service/CodeWhispererService.kt +++ b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/service/CodeWhispererService.kt @@ -21,6 +21,7 @@ import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiFile import com.intellij.util.concurrency.annotations.RequiresEdt import com.intellij.util.messages.Topic +import io.ktor.client.request.request import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Deferred import kotlinx.coroutines.Job @@ -232,7 +233,8 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable { buildCodeWhispererRequest( requestContext.fileContextInfo, requestContext.awaitSupplementalContext(), - requestContext.customizationArn + requestContext.customizationArn, + requestContext.workspaceId ) ) @@ -671,7 +673,12 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable { // 5. customization val customizationArn = CodeWhispererModelConfigurator.getInstance().activeCustomization(project)?.arn - return RequestContext(project, editor, triggerTypeInfo, caretPosition, fileContext, supplementalContext, connection, latencyContext, customizationArn) + // TODO: use workspaceID from LSP + // hardcoded for now! + val workspaceId = null + + return RequestContext(project, editor, triggerTypeInfo, caretPosition, + fileContext, supplementalContext, connection, latencyContext, customizationArn, workspaceId) } fun validateResponse(response: GenerateCompletionsResponse): GenerateCompletionsResponse { @@ -805,6 +812,7 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable { fileContextInfo: FileContextInfo, supplementalContext: SupplementalContextInfo?, customizationArn: String?, + workspaceId: String? ): GenerateCompletionsRequest { val programmingLanguage = ProgrammingLanguage.builder() .languageName(fileContextInfo.programmingLanguage.toCodeWhispererRuntimeLanguage().languageId) @@ -833,6 +841,7 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable { .referenceTrackerConfiguration { it.recommendationsWithReferences(includeCodeWithReference) } .customizationArn(customizationArn) .optOutPreference(getTelemetryOptOutPreference()) + .workspaceId(workspaceId) .build() } } @@ -848,6 +857,7 @@ data class RequestContext( val connection: ToolkitConnection?, val latencyContext: LatencyContext, val customizationArn: String?, + val workspaceId: String? ) { // TODO: should make the entire getRequestContext() suspend function instead of making supplemental context only var supplementalContext: SupplementalContextInfo? = null diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/settings/CodeWhispererConfigurable.kt b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/settings/CodeWhispererConfigurable.kt index 154f48d61c3..116434aa008 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/settings/CodeWhispererConfigurable.kt +++ b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/settings/CodeWhispererConfigurable.kt @@ -136,6 +136,20 @@ class CodeWhispererConfigurable(private val project: Project) : } group(message("aws.settings.codewhisperer.group.q_chat")) { + row { + checkBox(message("aws.settings.codewhisperer.workspace_context")).apply { + connect.subscribe( + ToolkitConnectionManagerListener.TOPIC, + object : ToolkitConnectionManagerListener { + override fun activeConnectionChanged(newConnection: ToolkitConnection?) { + enabled(isCodeWhispererEnabled(project)) + } + } + ) + enabled(invoke) + bindSelected(codeWhispererSettings::isWorkspaceContextEnabled, codeWhispererSettings::toggleWorkspaceContextEnabled) + }.comment(message("aws.settings.codewhisperer.workspace_context.tooltip")) + } row { checkBox(message("aws.settings.codewhisperer.project_context")).apply { connect.subscribe( diff --git a/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLanguageClientImpl.kt b/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLanguageClientImpl.kt index cb6388afed5..6bbfd60fd84 100644 --- a/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLanguageClientImpl.kt +++ b/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLanguageClientImpl.kt @@ -64,7 +64,8 @@ class AmazonQLanguageClientImpl : AmazonQLanguageClient { AmazonQLspConstants.LSP_CW_CONFIGURATION_KEY -> { add( CodeWhispererLspConfiguration( - shouldShareData = CodeWhispererSettings.getInstance().isMetricOptIn() + shouldShareData = CodeWhispererSettings.getInstance().isMetricOptIn(), + shouldEnableWorkspaceContext = CodeWhispererSettings.getInstance().isWorkspaceContextEnabled() ) ) } diff --git a/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspConstants.kt b/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspConstants.kt index 0894a875f43..4594c29ac20 100644 --- a/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspConstants.kt +++ b/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspConstants.kt @@ -6,4 +6,5 @@ package software.aws.toolkits.jetbrains.services.amazonq.lsp object AmazonQLspConstants { const val LSP_CW_CONFIGURATION_KEY = "aws.codeWhisperer" const val LSP_CW_OPT_OUT_KEY = "shareCodeWhispererContentWithAWS" + const val LSP_WORKSPACE_CONTEXT_ENABLED_KEY = "workspaceContext" } diff --git a/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/CodeWhispererLspConfiguration.kt b/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/CodeWhispererLspConfiguration.kt index 6442e4cc380..05eddd66e42 100644 --- a/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/CodeWhispererLspConfiguration.kt +++ b/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/CodeWhispererLspConfiguration.kt @@ -8,4 +8,6 @@ import com.google.gson.annotations.SerializedName data class CodeWhispererLspConfiguration( @SerializedName(AmazonQLspConstants.LSP_CW_OPT_OUT_KEY) val shouldShareData: Boolean? = null, + @SerializedName(AmazonQLspConstants.LSP_WORKSPACE_CONTEXT_ENABLED_KEY) + val shouldEnableWorkspaceContext: Boolean? = null, ) diff --git a/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/CodeWhispererSettings.kt b/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/CodeWhispererSettings.kt index 9e78c5aa17f..e33ac861507 100644 --- a/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/CodeWhispererSettings.kt +++ b/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/CodeWhispererSettings.kt @@ -84,6 +84,11 @@ class CodeWhispererSettings : PersistentStateComponent + defaultValue="https://rts.alpha-us-west-2.codewhisperer.ai.aws.dev/" restartRequired="true"/> diff --git a/plugins/core/resources/resources/software/aws/toolkits/resources/MessagesBundle.properties b/plugins/core/resources/resources/software/aws/toolkits/resources/MessagesBundle.properties index 94bdea402bf..c415a417ea0 100644 --- a/plugins/core/resources/resources/software/aws/toolkits/resources/MessagesBundle.properties +++ b/plugins/core/resources/resources/software/aws/toolkits/resources/MessagesBundle.properties @@ -286,6 +286,8 @@ aws.settings.codewhisperer.group.plugin_settings=Plugin Settings aws.settings.codewhisperer.group.q_chat=Chat aws.settings.codewhisperer.include_code_with_reference=Include suggestions with code references aws.settings.codewhisperer.include_code_with_reference.tooltip=When checked, Amazon Q will include suggestions with code references. If you authenticate through IAM Identity Center, this setting is controlled by your Amazon Q Developer Pro administrator. Learn more +aws.settings.codewhisperer.workspace_context=Workspace context +aws.settings.codewhisperer.workspace_context.tooltip=When checked, Amazon Q will enable server side project context. aws.settings.codewhisperer.project_context=Workspace index aws.settings.codewhisperer.project_context.tooltip=When you add @workspace to your questions in Amazon Q chat, Amazon Q will index your workspace files locally to use as context for its response. Extra CPU usage is expected while indexing a workspace. This will not impact Amazon Q features or your IDE, but you may manage CPU usage by setting the number of local threads below. aws.settings.codewhisperer.project_context_gpu=Workspace index uses GPU diff --git a/plugins/core/sdk-codegen/codegen-resources/codewhispererruntime/service-2.json b/plugins/core/sdk-codegen/codegen-resources/codewhispererruntime/service-2.json index ac1f5d6e357..fe74cb1626c 100644 --- a/plugins/core/sdk-codegen/codegen-resources/codewhispererruntime/service-2.json +++ b/plugins/core/sdk-codegen/codegen-resources/codewhispererruntime/service-2.json @@ -1386,7 +1386,8 @@ "customizationArn": { "shape": "CustomizationArn" }, "optOutPreference": { "shape": "OptOutPreference" }, "userContext": { "shape": "UserContext" }, - "profileArn": { "shape": "ProfileArn" } + "profileArn": { "shape": "ProfileArn" }, + "workspaceId": { "shape": "UUID" } } }, "GenerateCompletionsRequestMaxResultsInteger": {