Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(amazonq): Create a common langauge server downloader #6148

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/amazonq/src/lsp/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@
*/

import vscode from 'vscode'
import { AmazonQLSPDownloader } from './download'

export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
const serverPath = ctx.asAbsolutePath('resources/qdeveloperserver')
const clientPath = ctx.asAbsolutePath('resources/qdeveloperclient')
await new AmazonQLSPDownloader(serverPath, clientPath).tryInstallLsp()

/**
* download install and run the language server
* at this point the language server should be installed and available
* at serverPath and mynah ui should be available and serveable at
* clientPath
*
* TODO: actually hook up the language server
*/
}
77 changes: 77 additions & 0 deletions packages/amazonq/src/lsp/download.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import {
LspDownloader,
getLogger,
makeTemporaryToolkitFolder,
tryRemoveFolder,
fs,
Manifest,
} from 'aws-core-vscode/shared'

const manifestURL = 'https://aws-toolkit-language-servers.amazonaws.com/codewhisperer/0/manifest.json'

export class AmazonQLSPDownloader extends LspDownloader {
constructor(
private readonly serverPath: string,
private readonly clientPath: string
) {
super(manifestURL)
}

async isLspInstalled(): Promise<boolean> {
return (await fs.exists(this.serverPath)) && (await fs.exists(this.clientPath))
}

async cleanup(): Promise<boolean> {
if (await fs.exists(this.serverPath)) {
await tryRemoveFolder(this.serverPath)
}

if (await fs.exists(this.clientPath)) {
await tryRemoveFolder(this.clientPath)
}

return true
}

async install(manifest: Manifest) {
const server = this.getDependency(manifest, 'servers')
const clients = this.getDependency(manifest, 'clients')
if (!server || !clients) {
getLogger('lsp').info(`Did not find LSP URL for ${process.platform} ${process.arch}`)
return false
}

let tempFolder = undefined

try {
tempFolder = await makeTemporaryToolkitFolder()

// download and extract the business logic
await this.downloadAndExtractServer({
content: server,
installLocation: this.serverPath,
name: 'qdeveloperserver',
tempFolder,
})

// download and extract mynah ui
await this.downloadAndExtractServer({
content: clients,
installLocation: this.clientPath,
name: 'qdeveloperclient',
tempFolder,
})
} finally {
if (tempFolder) {
await tryRemoveFolder(tempFolder)
}
}

return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/
import assert from 'assert'
import sinon from 'sinon'
import { Content, LspController } from 'aws-core-vscode/amazonq'
import { LspController } from 'aws-core-vscode/amazonq'
import { createTestFile } from 'aws-core-vscode/test'
import { fs } from 'aws-core-vscode/shared'
import { fs, Content } from 'aws-core-vscode/shared'

describe('Amazon Q LSP controller', function () {
it('Download mechanism checks against hash, when hash matches', async function () {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/amazonq/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export {
walkthroughInlineSuggestionsExample,
walkthroughSecurityScanExample,
} from './onboardingPage/walkthrough'
export { LspController, Content } from './lsp/lspController'
export { LspController } from './lsp/lspController'
export { LspClient } from './lsp/lspClient'
export { api } from './extApi'
export { AmazonQChatViewProvider } from './webview/webView'
Expand Down
Loading
Loading