Skip to content

Commit 1bb9691

Browse files
committed
save
1 parent 2889a10 commit 1bb9691

File tree

6 files changed

+48
-13
lines changed

6 files changed

+48
-13
lines changed

packages/amazonq/src/lsp/activation.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
*/
55

66
import vscode from 'vscode'
7+
import path from 'path'
78
import { AmazonQLSPDownloader } from './download'
89

910
export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
1011
// use the codewhisperer language server
11-
const serverPath = ctx.asAbsolutePath('dist/amazonqLSP/server.js')
12-
const clientPath = ctx.asAbsolutePath('dist/amazonqLSP/client.js')
12+
const serverPath = ctx.asAbsolutePath(path.join('resources', 'qdeveloperserver'))
13+
const clientPath = ctx.asAbsolutePath(path.join('resources', 'qdeveloperclient'))
1314
await new AmazonQLSPDownloader(serverPath, clientPath).tryInstallLsp()
1415

1516
/**

packages/amazonq/src/lsp/download.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,22 @@ export class AmazonQLSPDownloader extends LSPDownloader {
5050

5151
try {
5252
tempFolder = await makeTemporaryToolkitFolder()
53-
await this.downloadAndExtractServer(server, this.serverPath, 'qdeveloperserver', tempFolder)
54-
await this.downloadAndExtractServer(clients, this.clientPath, 'qdeveloperclient', tempFolder)
53+
54+
// the business logic
55+
await this.downloadAndExtractServer({
56+
content: server,
57+
installLocation: this.serverPath,
58+
name: 'qdeveloperserver',
59+
tempFolder,
60+
})
61+
62+
// mynah ui
63+
await this.downloadAndExtractServer({
64+
content: clients,
65+
installLocation: this.clientPath,
66+
name: 'qdeveloperclient',
67+
tempFolder,
68+
})
5569
} finally {
5670
// clean up temp folder
5771
if (tempFolder) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*/
55
import assert from 'assert'
66
import sinon from 'sinon'
7-
import { Content, LspController } from 'aws-core-vscode/amazonq'
7+
import { LspController } from 'aws-core-vscode/amazonq'
88
import { createTestFile } from 'aws-core-vscode/test'
9-
import { fs } from 'aws-core-vscode/shared'
9+
import { fs, Content } from 'aws-core-vscode/shared'
1010

1111
describe('Amazon Q LSP controller', function () {
1212
it('Download mechanism checks against hash, when hash matches', async function () {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,13 @@ export class LspController extends LSPDownloader {
198198

199199
try {
200200
tempFolder = await makeTemporaryToolkitFolder()
201-
await this.downloadAndExtractServer(server, this.serverPath, 'qserver', tempFolder)
201+
await this.downloadAndExtractServer({
202+
content: server,
203+
installLocation: this.serverPath,
204+
name: 'qserver',
205+
tempFolder,
206+
extractToTempFolder: true,
207+
})
202208

203209
const runtimeTempPath = path.join(tempFolder, nodeBinName)
204210
await this.installRuntime(runtime, this.nodePath, runtimeTempPath)

packages/core/src/shared/downloadLSP.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,29 @@ export abstract class LSPDownloader {
142142
/**
143143
* Downloads servers.zip, clients.zip, qserver.zip and then extracts them
144144
*/
145-
async downloadAndExtractServer(server: Content, installLocation: string, name: string, tempFolder: string) {
146-
const qserverZipTempPath = path.join(tempFolder, `${name}.zip`)
147-
const downloadOk = await this.downloadAndCheckHash(qserverZipTempPath, server)
145+
async downloadAndExtractServer({
146+
content,
147+
installLocation,
148+
name,
149+
tempFolder,
150+
extractToTempFolder = false,
151+
}: {
152+
content: Content
153+
installLocation: string
154+
name: string
155+
tempFolder: string
156+
extractToTempFolder?: boolean
157+
}) {
158+
const serverZipTempPath = path.join(tempFolder, `${name}.zip`)
159+
const downloadOk = await this.downloadAndCheckHash(serverZipTempPath, content)
148160
if (!downloadOk) {
149161
return false
150162
}
151163

152-
const zip = new AdmZip(qserverZipTempPath)
153-
zip.extractAllTo(tempFolder)
164+
// load the zip contents
165+
const extractPath = extractToTempFolder ? tempFolder : path.join(tempFolder, name)
166+
new AdmZip(serverZipTempPath).extractAllTo(extractPath)
167+
154168
await fs.rename(path.join(tempFolder, name), installLocation)
155169
}
156170

packages/core/src/shared/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ export { i18n } from './i18n-helper'
5959
export * from './icons'
6060
export * as textDocumentUtil from './utilities/textDocumentUtilities'
6161
export { TabTypeDataMap } from '../amazonq/webview/ui/tabs/constants'
62-
export { LSPDownloader, Manifest } from './downloadLSP'
62+
export { LSPDownloader, Manifest, Content } from './downloadLSP'

0 commit comments

Comments
 (0)