|
| 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 | +} |
0 commit comments