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
56 changes: 1 addition & 55 deletions packages/amazonq/src/app/inline/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,27 @@
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 { Commands, getLogger, globals, sleep } from 'aws-core-vscode/shared'
import { globals, sleep } from 'aws-core-vscode/shared'

export async function activate() {
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 Down Expand Up @@ -105,19 +64,6 @@ 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) => {
getLogger().error('invokeRecommendation failed: %s', (e as Error).message)
})
})
)
}
Expand Down
19 changes: 2 additions & 17 deletions packages/amazonq/test/e2e/inline/inline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
toTextEditor,
using,
} from 'aws-core-vscode/test'
import { RecommendationHandler, RecommendationService, session } from 'aws-core-vscode/codewhisperer'
import { session } from 'aws-core-vscode/codewhisperer'
import { Commands, globals, sleep, waitUntil, collectionUtil } from 'aws-core-vscode/shared'
import { loginToIdC } from '../amazonq/utils/setup'

Expand Down Expand Up @@ -54,7 +54,6 @@ describe('Amazon Q Inline', async function () {
const events = getUserTriggerDecision()
console.table({
'telemetry events': JSON.stringify(events),
'recommendation service status': RecommendationService.instance.isRunning,
})
}

Expand All @@ -76,24 +75,10 @@ describe('Amazon Q Inline', async function () {
if (!suggestionShown) {
throw new Error(`Suggestion did not show. Suggestion States: ${JSON.stringify(session.suggestionStates)}`)
}
const suggestionVisible = await waitUntil(
async () => RecommendationHandler.instance.isSuggestionVisible(),
waitOptions
)
if (!suggestionVisible) {
throw new Error(
`Suggestions failed to become visible. Suggestion States: ${JSON.stringify(session.suggestionStates)}`
)
}
console.table({
'suggestions states': JSON.stringify(session.suggestionStates),
'valid recommendation': RecommendationHandler.instance.isValidResponse(),
'recommendation service status': RecommendationService.instance.isRunning,
recommendations: session.recommendations,
})
if (!RecommendationHandler.instance.isValidResponse()) {
throw new Error('Did not find a valid response')
}
}

/**
Expand Down Expand Up @@ -234,7 +219,7 @@ describe('Amazon Q Inline', async function () {

if (name === 'automatic') {
// It should never get triggered since its not a supported file type
assert.deepStrictEqual(RecommendationService.instance.isRunning, false)
// assert.deepStrictEqual(RecommendationService.instance.isRunning, false)
} else {
await getTestWindow().waitForMessage('currently not supported by Amazon Q inline suggestions')
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading