Skip to content

Commit

Permalink
feat(amazonq): Create a common langauge server downloader (#6148)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
jpinkney-aws authored Dec 5, 2024
1 parent 4d969a6 commit e193d44
Show file tree
Hide file tree
Showing 9 changed files with 375 additions and 231 deletions.
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
}
}
4 changes: 2 additions & 2 deletions packages/amazonq/test/unit/amazonq/lsp/lspController.test.ts
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

0 comments on commit e193d44

Please sign in to comment.