Skip to content

Commit 6cf9dce

Browse files
committed
save
1 parent eb5a429 commit 6cf9dce

File tree

15 files changed

+912
-983
lines changed

15 files changed

+912
-983
lines changed

packages/amazonq/src/lsp/activation.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@
44
*/
55

66
import vscode from 'vscode'
7-
import path from 'path'
8-
import { AmazonQLSPDownloader } from './download'
97
import { startLanguageServer } from './client'
8+
import { AmazonQLSPInstaller } from './lspInstaller'
9+
import { ToolkitError } from 'aws-core-vscode/shared'
1010

1111
export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
12-
const serverPath = ctx.asAbsolutePath('resources/qdeveloperserver')
13-
const clientPath = ctx.asAbsolutePath('resources/qdeveloperclient')
14-
const installedAndReady = await new AmazonQLSPDownloader(serverPath, clientPath).tryInstallLsp()
15-
if (installedAndReady) {
16-
await startLanguageServer(
17-
ctx,
18-
process.env.AWS_LANGUAGE_SERVER_OVERRIDE ?? path.join(serverPath, 'aws-lsp-codewhisperer.js')
19-
)
12+
try {
13+
const result = await new AmazonQLSPInstaller().install()
14+
await startLanguageServer(ctx, result.location)
15+
} catch (err) {
16+
const e = err as ToolkitError
17+
void vscode.window.showInformationMessage(`Unable to launch amazonq language server: ${e.message}`)
2018
}
2119
}

packages/amazonq/src/lsp/download.ts

Lines changed: 0 additions & 90 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import * as vscode from 'vscode'
7+
import { ManifestManager, LspManager, LspInstaller, LspResult } from 'aws-core-vscode/shared'
8+
9+
const manifestURL = 'https://aws-toolkit-language-servers.amazonaws.com/codewhisperer/0/manifest.json'
10+
11+
export class AmazonQLSPInstaller implements LspInstaller {
12+
async install(): Promise<LspResult> {
13+
const overrideLocation = process.env.AWS_LANGUAGE_SERVER_OVERRIDE
14+
if (overrideLocation) {
15+
void vscode.window.showInformationMessage(`Using language server override location: ${overrideLocation}`)
16+
return {
17+
assetDirectory: overrideLocation,
18+
location: 'override',
19+
version: '0.0.0',
20+
}
21+
}
22+
23+
const manifestManager = new ManifestManager(manifestURL, 'amazonq')
24+
const manifest = await manifestManager.getManifest()
25+
26+
const lspManager = new LspManager(manifest, '', '')
27+
const downloadResult = lspManager.download()
28+
29+
// TODO Cleanup old versions of language servers
30+
return downloadResult
31+
}
32+
}

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

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,52 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
import assert from 'assert'
6-
import sinon from 'sinon'
7-
import { LspController } from 'aws-core-vscode/amazonq'
8-
import { createTestFile } from 'aws-core-vscode/test'
9-
import { fs, Content } from 'aws-core-vscode/shared'
105

11-
describe('Amazon Q LSP controller', function () {
12-
it('Download mechanism checks against hash, when hash matches', async function () {
13-
const content = {
14-
filename: 'qserver-linux-x64.zip',
15-
url: 'https://x/0.0.6/qserver-linux-x64.zip',
16-
hashes: [
17-
'sha384:768412320f7b0aa5812fce428dc4706b3cae50e02a64caa16a782249bfe8efc4b7ef1ccb126255d196047dfedf17a0a9',
18-
],
19-
bytes: 512,
20-
} as Content
21-
const lspController = new LspController()
22-
sinon.stub(lspController, '_download')
23-
const mockFileName = 'test_case_1.zip'
24-
const mockDownloadFile = await createTestFile(mockFileName)
25-
await fs.writeFile(mockDownloadFile.fsPath, 'test')
26-
const result = await lspController.downloadAndCheckHash(mockDownloadFile.fsPath, content)
27-
assert.strictEqual(result, true)
28-
})
6+
// TODO re-enable this file once amazon q context server is migrated to the new interface
7+
// import assert from 'assert'
8+
// import sinon from 'sinon'
9+
// import { LspController } from 'aws-core-vscode/amazonq'
10+
// import { createTestFile } from 'aws-core-vscode/test'
11+
// import { fs, Content } from 'aws-core-vscode/shared'
2912

30-
it('Download mechanism checks against hash, when hash does not match', async function () {
31-
const content = {
32-
filename: 'qserver-linux-x64.zip',
33-
url: 'https://x/0.0.6/qserver-linux-x64.zip',
34-
hashes: [
35-
'sha384:38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b',
36-
],
37-
bytes: 512,
38-
} as Content
39-
const lspController = new LspController()
40-
sinon.stub(lspController, '_download')
41-
const mockFileName = 'test_case_2.zip'
42-
const mockDownloadFile = await createTestFile(mockFileName)
43-
await fs.writeFile(mockDownloadFile.fsPath, 'file_content')
44-
const result = await lspController.downloadAndCheckHash(mockDownloadFile.fsPath, content)
45-
assert.strictEqual(result, false)
46-
})
13+
// describe('Amazon Q LSP controller', function () {
14+
// it('Download mechanism checks against hash, when hash matches', async function () {
15+
// const content = {
16+
// filename: 'qserver-linux-x64.zip',
17+
// url: 'https://x/0.0.6/qserver-linux-x64.zip',
18+
// hashes: [
19+
// 'sha384:768412320f7b0aa5812fce428dc4706b3cae50e02a64caa16a782249bfe8efc4b7ef1ccb126255d196047dfedf17a0a9',
20+
// ],
21+
// bytes: 512,
22+
// } as Content
23+
// const lspController = new LspController()
24+
// sinon.stub(lspController, '_download')
25+
// const mockFileName = 'test_case_1.zip'
26+
// const mockDownloadFile = await createTestFile(mockFileName)
27+
// await fs.writeFile(mockDownloadFile.fsPath, 'test')
28+
// const result = await lspController.downloadAndCheckHash(mockDownloadFile.fsPath, content)
29+
// assert.strictEqual(result, true)
30+
// })
4731

48-
afterEach(() => {
49-
sinon.restore()
50-
})
51-
})
32+
// it('Download mechanism checks against hash, when hash does not match', async function () {
33+
// const content = {
34+
// filename: 'qserver-linux-x64.zip',
35+
// url: 'https://x/0.0.6/qserver-linux-x64.zip',
36+
// hashes: [
37+
// 'sha384:38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b',
38+
// ],
39+
// bytes: 512,
40+
// } as Content
41+
// const lspController = new LspController()
42+
// sinon.stub(lspController, '_download')
43+
// const mockFileName = 'test_case_2.zip'
44+
// const mockDownloadFile = await createTestFile(mockFileName)
45+
// await fs.writeFile(mockDownloadFile.fsPath, 'file_content')
46+
// const result = await lspController.downloadAndCheckHash(mockDownloadFile.fsPath, content)
47+
// assert.strictEqual(result, false)
48+
// })
49+
50+
// afterEach(() => {
51+
// sinon.restore()
52+
// })
53+
// })

packages/core/src/amazonq/lsp/lspController.ts

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import { telemetry } from '../../shared/telemetry'
1414
import { isCloud9 } from '../../shared/extensionUtilities'
1515
import globals, { isWeb } from '../../shared/extensionGlobals'
1616
import { isAmazonInternalOs } from '../../shared/vscode/env'
17-
import { LspDownloader, Manifest } from '../../shared/fetchLsp'
1817
import { fs } from '../../shared/fs/fs'
19-
import { makeTemporaryToolkitFolder, tryRemoveFolder } from '../../shared/filesystemUtilities'
18+
import { tryRemoveFolder } from '../../shared/filesystemUtilities'
19+
import { LspInstaller, LspResult } from '../../shared/languageServer/types'
2020

2121
export interface Chunk {
2222
readonly filePath: string
@@ -26,9 +26,9 @@ export interface Chunk {
2626
readonly programmingLanguage?: string
2727
}
2828

29-
const manifestUrl = 'https://aws-toolkit-language-servers.amazonaws.com/q-context/manifest.json'
30-
// this LSP client in Q extension is only going to work with these LSP server versions
31-
const supportedLspServerVersions = ['0.1.32']
29+
// const manifestUrl = 'https://aws-toolkit-language-servers.amazonaws.com/q-context/manifest.json'
30+
// // this LSP client in Q extension is only going to work with these LSP server versions
31+
// const supportedLspServerVersions = ['0.1.32']
3232

3333
const nodeBinName = process.platform === 'win32' ? 'node.exe' : 'node'
3434

@@ -49,7 +49,7 @@ export interface BuildIndexConfig {
4949
* Pre-process the input to Index Files API
5050
* Post-process the output from Query API
5151
*/
52-
export class LspController extends LspDownloader {
52+
export class LspController implements LspInstaller {
5353
static #instance: LspController
5454
private _isIndexingInProgress = false
5555
private serverPath: string
@@ -60,7 +60,6 @@ export class LspController extends LspDownloader {
6060
}
6161

6262
constructor() {
63-
super(manifestUrl, 'qcontextserver', supportedLspServerVersions)
6463
this.serverPath = globals.context.asAbsolutePath(path.join('resources', 'qserver'))
6564
this.nodePath = globals.context.asAbsolutePath(path.join('resources', nodeBinName))
6665
}
@@ -186,40 +185,9 @@ export class LspController extends LspDownloader {
186185
return true
187186
}
188187

189-
async install(manifest: Manifest) {
190-
const server = this.getDependency(manifest, 'qserver')
191-
const runtime = this.getDependency(manifest, 'node')
192-
if (!server || !runtime) {
193-
getLogger('lsp').info(`Did not find LSP URL for ${process.platform} ${process.arch}`)
194-
return false
195-
}
196-
197-
const current = globals.globalState.tryGet('aws.toolkit.lsp.versions', Object, {})
198-
current[this.lsName] = server.serverVersion
199-
globals.globalState.tryUpdate('aws.toolkit.lsp.versions', current)
200-
201-
let tempFolder = undefined
202-
203-
try {
204-
tempFolder = await makeTemporaryToolkitFolder()
205-
await this.downloadAndExtractServer({
206-
content: server,
207-
installLocation: this.serverPath,
208-
name: 'qserver',
209-
tempFolder,
210-
extractToTempFolder: true,
211-
})
212-
213-
const runtimeTempPath = path.join(tempFolder, nodeBinName)
214-
await this.installRuntime(runtime, this.nodePath, runtimeTempPath)
215-
} finally {
216-
// clean up temp folder
217-
if (tempFolder) {
218-
await tryRemoveFolder(tempFolder)
219-
}
220-
}
221-
222-
return true
188+
install(): Promise<LspResult> {
189+
// TODO
190+
throw new Error('Method not implemented.')
223191
}
224192

225193
async trySetupLsp(context: vscode.ExtensionContext, buildIndexConfig: BuildIndexConfig) {
@@ -229,7 +197,7 @@ export class LspController extends LspDownloader {
229197
return
230198
}
231199
setImmediate(async () => {
232-
const ok = await LspController.instance.tryInstallLsp()
200+
const ok = await LspController.instance.install()
233201
if (!ok) {
234202
return
235203
}

0 commit comments

Comments
 (0)