Skip to content

Commit e193d44

Browse files
authored
feat(amazonq): Create a common langauge server downloader (#6148)
## Problem - we need a way to download the manifest and install the correct mynah ui/language server code ## Solution - create a common lsp downloader that flare/workspace lsps can use
1 parent 4d969a6 commit e193d44

File tree

9 files changed

+375
-231
lines changed

9 files changed

+375
-231
lines changed

packages/amazonq/src/lsp/activation.ts

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

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

89
export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
10+
const serverPath = ctx.asAbsolutePath('resources/qdeveloperserver')
11+
const clientPath = ctx.asAbsolutePath('resources/qdeveloperclient')
12+
await new AmazonQLSPDownloader(serverPath, clientPath).tryInstallLsp()
13+
914
/**
10-
* download install and run the language server
15+
* at this point the language server should be installed and available
16+
* at serverPath and mynah ui should be available and serveable at
17+
* clientPath
18+
*
19+
* TODO: actually hook up the language server
1120
*/
1221
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
getLogger,
9+
makeTemporaryToolkitFolder,
10+
tryRemoveFolder,
11+
fs,
12+
Manifest,
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+
54+
// download and extract the business logic
55+
await this.downloadAndExtractServer({
56+
content: server,
57+
installLocation: this.serverPath,
58+
name: 'qdeveloperserver',
59+
tempFolder,
60+
})
61+
62+
// download and extract mynah ui
63+
await this.downloadAndExtractServer({
64+
content: clients,
65+
installLocation: this.clientPath,
66+
name: 'qdeveloperclient',
67+
tempFolder,
68+
})
69+
} finally {
70+
if (tempFolder) {
71+
await tryRemoveFolder(tempFolder)
72+
}
73+
}
74+
75+
return true
76+
}
77+
}

packages/amazonq/test/unit/amazonq/lsp/lspController.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*/
55
import assert from 'assert'
66
import sinon from 'sinon'
7-
import { Content, LspController } from 'aws-core-vscode/amazonq'
7+
import { LspController } from 'aws-core-vscode/amazonq'
88
import { createTestFile } from 'aws-core-vscode/test'
9-
import { fs } from 'aws-core-vscode/shared'
9+
import { fs, Content } from 'aws-core-vscode/shared'
1010

1111
describe('Amazon Q LSP controller', function () {
1212
it('Download mechanism checks against hash, when hash matches', async function () {

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)