Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 11 additions & 1 deletion packages/amazonq/src/lsp/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@
*/

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

export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
const serverPath = ctx.asAbsolutePath(path.join('resources', 'qdeveloperserver'))
const clientPath = ctx.asAbsolutePath(path.join('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,
Manifest,
getLogger,
makeTemporaryToolkitFolder,
tryRemoveFolder,
fs,
} 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
Loading