|
| 1 | +/*! |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import * as vscode from 'vscode' |
| 7 | +import { ExtensionContext, window } from 'vscode' |
| 8 | +import { Auth } from 'aws-core-vscode/auth' |
| 9 | +import { telemetry } from 'aws-core-vscode/telemetry' |
| 10 | +import { CodeWhispererSettings } from 'aws-core-vscode/codewhisperer' |
| 11 | +import { Commands, placeholder, funcUtil } from 'aws-core-vscode/shared' |
| 12 | +import * as amazonq from 'aws-core-vscode/amazonq' |
| 13 | + |
| 14 | +export async function activate(context: ExtensionContext) { |
| 15 | + const appInitContext = amazonq.DefaultAmazonQAppInitContext.instance |
| 16 | + |
| 17 | + registerApps(appInitContext) |
| 18 | + |
| 19 | + const provider = new amazonq.AmazonQChatViewProvider( |
| 20 | + context, |
| 21 | + appInitContext.getWebViewToAppsMessagePublishers(), |
| 22 | + appInitContext.getAppsToWebViewMessageListener(), |
| 23 | + appInitContext.onDidChangeAmazonQVisibility |
| 24 | + ) |
| 25 | + |
| 26 | + await amazonq.TryChatCodeLensProvider.register(appInitContext.onDidChangeAmazonQVisibility.event) |
| 27 | + |
| 28 | + const setupLsp = funcUtil.debounce(async () => { |
| 29 | + void amazonq.LspController.instance.trySetupLsp(context) |
| 30 | + }, 5000) |
| 31 | + |
| 32 | + context.subscriptions.push( |
| 33 | + window.registerWebviewViewProvider(amazonq.AmazonQChatViewProvider.viewType, provider, { |
| 34 | + webviewOptions: { |
| 35 | + retainContextWhenHidden: true, |
| 36 | + }, |
| 37 | + }), |
| 38 | + amazonq.focusAmazonQChatWalkthrough.register(), |
| 39 | + amazonq.walkthroughInlineSuggestionsExample.register(), |
| 40 | + amazonq.walkthroughSecurityScanExample.register(), |
| 41 | + amazonq.openAmazonQWalkthrough.register(), |
| 42 | + amazonq.listCodeWhispererCommandsWalkthrough.register(), |
| 43 | + amazonq.focusAmazonQPanel.register(), |
| 44 | + amazonq.focusAmazonQPanelKeybinding.register(), |
| 45 | + amazonq.tryChatCodeLensCommand.register(), |
| 46 | + vscode.workspace.onDidChangeConfiguration(async (configurationChangeEvent) => { |
| 47 | + if (configurationChangeEvent.affectsConfiguration('amazonQ.workspaceIndex')) { |
| 48 | + if (CodeWhispererSettings.instance.isLocalIndexEnabled()) { |
| 49 | + void setupLsp() |
| 50 | + } |
| 51 | + } |
| 52 | + }) |
| 53 | + ) |
| 54 | + |
| 55 | + Commands.register('aws.amazonq.learnMore', () => { |
| 56 | + void vscode.env.openExternal(vscode.Uri.parse(amazonq.amazonQHelpUrl)) |
| 57 | + }) |
| 58 | + |
| 59 | + await amazonq.activateBadge() |
| 60 | + void setupLsp() |
| 61 | + void setupAuthNotification() |
| 62 | +} |
| 63 | + |
| 64 | +function registerApps(appInitContext: amazonq.AmazonQAppInitContext) { |
| 65 | + amazonq.cwChatAppInit(appInitContext) |
| 66 | + amazonq.featureDevChatAppInit(appInitContext) |
| 67 | + amazonq.gumbyChatAppInit(appInitContext) |
| 68 | +} |
| 69 | + |
| 70 | +/** |
| 71 | + * Display a notification to user for Log In. |
| 72 | + * |
| 73 | + * Authentication Notification is displayed when: |
| 74 | + * - User is not authenticated |
| 75 | + * - Once every session |
| 76 | + * |
| 77 | + */ |
| 78 | +async function setupAuthNotification() { |
| 79 | + let notificationDisplayed = false // Auth Notification should be displayed only once. |
| 80 | + await tryShowNotification() |
| 81 | + |
| 82 | + async function tryShowNotification() { |
| 83 | + // Do not show the notification if the IDE starts and user is already authenticated. |
| 84 | + if (Auth.instance.activeConnection) { |
| 85 | + notificationDisplayed = true |
| 86 | + } |
| 87 | + |
| 88 | + if (notificationDisplayed) { |
| 89 | + return |
| 90 | + } |
| 91 | + |
| 92 | + const source = 'authNotification' |
| 93 | + const buttonAction = 'Sign In' |
| 94 | + notificationDisplayed = true |
| 95 | + |
| 96 | + telemetry.toolkit_showNotification.emit({ |
| 97 | + component: 'editor', |
| 98 | + id: source, |
| 99 | + reason: 'notLoggedIn', |
| 100 | + result: 'Succeeded', |
| 101 | + }) |
| 102 | + const selection = await vscode.window.showWarningMessage('Start using Amazon Q', buttonAction) |
| 103 | + |
| 104 | + if (selection === buttonAction) { |
| 105 | + void amazonq.focusAmazonQPanel.execute(placeholder, source) |
| 106 | + } |
| 107 | + } |
| 108 | +} |
0 commit comments