Skip to content

Commit 836ac80

Browse files
committed
merge
2 parents 5d4b6d9 + f9433f6 commit 836ac80

File tree

20 files changed

+167
-92
lines changed

20 files changed

+167
-92
lines changed

docs/lsp.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,16 @@ sequenceDiagram
4545
npm run package
4646
```
4747
to get the project setup
48-
3. Uncomment the `__AMAZONQLSP_PATH` variable in `amazonq/.vscode/launch.json` Extension configuration
49-
4. Use the `Launch LSP with Debugging` configuration and set breakpoints in VSCode or the language server
48+
3. Enable the lsp experiment:
49+
```
50+
"aws.experiments": {
51+
"amazonqLSP": true,
52+
"amazonqLSPInline": true, // optional: enables inline completion from flare
53+
"amazonqLSPChat": true // optional: enables chat from flare
54+
}
55+
```
56+
4. Uncomment the `__AMAZONQLSP_PATH` variable in `amazonq/.vscode/launch.json` Extension configuration
57+
5. Use the `Launch LSP with Debugging` configuration and set breakpoints in VSCode or the language server
5058
5159
## Amazon Q Inline Activation
5260

package-lock.json

Lines changed: 24 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Amazon Q chat: `@prompts` not added to context"
4+
}

packages/amazonq/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@
119119
"ssoCacheError": {
120120
"type": "boolean",
121121
"default": false
122+
},
123+
"amazonQLspManifestMessage": {
124+
"type": "boolean",
125+
"default": false
126+
},
127+
"amazonQWorkspaceLspManifestMessage": {
128+
"type": "boolean",
129+
"default": false
122130
}
123131
},
124132
"additionalProperties": false

packages/amazonq/src/app/inline/completion.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
ReferenceHoverProvider,
3030
ReferenceInlineProvider,
3131
ReferenceLogViewProvider,
32+
ImportAdderProvider,
3233
} from 'aws-core-vscode/codewhisperer'
3334

3435
export class InlineCompletionManager implements Disposable {
@@ -66,6 +67,7 @@ export class InlineCompletionManager implements Disposable {
6667
item: InlineCompletionItemWithReferences,
6768
editor: TextEditor,
6869
requestStartTime: number,
70+
startLine: number,
6971
firstCompletionDisplayLatency?: number
7072
) => {
7173
// TODO: also log the seen state for other suggestions in session
@@ -96,6 +98,9 @@ export class InlineCompletionManager implements Disposable {
9698
ReferenceLogViewProvider.instance.addReferenceLog(referenceLog)
9799
ReferenceHoverProvider.instance.addCodeReferences(item.insertText as string, item.references)
98100
}
101+
if (item.mostRelevantMissingImports?.length) {
102+
await ImportAdderProvider.instance.onAcceptRecommendation(editor, item, startLine)
103+
}
99104
}
100105
commands.registerCommand('aws.amazonq.acceptInline', onInlineAcceptance)
101106

@@ -200,6 +205,7 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
200205
item,
201206
editor,
202207
session.requestStartTime,
208+
position.line,
203209
session.firstCompletionDisplayLatency,
204210
],
205211
}
@@ -208,6 +214,7 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
208214
item.insertText as string,
209215
item.references
210216
)
217+
ImportAdderProvider.instance.onShowRecommendation(document, position.line, item)
211218
}
212219
return items as InlineCompletionItem[]
213220
}

packages/amazonq/src/extension.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,14 @@ export async function activateAmazonQCommon(context: vscode.ExtensionContext, is
118118
}
119119
// This contains every lsp agnostic things (auth, security scan, code scan)
120120
await activateCodeWhisperer(extContext as ExtContext)
121-
// start Amazon Q LSP for everyone
122-
await activateAmazonqLsp(context)
123-
await activateInlineCompletion()
121+
if (Experiments.instance.get('amazonqLSP', false)) {
122+
await activateAmazonqLsp(context)
123+
}
124+
125+
if (!Experiments.instance.get('amazonqLSPInline', false)) {
126+
await activateInlineCompletion()
127+
}
128+
124129
// Generic extension commands
125130
registerGenericCommands(context, amazonQContextPrefix)
126131

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

155160
context.subscriptions.push(
156161
Experiments.instance.onDidChange(async (event) => {
157-
if (event.key === 'amazonqLSP' || event.key === 'amazonqChatLSP') {
162+
if (event.key === 'amazonqLSP' || event.key === 'amazonqChatLSP' || event.key === 'amazonqLSPInline') {
158163
await vscode.window
159164
.showInformationMessage(
160165
'Amazon Q LSP setting has changed. Reload VS Code for the changes to take effect.',

packages/amazonq/src/lsp/activation.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
1414
const installResult = await new AmazonQLspInstaller().resolve()
1515
await lspSetupStage('launch', async () => await startLanguageServer(ctx, installResult.resourcePaths))
1616
})
17-
// Do not enable inline code path in LSP from 04/16 to 06/30.
18-
// Workspace context needs to use IDE inline completion code path for AB test
19-
// ctx.subscriptions.push(
20-
// Commands.register({ id: 'aws.amazonq.invokeInlineCompletion', autoconnect: true }, async () => {
21-
// await vscode.commands.executeCommand('editor.action.inlineSuggest.trigger')
22-
// }),
23-
// vscode.workspace.onDidCloseTextDocument(async () => {
24-
// await vscode.commands.executeCommand('aws.amazonq.rejectCodeSuggestion')
25-
// })
26-
// )
2717
} catch (err) {
2818
const e = err as ToolkitError
2919
void vscode.window.showInformationMessage(`Unable to launch amazonq language server: ${e.message}`)

packages/amazonq/src/lsp/chat/webviewProvider.ts

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
Uri,
1414
} from 'vscode'
1515
import { LanguageServerResolver } from 'aws-core-vscode/shared'
16+
import { QuickActionCommandGroup } from '@aws/mynah-ui'
1617

1718
export class AmazonQChatViewProvider implements WebviewViewProvider {
1819
public static readonly viewType = 'aws.amazonq.AmazonQChatView'
@@ -21,6 +22,24 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {
2122

2223
webview: Webview | undefined
2324

25+
private readonly quickActionCommands: QuickActionCommandGroup[] = [
26+
{
27+
groupName: 'Quick Actions',
28+
commands: [
29+
{
30+
command: '/help',
31+
icon: 'help',
32+
description: 'Learn more about Amazon Q',
33+
},
34+
{
35+
command: '/clear',
36+
icon: 'trash',
37+
description: 'Clear this session',
38+
},
39+
],
40+
},
41+
]
42+
2443
constructor(private readonly mynahUIPath: string) {}
2544

2645
public resolveWebviewView(webviewView: WebviewView, context: WebviewViewResolveContext, _token: CancellationToken) {
@@ -34,40 +53,40 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {
3453
}
3554

3655
const uiPath = webviewView.webview.asWebviewUri(Uri.parse(this.mynahUIPath)).toString()
37-
webviewView.webview.html = getWebviewContent(uiPath)
56+
webviewView.webview.html = this.getWebviewContent(uiPath)
3857

3958
this.onDidResolveWebviewEmitter.fire()
4059
}
41-
}
4260

43-
function getWebviewContent(mynahUIPath: string) {
44-
return `
45-
<!DOCTYPE html>
46-
<html lang="en">
47-
<head>
48-
<meta charset="UTF-8">
49-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
50-
<title>Chat</title>
51-
<style>
52-
body,
53-
html {
54-
background-color: var(--mynah-color-bg);
55-
color: var(--mynah-color-text-default);
56-
height: 100%;
57-
width: 100%;
58-
overflow: hidden;
59-
margin: 0;
60-
padding: 0;
61-
}
62-
</style>
63-
</head>
64-
<body>
65-
<script type="text/javascript" src="${mynahUIPath.toString()}" defer onload="init()"></script>
66-
<script type="text/javascript">
67-
const init = () => {
68-
amazonQChat.createChat(acquireVsCodeApi(), {disclaimerAcknowledged: false});
69-
}
70-
</script>
71-
</body>
72-
</html>`
61+
private getWebviewContent(mynahUIPath: string) {
62+
return `
63+
<!DOCTYPE html>
64+
<html lang="en">
65+
<head>
66+
<meta charset="UTF-8">
67+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
68+
<title>Chat</title>
69+
<style>
70+
body,
71+
html {
72+
background-color: var(--mynah-color-bg);
73+
color: var(--mynah-color-text-default);
74+
height: 100%;
75+
width: 100%;
76+
overflow: hidden;
77+
margin: 0;
78+
padding: 0;
79+
}
80+
</style>
81+
</head>
82+
<body>
83+
<script type="text/javascript" src="${mynahUIPath.toString()}" defer onload="init()"></script>
84+
<script type="text/javascript">
85+
const init = () => {
86+
amazonQChat.createChat(acquireVsCodeApi(), { disclaimerAcknowledged: false, quickActionCommands: ${JSON.stringify(this.quickActionCommands)}});
87+
}
88+
</script>
89+
</body>
90+
</html>`
91+
}
7392
}

packages/amazonq/src/lsp/client.ts

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,18 @@ import {
2121
ResponseMessage,
2222
WorkspaceFolder,
2323
} from '@aws/language-server-runtimes/protocol'
24-
import { Settings, oidcClientName, createServerOptions, globals, Experiments, getLogger } from 'aws-core-vscode/shared'
24+
import {
25+
Settings,
26+
oidcClientName,
27+
createServerOptions,
28+
globals,
29+
Experiments,
30+
getLogger,
31+
Commands,
32+
} from 'aws-core-vscode/shared'
2533
import { activate } from './chat/activation'
2634
import { AmazonQResourcePaths } from './lspInstaller'
35+
import { InlineCompletionManager } from '../app/inline/completion'
2736

2837
const localize = nls.loadMessageBundle()
2938

@@ -103,21 +112,33 @@ export async function startLanguageServer(
103112
const auth = new AmazonQLspAuth(client)
104113

105114
return client.onReady().then(async () => {
106-
await auth.init()
107-
//const inlineManager = new InlineCompletionManager(client)
108-
//inlineManager.registerInlineCompletion()
109-
if (Experiments.instance.get('amazonqChatLSP', false)) {
110-
activate(client, encryptionKey, resourcePaths.mynahUI)
111-
}
112-
113-
// Request handler for when the server wants to know about the clients auth connnection
115+
// Request handler for when the server wants to know about the clients auth connnection. Must be registered before the initial auth init call
114116
client.onRequest<ConnectionMetadata, Error>(notificationTypes.getConnectionMetadata.method, () => {
115117
return {
116118
sso: {
117119
startUrl: AuthUtil.instance.auth.startUrl,
118120
},
119121
}
120122
})
123+
await auth.init()
124+
125+
if (Experiments.instance.get('amazonqLSPInline', false)) {
126+
const inlineManager = new InlineCompletionManager(client)
127+
inlineManager.registerInlineCompletion()
128+
toDispose.push(
129+
inlineManager,
130+
Commands.register({ id: 'aws.amazonq.invokeInlineCompletion', autoconnect: true }, async () => {
131+
await vscode.commands.executeCommand('editor.action.inlineSuggest.trigger')
132+
}),
133+
vscode.workspace.onDidCloseTextDocument(async () => {
134+
await vscode.commands.executeCommand('aws.amazonq.rejectCodeSuggestion')
135+
})
136+
)
137+
}
138+
139+
if (Experiments.instance.get('amazonqChatLSP', false)) {
140+
activate(client, encryptionKey, resourcePaths.mynahUI)
141+
}
121142

122143
// Temporary code for pen test. Will be removed when we switch to the real flare auth
123144
const authInterval = setInterval(async () => {

0 commit comments

Comments
 (0)