Skip to content

Commit 908dba8

Browse files
committed
move the activation inside autodebug feature
1 parent 6ab208e commit 908dba8

File tree

4 files changed

+18
-138
lines changed

4 files changed

+18
-138
lines changed

packages/amazonq/src/extension.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import { registerCommands } from './commands'
4545
import { focusAmazonQPanel } from 'aws-core-vscode/codewhispererChat'
4646
import { activate as activateAmazonqLsp } from './lsp/activation'
4747
import { hasGlibcPatch } from './lsp/client'
48-
import { activateAutoDebug } from './lsp/autoDebug/activation'
4948

5049
export const amazonQContextPrefix = 'amazonq'
5150

@@ -138,15 +137,6 @@ export async function activateAmazonQCommon(context: vscode.ExtensionContext, is
138137
// Amazon Q specific commands
139138
registerCommands(context)
140139

141-
// Activate Auto Debug feature
142-
try {
143-
const autoDebugFeature = await activateAutoDebug(context)
144-
context.subscriptions.push(autoDebugFeature)
145-
getLogger().info('Amazon Q Auto Debug feature activated successfully')
146-
} catch (error) {
147-
getLogger().error('Failed to activate Auto Debug feature: %s', error)
148-
}
149-
150140
// Handle Amazon Q Extension un-installation.
151141
setupUninstallHandler(VSCODE_EXTENSION_ID.amazonq, context.extension.packageJSON.version, context)
152142

packages/amazonq/src/lsp/autoDebug/activation.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { getLogger } from 'aws-core-vscode/shared'
88
import { AutoDebugCommands } from './commands'
99
import { AutoDebugCodeActionsProvider } from './codeActionsProvider'
1010
import { AutoDebugController } from './controller'
11-
import { registerAutoDebugFeature } from '../client'
1211

1312
/**
1413
* Auto Debug feature activation for Amazon Q
@@ -65,15 +64,24 @@ export class AutoDebugFeature implements vscode.Disposable {
6564
}
6665

6766
/**
68-
* Factory function to activate auto debug feature
67+
* Factory function to activate auto debug feature with LSP client
6968
* This is the main entry point for activating auto debug
7069
*/
71-
export async function activateAutoDebug(context: vscode.ExtensionContext): Promise<AutoDebugFeature> {
70+
export async function activateAutoDebug(
71+
context: vscode.ExtensionContext,
72+
client?: any,
73+
encryptionKey?: Buffer
74+
): Promise<AutoDebugFeature> {
7275
const feature = new AutoDebugFeature(context)
7376
await feature.activate()
7477

75-
// Register the feature with the module-level registry
76-
registerAutoDebugFeature(feature)
78+
// If LSP client is provided, connect it immediately
79+
if (client) {
80+
const controller = feature.getController()
81+
if (controller) {
82+
controller.setLanguageClient(client)
83+
}
84+
}
7785

7886
return feature
7987
}

packages/amazonq/src/lsp/autoDebug/constants.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/amazonq/src/lsp/client.ts

Lines changed: 5 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -53,64 +53,11 @@ import { LineTracker } from '../app/inline/stateTracker/lineTracker'
5353
import { InlineTutorialAnnotation } from '../app/inline/tutorials/inlineTutorialAnnotation'
5454
import { InlineChatTutorialAnnotation } from '../app/inline/tutorials/inlineChatTutorialAnnotation'
5555
import { codeReviewInChat } from '../app/amazonqScan/models/constants'
56-
import { AutoDebugFeature } from '../lsp/autoDebug'
57-
import { autoDebugRetryConfig } from '../lsp/autoDebug/constants'
58-
59-
// Module-level registry for AutoDebug feature
60-
let registeredAutoDebugFeature: AutoDebugFeature | undefined
61-
62-
export function registerAutoDebugFeature(feature: AutoDebugFeature) {
63-
registeredAutoDebugFeature = feature
64-
}
65-
66-
export function getRegisteredAutoDebugFeature(): AutoDebugFeature | undefined {
67-
return registeredAutoDebugFeature
68-
}
56+
import { activateAutoDebug } from './autoDebug/activation'
6957

7058
const localize = nls.loadMessageBundle()
7159
const logger = getLogger('amazonqLsp.lspClient')
7260

73-
interface RetryOptions {
74-
maxAttempts: number
75-
initialDelayMs: number
76-
maxDelayMs: number
77-
backoffMultiplier: number
78-
onRetry?: (attempt: number, error: Error) => void
79-
onFailure?: (attempts: number, lastError: Error) => void
80-
}
81-
82-
/**
83-
* Retry a function with exponential backoff
84-
*/
85-
async function retryWithExponentialBackoff<T>(fn: () => T | Promise<T>, options: RetryOptions): Promise<T> {
86-
const { maxAttempts, initialDelayMs, maxDelayMs, backoffMultiplier, onRetry, onFailure } = options
87-
88-
let lastError: Error
89-
90-
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
91-
try {
92-
return await fn()
93-
} catch (error) {
94-
lastError = error instanceof Error ? error : new Error(String(error))
95-
96-
if (attempt === maxAttempts) {
97-
onFailure?.(attempt, lastError)
98-
throw lastError
99-
}
100-
101-
onRetry?.(attempt, lastError)
102-
103-
// Calculate delay with exponential backoff
104-
const delay = Math.min(initialDelayMs * Math.pow(backoffMultiplier, attempt - 1), maxDelayMs)
105-
106-
await new Promise((resolve) => setTimeout(resolve, delay))
107-
}
108-
}
109-
110-
// This should never be reached, but TypeScript requires it
111-
throw lastError!
112-
}
113-
11461
export function hasGlibcPatch(): boolean {
11562
// Skip GLIBC patching for SageMaker environments
11663
if (isSageMaker()) {
@@ -396,48 +343,12 @@ async function onLanguageServerReady(
396343
await activate(client, encryptionKey, resourcePaths.ui)
397344
}
398345

399-
// Connect AutoDebug feature to the language client
346+
// Activate AutoDebug feature with direct LSP client connection
400347
try {
401-
getLogger('amazonqLsp').debug('Attempting to connect AutoDebug feature to language client')
402-
403-
await retryWithExponentialBackoff(
404-
() => {
405-
const autoDebugFeature = getRegisteredAutoDebugFeature()
406-
if (!autoDebugFeature) {
407-
throw new Error('AutoDebug feature not registered')
408-
}
409-
const controller = autoDebugFeature.getController()
410-
if (!controller) {
411-
throw new Error('AutoDebug controller not available')
412-
}
413-
controller.setLanguageClient(client)
414-
getLogger('amazonqLsp').debug('AutoDebug feature connected successfully')
415-
},
416-
{
417-
maxAttempts: autoDebugRetryConfig.maxAttempts,
418-
initialDelayMs: autoDebugRetryConfig.initialDelayMs,
419-
maxDelayMs: autoDebugRetryConfig.maxDelayMs,
420-
backoffMultiplier: autoDebugRetryConfig.backoffMultiplier,
421-
onRetry: (attempt, error) => {
422-
getLogger('amazonqLsp').debug(
423-
'AutoDebug connection attempt %d failed: %s. Retrying...',
424-
attempt,
425-
error.message
426-
)
427-
},
428-
onFailure: (attempts, lastError) => {
429-
getLogger('amazonqLsp').error(
430-
'AutoDebug feature not found after %d attempts - integration will not work. ' +
431-
'This may indicate that the AutoDebug feature failed to activate or there is a timing issue. ' +
432-
'Last error: %s',
433-
attempts,
434-
lastError.message
435-
)
436-
},
437-
}
438-
)
348+
const autoDebugFeature = await activateAutoDebug(extensionContext, client, encryptionKey)
349+
toDispose.push(autoDebugFeature)
439350
} catch (error) {
440-
getLogger('amazonqLsp').error('Failed to connect AutoDebug feature to language client: %s', error)
351+
getLogger('amazonqLsp').error('Failed to activate AutoDebug feature: %s', error)
441352
}
442353

443354
const refreshInterval = auth.startTokenRefreshInterval(10 * oneSecond)

0 commit comments

Comments
 (0)