diff --git a/packages/amazonq/src/extension.ts b/packages/amazonq/src/extension.ts index d489f694d34..222ebcaff87 100644 --- a/packages/amazonq/src/extension.ts +++ b/packages/amazonq/src/extension.ts @@ -3,13 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { CredentialsStore, LoginManager, authUtils, initializeAuth } from 'aws-core-vscode/auth' -import { Auth, AuthUtils, CredentialsStore, LoginManager, initializeAuth } from 'aws-core-vscode/auth' -import { - activate as activateCodeWhisperer, - AuthUtil, - shutdown as shutdownCodeWhisperer, -} from 'aws-core-vscode/codewhisperer' +import { authUtils, CredentialsStore, LoginManager, initializeAuth } from 'aws-core-vscode/auth' +import { activate as activateCodeWhisperer, shutdown as shutdownCodeWhisperer } from 'aws-core-vscode/codewhisperer' import { makeEndpointsProvider, registerGenericCommands } from 'aws-core-vscode' import { CommonAuthWebview } from 'aws-core-vscode/login' import { @@ -39,7 +34,6 @@ import { Experiments, isSageMaker, Commands, - isAmazonInternalOs, } from 'aws-core-vscode/shared' import { ExtStartUpSources } from 'aws-core-vscode/telemetry' import { VSCODE_EXTENSION_ID } from 'aws-core-vscode/utils' @@ -50,8 +44,6 @@ import { registerCommands } from './commands' import { focusAmazonQPanel } from 'aws-core-vscode/codewhispererChat' import { activate as activateAmazonqLsp } from './lsp/activation' import { activate as activateInlineCompletion } from './app/inline/activation' -import { isAmazonInternalOs } from 'aws-core-vscode/shared' -import { hasGlibcPatch } from './lsp/client' export const amazonQContextPrefix = 'amazonq' @@ -127,17 +119,12 @@ export async function activateAmazonQCommon(context: vscode.ExtensionContext, is extensionContext: context, } + // Auth is dependent on LSP, needs to be activated before CW and Inline + await activateAmazonqLsp(context) + // This contains every lsp agnostic things (auth, security scan, code scan) await activateCodeWhisperer(extContext as ExtContext) - if ( - (Experiments.instance.get('amazonqLSP', true) || AuthUtil.instance.isInternalAmazonUser()) && - (!isAmazonInternalOs() || (await hasGlibcPatch())) - ) { - // start the Amazon Q LSP for internal users first - // for AL2, start LSP if glibc patch is found - await activateAmazonqLsp(context) - } if (!Experiments.instance.get('amazonqLSPInline', false)) { await activateInlineCompletion() } diff --git a/packages/amazonq/src/extensionNode.ts b/packages/amazonq/src/extensionNode.ts index 98be79c1920..2bcf5c152ce 100644 --- a/packages/amazonq/src/extensionNode.ts +++ b/packages/amazonq/src/extensionNode.ts @@ -19,7 +19,6 @@ import api from './api' import { activate as activateCWChat } from './app/chat/activation' import { activate as activateInlineChat } from './inlineChat/activation' import { beta } from 'aws-core-vscode/dev' -import * as amazonq from 'aws-core-vscode/amazonq' import { activate as activateNotifications, NotificationsController } from 'aws-core-vscode/notifications' import { AuthUtil } from 'aws-core-vscode/codewhisperer' import { telemetry, AuthUserState } from 'aws-core-vscode/telemetry' @@ -68,8 +67,6 @@ async function activateAmazonQNode(context: vscode.ExtensionContext) { await activateTransformationHub(extContext as ExtContext) activateInlineChat(context) - context.subscriptions.push(amazonq.focusAmazonQPanel.register(), amazonq.focusAmazonQPanelKeybinding.register()) - const authProvider = new CommonAuthViewProvider( context, amazonQContextPrefix, diff --git a/packages/amazonq/src/lsp/activation.ts b/packages/amazonq/src/lsp/activation.ts index 193d306f5f0..fe1e2f15ddc 100644 --- a/packages/amazonq/src/lsp/activation.ts +++ b/packages/amazonq/src/lsp/activation.ts @@ -4,19 +4,17 @@ */ import vscode from 'vscode' -import { clientId, encryptionKey, startLanguageServer } from './client' +import { startLanguageServer } from './client' import { AmazonQLspInstaller } from './lspInstaller' import { lspSetupStage, ToolkitError, messages } from 'aws-core-vscode/shared' import { AuthUtil } from 'aws-core-vscode/codewhisperer' -import { auth2 } from 'aws-core-vscode/auth' export async function activate(ctx: vscode.ExtensionContext) { try { - const client = await lspSetupStage('all', async () => { + await lspSetupStage('all', async () => { const installResult = await new AmazonQLspInstaller().resolve() return await lspSetupStage('launch', () => startLanguageServer(ctx, installResult.resourcePaths)) }) - AuthUtil.create(new auth2.LanguageClientAuth(client, clientId, encryptionKey)) await AuthUtil.instance.restore() } catch (err) { const e = err as ToolkitError diff --git a/packages/amazonq/src/lsp/chat/messages.ts b/packages/amazonq/src/lsp/chat/messages.ts index 81dd9e13515..b5a028aa0ae 100644 --- a/packages/amazonq/src/lsp/chat/messages.ts +++ b/packages/amazonq/src/lsp/chat/messages.ts @@ -36,9 +36,6 @@ import { ShowSaveFileDialogParams, LSPErrorCodes, tabBarActionRequestType, - ShowDocumentParams, - ShowDocumentResult, - ShowDocumentRequest, contextCommandsNotificationType, ContextCommandParams, openFileDiffNotificationType, @@ -423,23 +420,6 @@ export function registerMessageListeners( } }) - languageClient.onRequest( - ShowDocumentRequest.method, - async (params: ShowDocumentParams): Promise> => { - try { - const uri = vscode.Uri.parse(params.uri) - const doc = await vscode.workspace.openTextDocument(uri) - await vscode.window.showTextDocument(doc, { preview: false }) - return params - } catch (e) { - return new ResponseError( - LSPErrorCodes.RequestFailed, - `Failed to open document: ${(e as Error).message}` - ) - } - } - ) - languageClient.onNotification(contextCommandsNotificationType.method, (params: ContextCommandParams) => { void provider.webview?.postMessage({ command: contextCommandsNotificationType.method, diff --git a/packages/amazonq/src/lsp/chat/webviewProvider.ts b/packages/amazonq/src/lsp/chat/webviewProvider.ts index 1a513f1df3f..3f9d273ab96 100644 --- a/packages/amazonq/src/lsp/chat/webviewProvider.ts +++ b/packages/amazonq/src/lsp/chat/webviewProvider.ts @@ -137,7 +137,7 @@ export class AmazonQChatViewProvider implements WebviewViewProvider { let qChat = undefined const init = () => { const vscodeApi = acquireVsCodeApi() - const hybridChatConnector = new HybridChatAdapter(${(await AuthUtil.instance.getChatAuthState()).amazonQ === 'connected'},${featureConfigData},${welcomeCount},${disclaimerAcknowledged},${regionProfileString},${disabledCommands},${isSMUS},${isSM},vscodeApi.postMessage) + const hybridChatConnector = new HybridChatAdapter(${AuthUtil.instance.isConnected()},${featureConfigData},${welcomeCount},${disclaimerAcknowledged},${regionProfileString},${disabledCommands},${isSMUS},${isSM},vscodeApi.postMessage) const commands = [hybridChatConnector.initialQuickActions[0]] qChat = amazonQChat.createChat(vscodeApi, {disclaimerAcknowledged: ${disclaimerAcknowledged}, pairProgrammingAcknowledged: ${pairProgrammingAcknowledged}, agenticMode: true, quickActionCommands: commands}, hybridChatConnector, ${JSON.stringify(featureConfigData)}); } diff --git a/packages/amazonq/src/lsp/client.ts b/packages/amazonq/src/lsp/client.ts index 5f6f548b951..899c221d28e 100644 --- a/packages/amazonq/src/lsp/client.ts +++ b/packages/amazonq/src/lsp/client.ts @@ -23,12 +23,14 @@ import { GetSsoTokenProgressToken, GetSsoTokenProgressType, MessageActionItem, - ShowDocumentParams, - ShowDocumentRequest, - ShowDocumentResult, ShowMessageRequest, ShowMessageRequestParams, ConnectionMetadata, + ShowDocumentRequest, + ShowDocumentParams, + ShowDocumentResult, + ResponseError, + LSPErrorCodes, } from '@aws/language-server-runtimes/protocol' import { AuthUtil, CodeWhispererSettings, getSelectedCustomization } from 'aws-core-vscode/codewhisperer' import { @@ -37,7 +39,6 @@ import { globals, Experiments, Commands, - openUrl, validateNodeExe, getLogger, undefinedIfEmpty, @@ -45,9 +46,10 @@ import { isAmazonInternalOs, fs, oidcClientName, + openUrl, } from 'aws-core-vscode/shared' import { processUtils } from 'aws-core-vscode/shared' -import { activate } from './chat/activation' +import { activate as activateChat } from './chat/activation' import { AmazonQResourcePaths } from './lspInstaller' import { auth2 } from 'aws-core-vscode/auth' import { ConfigSection, isValidConfigSection, toAmazonQLSPLogLevel } from './config' @@ -144,9 +146,6 @@ export async function startLanguageServer( notifications: true, showSaveFileDialog: true, }, - q: { - developerProfiles: true, - }, }, logLevel: toAmazonQLSPLogLevel(globals.logOutputChannel.logLevel), }, @@ -173,6 +172,7 @@ export async function startLanguageServer( toDispose.push(disposable) await client.onReady() + AuthUtil.create(new auth2.LanguageClientAuth(client, clientId, encryptionKey)) // Request handler for when the server wants to know about the clients auth connnection. Must be registered before the initial auth init call client.onRequest(auth2.notificationTypes.getConnectionMetadata.method, () => { @@ -183,15 +183,6 @@ export async function startLanguageServer( } }) - client.onRequest(ShowDocumentRequest.method, async (params: ShowDocumentParams) => { - try { - return { success: await openUrl(vscode.Uri.parse(params.uri), lspName) } - } catch (err: any) { - getLogger().error(`Failed to open document for LSP: ${lspName}, error: %s`, err) - return { success: false } - } - }) - client.onRequest( ShowMessageRequest.method, async (params: ShowMessageRequestParams) => { @@ -201,6 +192,30 @@ export async function startLanguageServer( } ) + client.onRequest( + ShowDocumentRequest.method, + async (params: ShowDocumentParams): Promise> => { + const uri = vscode.Uri.parse(params.uri) + getLogger().info(`Processing ShowDocumentRequest for URI scheme: ${uri.scheme}`) + try { + if (uri.scheme.startsWith('http')) { + getLogger().info('Opening URL...') + await openUrl(vscode.Uri.parse(params.uri)) + } else { + getLogger().info('Opening text document...') + const doc = await vscode.workspace.openTextDocument(uri) + await vscode.window.showTextDocument(doc, { preview: false }) + } + return params + } catch (e) { + return new ResponseError( + LSPErrorCodes.RequestFailed, + `Failed to process ShowDocumentRequest: ${(e as Error).message}` + ) + } + } + ) + const sendProfileToLsp = async () => { try { const result = await client.sendRequest(updateConfigurationRequestType.method, { @@ -266,9 +281,7 @@ export async function startLanguageServer( ) } - if (Experiments.instance.get('amazonqChatLSP', false)) { - activate(client, encryptionKey, resourcePaths.ui) - } + await activateChat(client, encryptionKey, resourcePaths.ui) toDispose.push( AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(sendProfileToLsp), diff --git a/packages/core/src/codewhisperer/util/authUtil.ts b/packages/core/src/codewhisperer/util/authUtil.ts index 5ff9a1c9a55..092b5f88d7c 100644 --- a/packages/core/src/codewhisperer/util/authUtil.ts +++ b/packages/core/src/codewhisperer/util/authUtil.ts @@ -88,6 +88,9 @@ export class AuthUtil implements IAuthProvider { async restore() { await this.session.restore() + if (!this.isConnected()) { + await this.refreshState() + } } async login(startUrl: string, region: string) {