Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(inline): move codewhispererConfigurable to shared module #5304

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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 @@ -20,9 +20,7 @@ import software.aws.toolkits.jetbrains.core.credentials.sso.bearer.BearerTokenPr
import software.aws.toolkits.jetbrains.services.codewhisperer.credentials.CodeWhispererLoginType
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.CodeWhispererExploreActionState
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.CodeWhispererExploreStateType
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererUtil.getConnectionStartUrl
import software.aws.toolkits.telemetry.AwsTelemetry

// TODO: refactor this class, now it's managing action and state
@State(name = "codewhispererStates", storages = [Storage("aws.xml")])
Expand All @@ -39,7 +37,10 @@ class CodeWhispererExplorerActionManager : PersistentStateComponent<CodeWhispere

private fun getCodeWhispererConnectionStartUrl(project: Project): String {
val connection = ToolkitConnectionManager.getInstance(project).activeConnectionForFeature(CodeWhispererConnection.getInstance())
return getConnectionStartUrl(connection) ?: CodeWhispererConstants.ACCOUNTLESS_START_URL
return getConnectionStartUrl(connection) ?: run {
LOG.warn { "fail to retrieve connection start url, not a bearer token connection" }
""
}
}

fun isAutoEnabled(): Boolean = actionState.value.getOrDefault(CodeWhispererExploreStateType.IsAutoEnabled, true)
Expand Down Expand Up @@ -76,17 +77,13 @@ class CodeWhispererExplorerActionManager : PersistentStateComponent<CodeWhispere
actionState.value[CodeWhispererExploreStateType.SessionConfigurationMessageShown] = isShown
}

fun setAutoSuggestion(project: Project, isAutoEnabled: Boolean) {
fun setAutoSuggestion(isAutoEnabled: Boolean) {
setAutoEnabled(isAutoEnabled)
val autoSuggestionState = if (isAutoEnabled) CodeWhispererConstants.AutoSuggestion.ACTIVATED else CodeWhispererConstants.AutoSuggestion.DEACTIVATED
AwsTelemetry.modifySetting(project, settingId = CodeWhispererConstants.AutoSuggestion.SETTING_ID, settingState = autoSuggestionState)
}

// Adding Auto CodeScan Function
fun setAutoCodeScan(project: Project, isAutoEnabledForCodeScan: Boolean) {
fun setAutoCodeScan(isAutoEnabledForCodeScan: Boolean) {
setAutoEnabledForCodeScan(isAutoEnabledForCodeScan)
val autoCodeScanState = if (isAutoEnabledForCodeScan) CodeWhispererConstants.AutoCodeScan.ACTIVATED else CodeWhispererConstants.AutoCodeScan.DEACTIVATED
AwsTelemetry.modifySetting(project, settingId = CodeWhispererConstants.AutoCodeScan.SETTING_ID, settingState = autoCodeScanState)
}

fun getIsFirstRestartAfterQInstall(): Boolean = actionState.value.getOrDefault(CodeWhispererExploreStateType.IsFirstRestartAfterQInstall, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.DumbAwareAction
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.CodeWhispererExplorerActionManager
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants
import software.aws.toolkits.resources.message
import software.aws.toolkits.telemetry.AwsTelemetry

Check warning

Code scanning / QDJVMC

Usage of redundant or deprecated syntax or deprecated symbols Warning

Remove deprecated symbol import

Check warning

Code scanning / QDJVMC

Usage of redundant or deprecated syntax or deprecated symbols Warning

'AwsTelemetry' is deprecated. Use type-safe metric builders

class Pause : DumbAwareAction(
{ message("codewhisperer.explorer.pause_auto") },
Expand All @@ -16,6 +18,11 @@
override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return

CodeWhispererExplorerActionManager.getInstance().setAutoSuggestion(project, false)
CodeWhispererExplorerActionManager.getInstance().setAutoSuggestion(false)
AwsTelemetry.modifySetting(

Check warning on line 22 in plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/explorer/actions/Pause.kt

View workflow job for this annotation

GitHub Actions / qodana

Usage of redundant or deprecated syntax or deprecated symbols

'AwsTelemetry' is deprecated. Use type-safe metric builders

Check warning

Code scanning / QDJVMC

Usage of redundant or deprecated syntax or deprecated symbols Warning

'AwsTelemetry' is deprecated. Use type-safe metric builders
project,
settingId = CodeWhispererConstants.AutoSuggestion.SETTING_ID,
settingState = CodeWhispererConstants.AutoSuggestion.DEACTIVATED
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.DumbAwareAction
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.CodeWhispererExplorerActionManager
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants
import software.aws.toolkits.resources.message
import software.aws.toolkits.telemetry.AwsTelemetry

Check warning on line 12 in plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/explorer/actions/PauseCodeScans.kt

View workflow job for this annotation

GitHub Actions / qodana

Usage of redundant or deprecated syntax or deprecated symbols

Remove deprecated symbol import

Check warning

Code scanning / QDJVMC

Usage of redundant or deprecated syntax or deprecated symbols Warning

Remove deprecated symbol import

Check warning

Code scanning / QDJVMC

Usage of redundant or deprecated syntax or deprecated symbols Warning

'AwsTelemetry' is deprecated. Use type-safe metric builders

class PauseCodeScans : DumbAwareAction(
{ message("codewhisperer.explorer.pause_auto_scans") },
Expand All @@ -16,6 +18,11 @@
override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return

CodeWhispererExplorerActionManager.getInstance().setAutoCodeScan(project, false)
CodeWhispererExplorerActionManager.getInstance().setAutoCodeScan(false)
AwsTelemetry.modifySetting(

Check warning on line 22 in plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/explorer/actions/PauseCodeScans.kt

View workflow job for this annotation

GitHub Actions / qodana

Usage of redundant or deprecated syntax or deprecated symbols

'AwsTelemetry' is deprecated. Use type-safe metric builders

Check warning

Code scanning / QDJVMC

Usage of redundant or deprecated syntax or deprecated symbols Warning

'AwsTelemetry' is deprecated. Use type-safe metric builders
project,
settingId = CodeWhispererConstants.AutoCodeScan.SETTING_ID,
settingState = CodeWhispererConstants.AutoCodeScan.DEACTIVATED
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.DumbAwareAction
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.CodeWhispererExplorerActionManager
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants
import software.aws.toolkits.resources.message
import software.aws.toolkits.telemetry.AwsTelemetry

Check warning on line 12 in plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/explorer/actions/Resume.kt

View workflow job for this annotation

GitHub Actions / qodana

Usage of redundant or deprecated syntax or deprecated symbols

'AwsTelemetry' is deprecated. Use type-safe metric builders

Check warning

Code scanning / QDJVMC

Usage of redundant or deprecated syntax or deprecated symbols Warning

Remove deprecated symbol import

Check warning

Code scanning / QDJVMC

Usage of redundant or deprecated syntax or deprecated symbols Warning

'AwsTelemetry' is deprecated. Use type-safe metric builders

class Resume : DumbAwareAction(
{ message("codewhisperer.explorer.resume_auto") },
Expand All @@ -16,6 +18,11 @@
override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return

CodeWhispererExplorerActionManager.getInstance().setAutoSuggestion(project, true)
CodeWhispererExplorerActionManager.getInstance().setAutoSuggestion(true)
AwsTelemetry.modifySetting(

Check warning on line 22 in plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/explorer/actions/Resume.kt

View workflow job for this annotation

GitHub Actions / qodana

Usage of redundant or deprecated syntax or deprecated symbols

'AwsTelemetry' is deprecated. Use type-safe metric builders

Check warning

Code scanning / QDJVMC

Usage of redundant or deprecated syntax or deprecated symbols Warning

'AwsTelemetry' is deprecated. Use type-safe metric builders
project,
settingId = CodeWhispererConstants.AutoSuggestion.SETTING_ID,
settingState = CodeWhispererConstants.AutoSuggestion.ACTIVATED
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.isUserBuilderId
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants
import software.aws.toolkits.resources.message
import software.aws.toolkits.telemetry.AwsTelemetry

Check warning on line 14 in plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/explorer/actions/ResumeCodeScans.kt

View workflow job for this annotation

GitHub Actions / qodana

Usage of redundant or deprecated syntax or deprecated symbols

'AwsTelemetry' is deprecated. Use type-safe metric builders

Check warning on line 14 in plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/explorer/actions/ResumeCodeScans.kt

View workflow job for this annotation

GitHub Actions / qodana

Usage of redundant or deprecated syntax or deprecated symbols

Remove deprecated symbol import

Check warning

Code scanning / QDJVMC

Usage of redundant or deprecated syntax or deprecated symbols Warning

Remove deprecated symbol import

Check warning

Code scanning / QDJVMC

Usage of redundant or deprecated syntax or deprecated symbols Warning

'AwsTelemetry' is deprecated. Use type-safe metric builders

class ResumeCodeScans : DumbAwareAction(
{ message("codewhisperer.explorer.resume_auto_scans") },
Expand All @@ -20,7 +21,12 @@
val project = e.project ?: return

val actionManager = CodeWhispererExplorerActionManager.getInstance()
actionManager.setAutoCodeScan(project, true)
actionManager.setAutoCodeScan(true)
AwsTelemetry.modifySetting(

Check warning

Code scanning / QDJVMC

Usage of redundant or deprecated syntax or deprecated symbols Warning

'AwsTelemetry' is deprecated. Use type-safe metric builders
project,
settingId = CodeWhispererConstants.AutoCodeScan.SETTING_ID,
settingState = CodeWhispererConstants.AutoCodeScan.ACTIVATED
)
// Run Proactive Code File Scan once toggle is enabled
if (actionManager.isAutoEnabledForCodeScan() && !actionManager.isMonthlyQuotaForCodeScansExceeded() && !isUserBuilderId(project)) {
CodeWhispererCodeScanManager.getInstance(project).createDebouncedRunCodeScan(CodeWhispererConstants.CodeAnalysisScope.FILE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ object CodeWhispererConstants {
const val TOTAL_BYTES_IN_MB = 1024 * 1024
const val TOTAL_MILLIS_IN_SECOND = 1000
const val TOTAL_SECONDS_IN_MINUTE: Long = 60L
const val ACCOUNTLESS_START_URL = "accountless"
const val FEATURE_CONFIG_POLL_INTERVAL_IN_MS: Long = 30 * 60 * 1000L // 30 mins
const val USING: String = "using"
const val GLOBAL_USING: String = "global using"
Expand Down
Loading