66import * as vscode from 'vscode'
77import * as nls from 'vscode-nls'
88import { getTabSizeSetting } from '../shared/utilities/editorUtilities'
9- import { KeyStrokeHandler } from './service/keyStrokeHandler'
109import * as EditorContext from './util/editorContext'
1110import * as CodeWhispererConstants from './models/constants'
1211import {
13- vsCodeState ,
14- ConfigurationEntry ,
1512 CodeSuggestionsState ,
1613 CodeScansState ,
1714 SecurityTreeViewFilterState ,
1815 AggregatedCodeScanIssue ,
1916 CodeScanIssue ,
2017 CodeIssueGroupingStrategyState ,
2118} from './models/model'
22- import { invokeRecommendation } from './commands/invokeRecommendation'
2319import { acceptSuggestion } from './commands/onInlineAcceptance'
2420import { CodeWhispererSettings } from './util/codewhispererSettings'
2521import { ExtContext } from '../shared/extensions'
2622import { CodeWhispererTracker } from './tracker/codewhispererTracker'
2723import * as codewhispererClient from './client/codewhisperer'
28- import { runtimeLanguageContext } from './util/runtimeLanguageContext'
2924import { getLogger } from '../shared/logger'
3025import {
3126 enableCodeSuggestions ,
@@ -59,7 +54,6 @@ import {
5954 showExploreAgentsView ,
6055 showCodeIssueGroupingQuickPick ,
6156} from './commands/basicCommands'
62- import { sleep } from '../shared/utilities/timeoutUtils'
6357import { ReferenceLogViewProvider } from './service/referenceLogViewProvider'
6458import { ReferenceHoverProvider } from './service/referenceHoverProvider'
6559import { ReferenceInlineProvider } from './service/referenceInlineProvider'
@@ -73,7 +67,6 @@ import { RecommendationHandler } from './service/recommendationHandler'
7367import { Commands , registerCommandErrorHandler , registerDeclaredCommands } from '../shared/vscode/commands2'
7468import { InlineCompletionService , refreshStatusBar } from './service/inlineCompletionService'
7569import { isInlineCompletionEnabled } from './util/commonUtil'
76- import { CodeWhispererCodeCoverageTracker } from './tracker/codewhispererCodeCoverageTracker'
7770import { AuthUtil } from './util/authUtil'
7871import { ImportAdderProvider } from './service/importAdderProvider'
7972import { TelemetryHelper } from './util/telemetryHelper'
@@ -97,8 +90,6 @@ import { SecurityIssueTreeViewProvider } from './service/securityIssueTreeViewPr
9790import { setContext } from '../shared/vscode/setContext'
9891import { syncSecurityIssueWebview } from './views/securityIssue/securityIssueWebview'
9992import { detectCommentAboveLine } from '../shared/utilities/commentUtils'
100- import { UserWrittenCodeTracker } from './tracker/userWrittenCodeTracker'
101- import globals from '../shared/extensionGlobals'
10293
10394let localize : nls . LocalizeFunc
10495
@@ -507,105 +498,6 @@ export async function activate(context: ExtContext): Promise<void> {
507498 }
508499}
509500
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-
519- function getAutoTriggerStatus ( ) : boolean {
520- return CodeSuggestionsState . instance . isSuggestionsEnabled ( )
521- }
522-
523- async function getConfigEntry ( ) : Promise < ConfigurationEntry > {
524- const isShowMethodsEnabled : boolean =
525- vscode . workspace . getConfiguration ( 'editor' ) . get ( 'suggest.showMethods' ) || false
526- const isAutomatedTriggerEnabled : boolean = getAutoTriggerStatus ( )
527- const isManualTriggerEnabled : boolean = true
528- const isSuggestionsWithCodeReferencesEnabled = codewhispererSettings . isSuggestionsWithCodeReferencesEnabled ( )
529-
530- // TODO:remove isManualTriggerEnabled
531- return {
532- isShowMethodsEnabled,
533- isManualTriggerEnabled,
534- isAutomatedTriggerEnabled,
535- isSuggestionsWithCodeReferencesEnabled,
536- }
537- }
538-
539- async function setSubscriptionsforInlineCompletion ( ) {
540- RecommendationHandler . instance . subscribeSuggestionCommands ( )
541- /**
542- * Automated trigger
543- */
544- globals . context . subscriptions . push (
545- vscode . window . onDidChangeActiveTextEditor ( async ( editor ) => {
546- await RecommendationHandler . instance . onEditorChange ( )
547- } ) ,
548- vscode . window . onDidChangeWindowState ( async ( e ) => {
549- await RecommendationHandler . instance . onFocusChange ( )
550- } ) ,
551- vscode . window . onDidChangeTextEditorSelection ( async ( e ) => {
552- await RecommendationHandler . instance . onCursorChange ( e )
553- } ) ,
554- vscode . workspace . onDidChangeTextDocument ( async ( e ) => {
555- const editor = vscode . window . activeTextEditor
556- if ( ! editor ) {
557- return
558- }
559- if ( e . document !== editor . document ) {
560- return
561- }
562- if ( ! runtimeLanguageContext . isLanguageSupported ( e . document ) ) {
563- return
564- }
565-
566- CodeWhispererCodeCoverageTracker . getTracker ( e . document . languageId ) ?. countTotalTokens ( e )
567- UserWrittenCodeTracker . instance . onTextDocumentChange ( e )
568- /**
569- * Handle this keystroke event only when
570- * 1. It is not a backspace
571- * 2. It is not caused by CodeWhisperer editing
572- * 3. It is not from undo/redo.
573- */
574- if ( e . contentChanges . length === 0 || vsCodeState . isCodeWhispererEditing ) {
575- return
576- }
577-
578- if ( vsCodeState . lastUserModificationTime ) {
579- TelemetryHelper . instance . setTimeSinceLastModification (
580- performance . now ( ) - vsCodeState . lastUserModificationTime
581- )
582- }
583- vsCodeState . lastUserModificationTime = performance . now ( )
584- /**
585- * Important: Doing this sleep(10) is to make sure
586- * 1. this event is processed by vs code first
587- * 2. editor.selection.active has been successfully updated by VS Code
588- * Then this event can be processed by our code.
589- */
590- await sleep ( CodeWhispererConstants . vsCodeCursorUpdateDelay )
591- if ( ! RecommendationHandler . instance . isSuggestionVisible ( ) ) {
592- await KeyStrokeHandler . instance . processKeyStroke ( e , editor , client , await getConfigEntry ( ) )
593- }
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- } )
604- } )
605- )
606- }
607- }
608-
609501export async function shutdown ( ) {
610502 RecommendationHandler . instance . reportUserDecisions ( - 1 )
611503 await CodeWhispererTracker . getTracker ( ) . shutdown ( )
0 commit comments