@@ -98,12 +98,12 @@ import { setContext } from '../shared/vscode/setContext'
9898import { syncSecurityIssueWebview } from './views/securityIssue/securityIssueWebview'
9999import { detectCommentAboveLine } from '../shared/utilities/commentUtils'
100100import { UserWrittenCodeTracker } from './tracker/userWrittenCodeTracker'
101+ import globals from '../shared/extensionGlobals'
101102
102103let localize : nls . LocalizeFunc
103104
104105export async function activate ( context : ExtContext ) : Promise < void > {
105106 localize = nls . loadMessageBundle ( )
106- const codewhispererSettings = CodeWhispererSettings . instance
107107
108108 // initialize AuthUtil earlier to make sure it can listen to connection change events.
109109 const auth = AuthUtil . instance
@@ -303,16 +303,6 @@ export async function activate(context: ExtContext): Promise<void> {
303303 SecurityIssueProvider . instance . issues . some ( ( group ) => group . issues . some ( ( issue ) => issue . visible ) )
304304 void setContext ( 'aws.amazonq.security.noMatches' , noMatches )
305305 } ) ,
306- // manual trigger
307- Commands . register ( { id : 'aws.amazonq.invokeInlineCompletion' , autoconnect : true } , async ( ) => {
308- invokeRecommendation (
309- vscode . window . activeTextEditor as vscode . TextEditor ,
310- client ,
311- await getConfigEntry ( )
312- ) . catch ( ( e ) => {
313- getLogger ( ) . error ( 'invokeRecommendation failed: %s' , ( e as Error ) . message )
314- } )
315- } ) ,
316306 // select customization
317307 selectCustomizationPrompt . register ( ) ,
318308 // notify new customizations
@@ -480,6 +470,52 @@ export async function activate(context: ExtContext): Promise<void> {
480470 } )
481471 }
482472
473+ void FeatureConfigProvider . instance . fetchFeatureConfigs ( ) . catch ( ( error ) => {
474+ getLogger ( ) . error ( 'Failed to fetch feature configs - %s' , error )
475+ } )
476+
477+ await Commands . tryExecute ( 'aws.amazonq.refreshConnectionCallback' )
478+ container . ready ( )
479+
480+ function setSubscriptionsForCodeIssues ( ) {
481+ context . extensionContext . subscriptions . push (
482+ vscode . workspace . onDidChangeTextDocument ( async ( e ) => {
483+ if ( e . document . uri . scheme !== 'file' ) {
484+ return
485+ }
486+ const diagnostics = securityScanRender . securityDiagnosticCollection ?. get ( e . document . uri )
487+ if ( ! diagnostics || diagnostics . length === 0 ) {
488+ return
489+ }
490+ disposeSecurityDiagnostic ( e )
491+
492+ SecurityIssueProvider . instance . handleDocumentChange ( e )
493+ SecurityIssueTreeViewProvider . instance . refresh ( )
494+ await syncSecurityIssueWebview ( context )
495+
496+ toggleIssuesVisibility ( ( issue , filePath ) =>
497+ filePath !== e . document . uri . fsPath
498+ ? issue . visible
499+ : ! detectCommentAboveLine (
500+ e . document ,
501+ issue . startLine ,
502+ CodeWhispererConstants . amazonqIgnoreNextLine
503+ )
504+ )
505+ } )
506+ )
507+ }
508+ }
509+
510+ export async function activateInlineCompletion ( ) {
511+ const codewhispererSettings = CodeWhispererSettings . instance
512+ const client = new codewhispererClient . DefaultCodeWhispererClient ( )
513+
514+ if ( isInlineCompletionEnabled ( ) ) {
515+ await setSubscriptionsforInlineCompletion ( )
516+ await AuthUtil . instance . setVscodeContextProps ( )
517+ }
518+
483519 function getAutoTriggerStatus ( ) : boolean {
484520 return CodeSuggestionsState . instance . isSuggestionsEnabled ( )
485521 }
@@ -500,17 +536,12 @@ export async function activate(context: ExtContext): Promise<void> {
500536 }
501537 }
502538
503- if ( isInlineCompletionEnabled ( ) ) {
504- await setSubscriptionsforInlineCompletion ( )
505- await AuthUtil . instance . setVscodeContextProps ( )
506- }
507-
508539 async function setSubscriptionsforInlineCompletion ( ) {
509540 RecommendationHandler . instance . subscribeSuggestionCommands ( )
510541 /**
511542 * Automated trigger
512543 */
513- context . extensionContext . subscriptions . push (
544+ globals . context . subscriptions . push (
514545 vscode . window . onDidChangeActiveTextEditor ( async ( editor ) => {
515546 await RecommendationHandler . instance . onEditorChange ( )
516547 } ) ,
@@ -560,42 +591,16 @@ export async function activate(context: ExtContext): Promise<void> {
560591 if ( ! RecommendationHandler . instance . isSuggestionVisible ( ) ) {
561592 await KeyStrokeHandler . instance . processKeyStroke ( e , editor , client , await getConfigEntry ( ) )
562593 }
563- } )
564- )
565- }
566-
567- void FeatureConfigProvider . instance . fetchFeatureConfigs ( ) . catch ( ( error ) => {
568- getLogger ( ) . error ( 'Failed to fetch feature configs - %s' , error )
569- } )
570-
571- await Commands . tryExecute ( 'aws.amazonq.refreshConnectionCallback' )
572- container . ready ( )
573-
574- function setSubscriptionsForCodeIssues ( ) {
575- context . extensionContext . subscriptions . push (
576- vscode . workspace . onDidChangeTextDocument ( async ( e ) => {
577- if ( e . document . uri . scheme !== 'file' ) {
578- return
579- }
580- const diagnostics = securityScanRender . securityDiagnosticCollection ?. get ( e . document . uri )
581- if ( ! diagnostics || diagnostics . length === 0 ) {
582- return
583- }
584- disposeSecurityDiagnostic ( e )
585-
586- SecurityIssueProvider . instance . handleDocumentChange ( e )
587- SecurityIssueTreeViewProvider . instance . refresh ( )
588- await syncSecurityIssueWebview ( context )
589-
590- toggleIssuesVisibility ( ( issue , filePath ) =>
591- filePath !== e . document . uri . fsPath
592- ? issue . visible
593- : ! detectCommentAboveLine (
594- e . document ,
595- issue . startLine ,
596- CodeWhispererConstants . amazonqIgnoreNextLine
597- )
598- )
594+ } ) ,
595+ // manual trigger
596+ Commands . register ( { id : 'aws.amazonq.invokeInlineCompletion' , autoconnect : true } , async ( ) => {
597+ invokeRecommendation (
598+ vscode . window . activeTextEditor as vscode . TextEditor ,
599+ client ,
600+ await getConfigEntry ( )
601+ ) . catch ( ( e ) => {
602+ getLogger ( ) . error ( 'invokeRecommendation failed: %s' , ( e as Error ) . message )
603+ } )
599604 } )
600605 )
601606 }
0 commit comments