Skip to content

Commit 724affe

Browse files
authored
fix(amazonq): skip activation if old Toolkit is detected; Q gain focus at first use aws#4711
Problem Q is not compatible with old toolkit. Solution - Prevent Q activation if detected old aws toolkit from the marketplace. - It will not prevent Q activation if detected toolkit with a dev version. - Auto installs new toolkit from marketplace and then prompt user to reload. - Let Q gain focus at first activation.
1 parent f6d5be7 commit 724affe

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

packages/amazonq/src/extensionShared.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import * as vscode from 'vscode'
7+
import * as semver from 'semver'
78
import { join } from 'path'
89
import {
910
CodeSuggestionsState,
@@ -24,7 +25,7 @@ import {
2425
globals,
2526
RegionProvider,
2627
} from 'aws-core-vscode/shared'
27-
import { initializeAuth, CredentialsStore, LoginManager } from 'aws-core-vscode/auth'
28+
import { initializeAuth, CredentialsStore, LoginManager, ExtensionUse } from 'aws-core-vscode/auth'
2829
import { makeEndpointsProvider, registerCommands } from 'aws-core-vscode'
2930
import { activate as activateCWChat } from 'aws-core-vscode/amazonq'
3031
import { activate as activateQGumby } from 'aws-core-vscode/amazonqGumby'
@@ -36,6 +37,32 @@ export async function activateShared(context: vscode.ExtensionContext) {
3637
const contextPrefix = 'amazonq'
3738
globals.contextPrefix = 'amazonq.' //todo: disconnect from above line
3839

40+
// Avoid activation if older toolkit is installed
41+
// Amazon Q is only compatible with AWS Toolkit >= 3.0.0
42+
// Or AWS Toolkit with a development version. Example: 2.19.0-3413gv
43+
const toolkit = vscode.extensions.getExtension(VSCODE_EXTENSION_ID.awstoolkit)
44+
if (toolkit) {
45+
const toolkitVersion = semver.coerce(toolkit.packageJSON.version)
46+
const isDevVersion = toolkit.packageJSON.version.toString().includes('-')
47+
if (toolkitVersion && toolkitVersion.major < 3 && !isDevVersion) {
48+
await vscode.commands
49+
.executeCommand('workbench.extensions.installExtension', VSCODE_EXTENSION_ID.awstoolkit)
50+
.then(
51+
void vscode.window
52+
.showInformationMessage(
53+
`The Amazon Q extension is incompatible with AWS Toolkit versions 2.9 and below. Your AWS Toolkit was updated to version 3.0 or later.`,
54+
'Reload Now'
55+
)
56+
.then(async resp => {
57+
if (resp === 'Reload Now') {
58+
await vscode.commands.executeCommand('workbench.action.reloadWindow')
59+
}
60+
})
61+
)
62+
return
63+
}
64+
}
65+
3966
await initializeComputeRegion()
4067
initialize(context)
4168
const extContext = {
@@ -93,6 +120,10 @@ export async function activateShared(context: vscode.ExtensionContext) {
93120

94121
// enable auto suggestions on activation
95122
await CodeSuggestionsState.instance.setSuggestionsEnabled(true)
123+
124+
if (ExtensionUse.instance.isFirstUse()) {
125+
await vscode.commands.executeCommand('workbench.view.extension.amazonq')
126+
}
96127
}
97128

98129
export async function deactivateShared() {

packages/core/src/auth/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ export { Connection, AwsConnection } from './connection'
1414
export { Auth } from './auth'
1515
export { CredentialsStore } from './credentials/store'
1616
export { LoginManager } from './deprecated/loginManager'
17+
export { ExtensionUse } from './utils'

packages/core/src/codewhisperer/activation.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import { sleep } from '../shared/utilities/timeoutUtils'
4545
import { ReferenceLogViewProvider } from './service/referenceLogViewProvider'
4646
import { ReferenceHoverProvider } from './service/referenceHoverProvider'
4747
import { ReferenceInlineProvider } from './service/referenceInlineProvider'
48-
import { SecurityPanelViewProvider } from './views/securityPanelViewProvider'
48+
import { SecurityPanelViewProvider, openEditorAtRange } from './views/securityPanelViewProvider'
4949
import { disposeSecurityDiagnostic } from './service/diagnosticsProvider'
5050
import { RecommendationHandler } from './service/recommendationHandler'
5151
import { Commands, registerCommandsWithVSCode } from '../shared/vscode/commands2'
@@ -266,7 +266,8 @@ export async function activate(context: ExtContext): Promise<void> {
266266
vscode.languages.registerCodeActionsProvider(
267267
[...CodeWhispererConstants.platformLanguageIds],
268268
SecurityIssueCodeActionProvider.instance
269-
)
269+
),
270+
vscode.commands.registerCommand('aws.amazonq.openEditorAtRange', openEditorAtRange)
270271
)
271272

272273
await auth.restore()

packages/core/src/codewhisperer/views/securityPanelViewProvider.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ function makeUri(...args: Parameters<typeof openEditorAtRange>): vscode.Uri {
1111
return vscode.Uri.parse(`command:aws.amazonq.openEditorAtRange?${encodeURIComponent(JSON.stringify(args))}`)
1212
}
1313

14-
async function openEditorAtRange(path: string, startLine: number, endLine: number) {
14+
export async function openEditorAtRange(path: string, startLine: number, endLine: number) {
1515
const uri = vscode.Uri.parse(path)
1616
await vscode.window.showTextDocument(uri, { preview: false, preserveFocus: true }).then(e => {
1717
e.selection = new vscode.Selection(startLine, 0, endLine, 0)
1818
e.revealRange(new vscode.Range(startLine, 0, endLine, 0), vscode.TextEditorRevealType.InCenterIfOutsideViewport)
1919
})
2020
}
2121

22-
vscode.commands.registerCommand('aws.amazonq.openEditorAtRange', openEditorAtRange)
23-
2422
export class SecurityPanelViewProvider implements vscode.WebviewViewProvider {
2523
public static readonly viewType = 'aws.codeWhisperer.securityPanel'
2624
private view?: vscode.WebviewView

0 commit comments

Comments
 (0)