Skip to content

Commit 79e90cb

Browse files
authored
settings: remove global state check for amazonq migration (#4891)
- Improve setting migration logging. - Remove global state check for migrating codewhisperer settings. With the current state of the setting migration code, this shouldn't be needed. The old values will never overwrite what is already defined.
1 parent 8d616f8 commit 79e90cb

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

packages/core/src/codewhisperer/models/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ export const validStatesForCheckingDownloadUrl = [
364364
'REJECTED',
365365
]
366366

367-
export const codewhispererSettingsImportedKey = 'aws.amazonq.codewhispererSettingsImported'
368367
export const amazonQDismissedKey = 'aws.toolkit.amazonq.dismissed'
369368
export const amazonQInstallDismissedKey = 'aws.toolkit.amazonqInstall.dismissed'
370369

packages/core/src/codewhisperer/util/codewhispererSettings.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55
import { fromExtensionManifest, migrateSetting } from '../../shared/settings'
6-
import globals from '../../shared/extensionGlobals'
7-
import { codewhispererSettingsImportedKey } from '../models/constants'
86

97
const description = {
108
showInlineCodeSuggestionsWithCodeReferences: Boolean, // eslint-disable-line id-length
@@ -13,11 +11,8 @@ const description = {
1311
}
1412

1513
export class CodeWhispererSettings extends fromExtensionManifest('amazonQ', description) {
14+
// TODO: Remove after a few releases
1615
public async importSettings() {
17-
if (globals.context.globalState.get<boolean>(codewhispererSettingsImportedKey)) {
18-
return
19-
}
20-
2116
await migrateSetting(
2217
{ key: 'aws.codeWhisperer.includeSuggestionsWithCodeReferences', type: Boolean },
2318
{ key: 'amazonQ.showInlineCodeSuggestionsWithCodeReferences' }
@@ -30,8 +25,6 @@ export class CodeWhispererSettings extends fromExtensionManifest('amazonQ', desc
3025
{ key: 'aws.codeWhisperer.shareCodeWhispererContentWithAWS', type: Boolean },
3126
{ key: 'amazonQ.shareContentWithAWS' }
3227
)
33-
34-
await globals.context.globalState.update(codewhispererSettingsImportedKey, true)
3528
}
3629

3730
public isSuggestionsWithCodeReferencesEnabled(): boolean {

packages/core/src/shared/settings.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,16 @@ export async function migrateSetting<T, U = T>(
874874
const logPrefix = `Settings migration ("${from.key}" -> "${to.key}"), (scope: ${valueProp})`
875875

876876
const oldSettingProps = config.inspect(from.key)
877-
if (hasLatest || !oldSettingProps || oldSettingProps[valueProp] === undefined) {
878-
getLogger().debug(`${logPrefix}: skipping, no migration needed`)
877+
if (hasLatest) {
878+
getLogger().debug(`skipping: ${logPrefix}, the latest setting is already defined for this scope.`)
879+
return
880+
}
881+
if (!oldSettingProps) {
882+
getLogger().debug(`skipping: ${logPrefix}, the old setting does not exist.`)
883+
return
884+
}
885+
if (oldSettingProps[valueProp] === undefined) {
886+
getLogger().debug(`skipping: ${logPrefix}, the old setting is not defined for this scope.`)
879887
return
880888
}
881889

packages/core/src/shared/telemetry/util.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ export class TelemetryConfig {
6262
if (globals.context.globalState.get<boolean>(this.amazonQSettingMigratedKey)) {
6363
return
6464
}
65-
// aws.telemetry isn't deprecated, we are just initializing amazonQ.telemetry with its value
65+
// aws.telemetry isn't deprecated, we are just initializing amazonQ.telemetry with its value.
66+
// This is also why we need to check that we only try this migration once.
6667
await migrateSetting({ key: 'aws.telemetry', type: Boolean }, { key: 'amazonQ.telemetry' })
6768
await globals.context.globalState.update(this.amazonQSettingMigratedKey, true)
6869
}

0 commit comments

Comments
 (0)