Skip to content

Commit

Permalink
refactor: openSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmk3 committed Apr 27, 2024
1 parent 338e868 commit 5e59ee4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/codewhisperer/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { debounceStartSecurityScan } from './commands/startSecurityScan'
import { securityScanLanguageContext } from './util/securityScanLanguageContext'
import { registerWebviewErrorHandler } from '../webviews/server'
import { logAndShowWebviewError } from '../shared/utilities/logAndShowUtils'
import { openSettings } from '../shared/settings'

let localize: nls.LocalizeFunc

Expand Down Expand Up @@ -190,7 +191,7 @@ export async function activate(context: ExtContext): Promise<void> {
`@id:amazonQ.includeSuggestionsWithCodeReferences`
)
} else {
await vscode.commands.executeCommand('workbench.action.openSettings', `amazonQ`)
await openSettings('amazonQ')
}
}),
Commands.register('aws.amazonq.refreshAnnotation', async (forceProceed: boolean = false) => {
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/shared/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -894,11 +894,16 @@ export async function migrateSetting<T, U = T>(
await migrateForScope(vscode.ConfigurationTarget.Global)
}

/** Opens the settings UI filtered by the given prefix. */
export async function openSettings(prefix: string): Promise<void> {
await vscode.commands.executeCommand('workbench.action.openSettings', prefix)
}

/**
* Opens the settings UI at the specified key.
*
* This only works for keys that are considered "top-level", e.g. keys of {@link settingsProps}.
*/
export async function openSettings<K extends keyof SettingsProps>(key: K): Promise<void> {
export async function openSettingsId<K extends keyof SettingsProps>(key: K): Promise<void> {
await vscode.commands.executeCommand('workbench.action.openSettings', `@id:${key}`)
}
4 changes: 2 additions & 2 deletions packages/core/src/shared/telemetry/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { AwsContext } from '../awsContext'
import { DefaultTelemetryService } from './telemetryService'
import { getLogger } from '../logger'
import { getComputeRegion, isAmazonQ, isCloud9, productName } from '../extensionUtilities'
import { openSettings, Settings } from '../settings'
import { openSettingsId, Settings } from '../settings'
import { TelemetryConfig, setupTelemetryId } from './util'
import { isAutomation, isReleaseVersion } from '../vscode/env'
import { AWSProduct } from './clienttelemetry'
Expand Down Expand Up @@ -133,7 +133,7 @@ export async function handleTelemetryNoticeResponse(
// noticeResponseOk is a no-op

if (response === noticeResponseViewSettings) {
await openSettings(isAmazonQ() ? 'amazonQ.telemetry' : 'aws.telemetry')
await openSettingsId(isAmazonQ() ? 'amazonQ.telemetry' : 'aws.telemetry')
}
} catch (err) {
getLogger().error('Error while handling response from telemetry notice: %O', err as Error)
Expand Down

0 comments on commit 5e59ee4

Please sign in to comment.