Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 63 additions & 4 deletions packages/amazonq/src/app/inline/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,68 @@
import vscode from 'vscode'
import {
AuthUtil,
CodeSuggestionsState,
CodeWhispererCodeCoverageTracker,
CodeWhispererConstants,
CodeWhispererSettings,
ConfigurationEntry,
DefaultCodeWhispererClient,
invokeRecommendation,
isInlineCompletionEnabled,
KeyStrokeHandler,
RecommendationHandler,
runtimeLanguageContext,
TelemetryHelper,
UserWrittenCodeTracker,
vsCodeState,
} from 'aws-core-vscode/codewhisperer'
import { globals, sleep } from 'aws-core-vscode/shared'
import { Commands, getLogger, globals, sleep } from 'aws-core-vscode/shared'

export async function activate() {
if (isInlineCompletionEnabled()) {
// Debugging purpose: only initialize NextEditPredictionPanel when development
// NextEditPredictionPanel.getInstance()
const codewhispererSettings = CodeWhispererSettings.instance
const client = new DefaultCodeWhispererClient()

if (isInlineCompletionEnabled()) {
await setSubscriptionsforInlineCompletion()
await AuthUtil.instance.setVscodeContextProps()
}

function getAutoTriggerStatus(): boolean {
return CodeSuggestionsState.instance.isSuggestionsEnabled()
}

async function getConfigEntry(): Promise<ConfigurationEntry> {
const isShowMethodsEnabled: boolean =
vscode.workspace.getConfiguration('editor').get('suggest.showMethods') || false
const isAutomatedTriggerEnabled: boolean = getAutoTriggerStatus()
const isManualTriggerEnabled: boolean = true
const isSuggestionsWithCodeReferencesEnabled = codewhispererSettings.isSuggestionsWithCodeReferencesEnabled()

// TODO:remove isManualTriggerEnabled
return {
isShowMethodsEnabled,
isManualTriggerEnabled,
isAutomatedTriggerEnabled,
isSuggestionsWithCodeReferencesEnabled,
}
}

async function setSubscriptionsforInlineCompletion() {
RecommendationHandler.instance.subscribeSuggestionCommands()

/**
* Automated trigger
*/
globals.context.subscriptions.push(
vscode.window.onDidChangeActiveTextEditor(async (editor) => {
await RecommendationHandler.instance.onEditorChange()
}),
vscode.window.onDidChangeWindowState(async (e) => {
await RecommendationHandler.instance.onFocusChange()
}),
vscode.window.onDidChangeTextEditorSelection(async (e) => {
await RecommendationHandler.instance.onCursorChange(e)
}),
vscode.workspace.onDidChangeTextDocument(async (e) => {
const editor = vscode.window.activeTextEditor
if (!editor) {
Expand All @@ -40,6 +80,7 @@ export async function activate() {
return
}

CodeWhispererCodeCoverageTracker.getTracker(e.document.languageId)?.countTotalTokens(e)
UserWrittenCodeTracker.instance.onTextDocumentChange(e)
/**
* Handle this keystroke event only when
Expand All @@ -51,6 +92,11 @@ export async function activate() {
return
}

if (vsCodeState.lastUserModificationTime) {
TelemetryHelper.instance.setTimeSinceLastModification(
performance.now() - vsCodeState.lastUserModificationTime
)
}
vsCodeState.lastUserModificationTime = performance.now()
/**
* Important: Doing this sleep(10) is to make sure
Expand All @@ -59,6 +105,19 @@ export async function activate() {
* Then this event can be processed by our code.
*/
await sleep(CodeWhispererConstants.vsCodeCursorUpdateDelay)
if (!RecommendationHandler.instance.isSuggestionVisible()) {
await KeyStrokeHandler.instance.processKeyStroke(e, editor, client, await getConfigEntry())
}
}),
// manual trigger
Commands.register({ id: 'aws.amazonq.invokeInlineCompletion', autoconnect: true }, async () => {
invokeRecommendation(
vscode.window.activeTextEditor as vscode.TextEditor,
client,
await getConfigEntry()
).catch((e: Error) => {
getLogger().error('invokeRecommendation failed: %s', (e as Error).message)
})
})
)
}
Expand Down
15 changes: 12 additions & 3 deletions packages/amazonq/src/lsp/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
} from 'aws-core-vscode/shared'
import { processUtils } from 'aws-core-vscode/shared'
import { activate } from './chat/activation'
import { activate as activateInline } from '../app/inline/activation'
import { AmazonQResourcePaths } from './lspInstaller'
import { ConfigSection, isValidConfigSection, pushConfigUpdate, toAmazonQLSPLogLevel } from './config'
import { activate as activateInlineChat } from '../inlineChat/activation'
Expand Down Expand Up @@ -338,8 +339,17 @@ async function onLanguageServerReady(
// tutorial for inline chat
const inlineChatTutorialAnnotation = new InlineChatTutorialAnnotation(inlineTutorialAnnotation)

const inlineManager = new InlineCompletionManager(client, sessionManager, lineTracker, inlineTutorialAnnotation)
inlineManager.registerInlineCompletion()
const enableInlineRollback = false
if (enableInlineRollback) {
// use VSC inline
await activateInline()
} else {
// use language server for inline completion
const inlineManager = new InlineCompletionManager(client, sessionManager, lineTracker, inlineTutorialAnnotation)
inlineManager.registerInlineCompletion()
toDispose.push(inlineManager)
}

activateInlineChat(extensionContext, client, encryptionKey, inlineChatTutorialAnnotation)

if (Experiments.instance.get('amazonqChatLSP', true)) {
Expand All @@ -354,7 +364,6 @@ async function onLanguageServerReady(
await initializeLanguageServerConfiguration(client, 'startup')

toDispose.push(
inlineManager,
Commands.register('aws.amazonq.showPrev', async () => {
await sessionManager.maybeRefreshSessionUx()
await vscode.commands.executeCommand('editor.action.inlineSuggest.showPrevious')
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/codewhisperer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ export * from './util/gitUtil'
export * from './ui/prompters'
export { UserWrittenCodeTracker } from './tracker/userWrittenCodeTracker'
export { RegionProfileManager, defaultServiceConfig } from './region/regionProfileManager'
export { DocumentChangedSource, KeyStrokeHandler, DefaultDocumentChangedType } from './service/keyStrokeHandler'
export { RecommendationHandler } from './service/recommendationHandler'
export { CodeWhispererCodeCoverageTracker } from './tracker/codewhispererCodeCoverageTracker'
export { invokeRecommendation } from './commands/invokeRecommendation'
Loading