Skip to content
Closed

Sspc #5454

Show file tree
Hide file tree
Changes from all 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 @@ -21,6 +21,7 @@
import com.intellij.psi.PsiFile
import com.intellij.util.concurrency.annotations.RequiresEdt
import com.intellij.util.messages.Topic
import io.ktor.client.request.request

Check warning on line 24 in plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/service/CodeWhispererService.kt

View workflow job for this annotation

GitHub Actions / qodana

Unused import directive

Unused import directive

Check warning

Code scanning / QDJVMC

Unused import directive Warning

Unused import directive
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Job
Expand Down Expand Up @@ -232,7 +233,8 @@
buildCodeWhispererRequest(
requestContext.fileContextInfo,
requestContext.awaitSupplementalContext(),
requestContext.customizationArn
requestContext.customizationArn,
requestContext.workspaceId
)
)

Expand Down Expand Up @@ -671,7 +673,12 @@
// 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 {
Expand Down Expand Up @@ -805,6 +812,7 @@
fileContextInfo: FileContextInfo,
supplementalContext: SupplementalContextInfo?,
customizationArn: String?,
workspaceId: String?
): GenerateCompletionsRequest {
val programmingLanguage = ProgrammingLanguage.builder()
.languageName(fileContextInfo.programmingLanguage.toCodeWhispererRuntimeLanguage().languageId)
Expand Down Expand Up @@ -833,6 +841,7 @@
.referenceTrackerConfiguration { it.recommendationsWithReferences(includeCodeWithReference) }
.customizationArn(customizationArn)
.optOutPreference(getTelemetryOptOutPreference())
.workspaceId(workspaceId)
.build()
}
}
Expand All @@ -848,6 +857,7 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ class CodeWhispererSettings : PersistentStateComponent<CodeWhispererConfiguratio
}
}

fun toggleWorkspaceContextEnabled(value: Boolean, passive: Boolean = false) {
state.value[CodeWhispererConfigurationType.IsWorkspaceContextEnabled] = value
}

fun isWorkspaceContextEnabled() = state.value.getOrDefault(CodeWhispererConfigurationType.IsWorkspaceContextEnabled, true)
fun isProjectContextEnabled() = state.value.getOrDefault(CodeWhispererConfigurationType.IsProjectContextEnabled, false)

private fun hasEnabledProjectContextOnce() = state.value.getOrDefault(CodeWhispererConfigurationType.HasEnabledProjectContextOnce, false)
Expand Down Expand Up @@ -192,6 +197,7 @@ enum class CodeWhispererConfigurationType {
HasEnabledProjectContextOnce,
IsQPrioritizedForTabAccept,
IsTabAcceptPriorityNotificationShownOnce,
IsWorkspaceContextEnabled
}

enum class CodeWhispererStringConfigurationType {
Expand Down
2 changes: 1 addition & 1 deletion plugins/amazonq/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

<extensions defaultExtensionNs="com.intellij">
<registryKey key="amazon.q.endpoint" description="Endpoint to use for Amazon Q"
defaultValue="https://codewhisperer.us-east-1.amazonaws.com/" restartRequired="true"/>
defaultValue="https://rts.alpha-us-west-2.codewhisperer.ai.aws.dev/" restartRequired="true"/>
<registryKey key="inline.completion.rem.dev.use.rhizome" description="Defined by IntelliJ. Used for Amazon Q to display suggestions on remote."
defaultValue="false" restartRequired="true"/>
</extensions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. <a href="https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/code-reference.html">Learn more<a/>
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,8 @@
"customizationArn": { "shape": "CustomizationArn" },
"optOutPreference": { "shape": "OptOutPreference" },
"userContext": { "shape": "UserContext" },
"profileArn": { "shape": "ProfileArn" }
"profileArn": { "shape": "ProfileArn" },
"workspaceId": { "shape": "UUID" }
}
},
"GenerateCompletionsRequestMaxResultsInteger": {
Expand Down
Loading