Skip to content

Commit 5d6512f

Browse files
authored
feat(amazonq): Use codewhisperer language server for completions (#6158)
## Problem - vscode doesn't have the codewhisperer lsp for completion requests ## Solution - use the codewhisperer lsp when `"aws.experiments": { "amazonqLSP": true },` --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 39817f3 commit 5d6512f

File tree

8 files changed

+785
-10
lines changed

8 files changed

+785
-10
lines changed

package-lock.json

Lines changed: 101 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import {
7+
CancellationToken,
8+
Uri,
9+
Webview,
10+
WebviewView,
11+
WebviewViewProvider,
12+
WebviewViewResolveContext,
13+
window,
14+
} from 'vscode'
15+
import { LanguageClient } from 'vscode-languageclient'
16+
import { globals } from 'aws-core-vscode/shared'
17+
import { handle } from './handler'
18+
19+
export class AmazonQChatViewProvider implements WebviewViewProvider {
20+
public static readonly viewType = 'aws.AmazonQChatView'
21+
22+
constructor(private readonly client: LanguageClient) {}
23+
24+
public async resolveWebviewView(
25+
webviewView: WebviewView,
26+
context: WebviewViewResolveContext,
27+
_token: CancellationToken
28+
) {
29+
webviewView.webview.options = {
30+
enableScripts: true,
31+
localResourceRoots: [Uri.joinPath(globals.context.extensionUri, 'resources', 'qdeveloperclient')],
32+
}
33+
34+
webviewView.webview.html = this.getWebviewContent(webviewView.webview, globals.context.extensionUri)
35+
handle(this.client, webviewView.webview)
36+
}
37+
38+
private getWebviewContent(webView: Webview, extensionUri: Uri) {
39+
return `
40+
<!DOCTYPE html>
41+
<html lang="en">
42+
<head>
43+
<meta charset="UTF-8">
44+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
45+
<title>Chat UI</title>
46+
${this.generateCss()}
47+
</head>
48+
<body>
49+
${this.generateJS(webView, extensionUri)}
50+
</body>
51+
</html>`
52+
}
53+
54+
private generateCss() {
55+
return `
56+
<style>
57+
body,
58+
html {
59+
background-color: var(--mynah-color-bg);
60+
color: var(--mynah-color-text-default);
61+
height: 100%;
62+
width: 100%;
63+
overflow: hidden;
64+
margin: 0;
65+
padding: 0;
66+
}
67+
</style>`
68+
}
69+
70+
private generateJS(webView: Webview, extensionUri: Uri): string {
71+
const assetsPath = Uri.joinPath(extensionUri)
72+
const chatUri = Uri.joinPath(assetsPath, 'resources', 'qdeveloperclient', 'amazonq-ui.js')
73+
74+
const entrypoint = webView.asWebviewUri(chatUri)
75+
76+
return `
77+
<script type="text/javascript" src="${entrypoint.toString()}" defer onload="init()"></script>
78+
<script type="text/javascript">
79+
const init = () => {
80+
amazonQChat.createChat(acquireVsCodeApi());
81+
}
82+
</script>
83+
`
84+
}
85+
}
86+
87+
export function registerChat(client: LanguageClient) {
88+
const panel = new AmazonQChatViewProvider(client)
89+
window.registerWebviewViewProvider(AmazonQChatViewProvider.viewType, panel, {
90+
webviewOptions: {
91+
retainContextWhenHidden: true,
92+
},
93+
})
94+
}

0 commit comments

Comments
 (0)