Skip to content

Commit 2889a10

Browse files
committed
feat(amazonq): Add amazon q language server downloading
1 parent 8e72b6c commit 2889a10

File tree

8 files changed

+347
-229
lines changed

8 files changed

+347
-229
lines changed

packages/amazonq/src/lsp/activation.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@
44
*/
55

66
import vscode from 'vscode'
7+
import { AmazonQLSPDownloader } from './download'
78

89
export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
10+
// use the codewhisperer language server
11+
const serverPath = ctx.asAbsolutePath('dist/amazonqLSP/server.js')
12+
const clientPath = ctx.asAbsolutePath('dist/amazonqLSP/client.js')
13+
await new AmazonQLSPDownloader(serverPath, clientPath).tryInstallLsp()
14+
915
/**
10-
* download install and run the language server
16+
* at this point the language server should be installed and available
17+
* at serverPath and mynah ui should be available and serveable at
18+
* clientPath
19+
*
20+
* TODO: actually hook up the language server
1121
*/
1222
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import {
7+
LSPDownloader,
8+
Manifest,
9+
getLogger,
10+
makeTemporaryToolkitFolder,
11+
tryRemoveFolder,
12+
fs,
13+
} from 'aws-core-vscode/shared'
14+
15+
const manifestURL = 'https://aws-toolkit-language-servers.amazonaws.com/codewhisperer/0/manifest.json'
16+
17+
export class AmazonQLSPDownloader extends LSPDownloader {
18+
constructor(
19+
private readonly serverPath: string,
20+
private readonly clientPath: string
21+
) {
22+
super(manifestURL)
23+
}
24+
25+
async isLspInstalled(): Promise<boolean> {
26+
return (await fs.exists(this.serverPath)) && (await fs.exists(this.clientPath))
27+
}
28+
29+
async cleanup(): Promise<boolean> {
30+
if (await fs.exists(this.serverPath)) {
31+
await tryRemoveFolder(this.serverPath)
32+
}
33+
34+
if (await fs.exists(this.clientPath)) {
35+
await tryRemoveFolder(this.clientPath)
36+
}
37+
38+
return true
39+
}
40+
41+
async install(manifest: Manifest) {
42+
const server = this.getDependency(manifest, 'servers')
43+
const clients = this.getDependency(manifest, 'clients')
44+
if (!server || !clients) {
45+
getLogger('lsp').info(`Did not find LSP URL for ${process.platform} ${process.arch}`)
46+
return false
47+
}
48+
49+
let tempFolder = undefined
50+
51+
try {
52+
tempFolder = await makeTemporaryToolkitFolder()
53+
await this.downloadAndExtractServer(server, this.serverPath, 'qdeveloperserver', tempFolder)
54+
await this.downloadAndExtractServer(clients, this.clientPath, 'qdeveloperclient', tempFolder)
55+
} finally {
56+
// clean up temp folder
57+
if (tempFolder) {
58+
await tryRemoveFolder(tempFolder)
59+
}
60+
}
61+
62+
return true
63+
}
64+
}

packages/core/src/amazonq/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export {
1515
walkthroughInlineSuggestionsExample,
1616
walkthroughSecurityScanExample,
1717
} from './onboardingPage/walkthrough'
18-
export { LspController, Content } from './lsp/lspController'
18+
export { LspController } from './lsp/lspController'
1919
export { LspClient } from './lsp/lspClient'
2020
export { api } from './extApi'
2121
export { AmazonQChatViewProvider } from './webview/webView'

0 commit comments

Comments
 (0)