Skip to content

Commit c7cb3c9

Browse files
committed
refactor(amazonq): expose lsp inline completion as an experiment
1 parent c3ea31d commit c7cb3c9

File tree

5 files changed

+35
-16
lines changed

5 files changed

+35
-16
lines changed

packages/amazonq/src/extension.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ export async function activateAmazonQCommon(context: vscode.ExtensionContext, is
120120
await activateCodeWhisperer(extContext as ExtContext)
121121
if (Experiments.instance.get('amazonqLSP', false)) {
122122
await activateAmazonqLsp(context)
123-
} else {
123+
}
124+
125+
if (!Experiments.instance.get('amazonqLSPInline', false)) {
124126
await activateInlineCompletion()
125127
}
126128

@@ -157,7 +159,7 @@ export async function activateAmazonQCommon(context: vscode.ExtensionContext, is
157159

158160
context.subscriptions.push(
159161
Experiments.instance.onDidChange(async (event) => {
160-
if (event.key === 'amazonqLSP' || event.key === 'amazonqChatLSP') {
162+
if (event.key === 'amazonqLSP' || event.key === 'amazonqChatLSP' || event.key === 'amazonqLSPInline') {
161163
await vscode.window
162164
.showInformationMessage(
163165
'Amazon Q LSP setting has changed. Reload VS Code for the changes to take effect.',

packages/amazonq/src/lsp/activation.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,14 @@
66
import vscode from 'vscode'
77
import { startLanguageServer } from './client'
88
import { AmazonQLspInstaller } from './lspInstaller'
9-
import { Commands, lspSetupStage, ToolkitError } from 'aws-core-vscode/shared'
9+
import { lspSetupStage, ToolkitError } from 'aws-core-vscode/shared'
1010

1111
export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
1212
try {
1313
await lspSetupStage('all', async () => {
1414
const installResult = await new AmazonQLspInstaller().resolve()
1515
await lspSetupStage('launch', async () => await startLanguageServer(ctx, installResult.resourcePaths))
1616
})
17-
ctx.subscriptions.push(
18-
Commands.register({ id: 'aws.amazonq.invokeInlineCompletion', autoconnect: true }, async () => {
19-
await vscode.commands.executeCommand('editor.action.inlineSuggest.trigger')
20-
}),
21-
vscode.workspace.onDidCloseTextDocument(async () => {
22-
await vscode.commands.executeCommand('aws.amazonq.rejectCodeSuggestion')
23-
})
24-
)
2517
} catch (err) {
2618
const e = err as ToolkitError
2719
void vscode.window.showInformationMessage(`Unable to launch amazonq language server: ${e.message}`)

packages/amazonq/src/lsp/client.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ import { InlineCompletionManager } from '../app/inline/completion'
1111
import { AmazonQLspAuth, encryptionKey, notificationTypes } from './auth'
1212
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
1313
import { ConnectionMetadata } from '@aws/language-server-runtimes/protocol'
14-
import { Settings, oidcClientName, createServerOptions, globals, Experiments, getLogger } from 'aws-core-vscode/shared'
14+
import {
15+
Settings,
16+
oidcClientName,
17+
createServerOptions,
18+
globals,
19+
Experiments,
20+
getLogger,
21+
Commands,
22+
} from 'aws-core-vscode/shared'
1523
import { activate } from './chat/activation'
1624
import { AmazonQResourcePaths } from './lspInstaller'
1725

@@ -94,8 +102,21 @@ export async function startLanguageServer(
94102

95103
return client.onReady().then(async () => {
96104
await auth.init()
97-
const inlineManager = new InlineCompletionManager(client)
98-
inlineManager.registerInlineCompletion()
105+
106+
if (Experiments.instance.get('amazonqLSPInline', false)) {
107+
const inlineManager = new InlineCompletionManager(client)
108+
inlineManager.registerInlineCompletion()
109+
toDispose.push(
110+
inlineManager,
111+
Commands.register({ id: 'aws.amazonq.invokeInlineCompletion', autoconnect: true }, async () => {
112+
await vscode.commands.executeCommand('editor.action.inlineSuggest.trigger')
113+
}),
114+
vscode.workspace.onDidCloseTextDocument(async () => {
115+
await vscode.commands.executeCommand('aws.amazonq.rejectCodeSuggestion')
116+
})
117+
)
118+
}
119+
99120
if (Experiments.instance.get('amazonqChatLSP', false)) {
100121
activate(client, encryptionKey, resourcePaths.mynahUI)
101122
}
@@ -125,8 +146,7 @@ export async function startLanguageServer(
125146
}),
126147
AuthUtil.instance.auth.onDidDeleteConnection(async () => {
127148
client.sendNotification(notificationTypes.deleteBearerToken.method)
128-
}),
129-
inlineManager
149+
})
130150
)
131151
})
132152
}

packages/core/src/shared/settings-toolkit.gen.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const toolkitSettings = {
4343
"aws.experiments": {
4444
"jsonResourceModification": {},
4545
"amazonqLSP": {},
46+
"amazonqLSPInline": {},
4647
"amazonqChatLSP": {}
4748
},
4849
"aws.resources.enabledResources": {},

packages/toolkit/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@
251251
"type": "boolean",
252252
"default": false
253253
},
254+
"amazonqLSPInline": {
255+
"type": "boolean",
256+
"default": false
257+
},
254258
"amazonqChatLSP": {
255259
"type": "boolean",
256260
"default": false

0 commit comments

Comments
 (0)