Skip to content

Commit 5f7a029

Browse files
DonJayamannebrettcannon
authored andcommitted
Change the download links of the language server files (#2181)
1 parent a18631e commit 5f7a029

File tree

5 files changed

+103
-18
lines changed

5 files changed

+103
-18
lines changed

news/3 Code Health/2180.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Change the download links of the language server files.

src/client/activation/downloader.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
'use strict';
5+
46
import * as fileSystem from 'fs';
57
import * as path from 'path';
68
import * as request from 'request';
@@ -11,7 +13,7 @@ import { createDeferred } from '../common/helpers';
1113
import { IFileSystem, IPlatformService } from '../common/platform/types';
1214
import { IExtensionContext, IOutputChannel } from '../common/types';
1315
import { IServiceContainer } from '../ioc/types';
14-
import { PlatformData } from './platformData';
16+
import { PlatformData, PlatformName } from './platformData';
1517

1618
// tslint:disable-next-line:no-require-imports no-var-requires
1719
const StreamZip = require('node-stream-zip');
@@ -21,6 +23,13 @@ const downloadBaseFileName = 'Python-Language-Server';
2123
const downloadVersion = '0.1.0';
2224
const downloadFileExtension = '.nupkg';
2325

26+
const DownloadLinks = {
27+
[PlatformName.Windows32Bit]: `${downloadUriPrefix}/${downloadBaseFileName}-${PlatformName.Windows32Bit}.${downloadVersion}${downloadFileExtension}`,
28+
[PlatformName.Windows64Bit]: `${downloadUriPrefix}/${downloadBaseFileName}-${PlatformName.Windows64Bit}.${downloadVersion}${downloadFileExtension}`,
29+
[PlatformName.Linux64Bit]: `${downloadUriPrefix}/${downloadBaseFileName}-${PlatformName.Linux64Bit}.${downloadVersion}${downloadFileExtension}`,
30+
[PlatformName.Mac64Bit]: `${downloadUriPrefix}/${downloadBaseFileName}-${PlatformName.Mac64Bit}.${downloadVersion}${downloadFileExtension}`
31+
};
32+
2433
export class LanguageServerDownloader {
2534
private readonly output: OutputChannel;
2635
private readonly platform: IPlatformService;
@@ -34,13 +43,17 @@ export class LanguageServerDownloader {
3443
this.platformData = new PlatformData(this.platform, this.fs);
3544
}
3645

37-
public async downloadLanguageServer(context: IExtensionContext): Promise<void> {
46+
public async getDownloadUri() {
3847
const platformString = await this.platformData.getPlatformName();
39-
const enginePackageFileName = `${downloadBaseFileName}-${platformString}.${downloadVersion}${downloadFileExtension}`;
48+
return DownloadLinks[platformString];
49+
}
50+
51+
public async downloadLanguageServer(context: IExtensionContext): Promise<void> {
52+
const downloadUri = await this.getDownloadUri();
4053

4154
let localTempFilePath = '';
4255
try {
43-
localTempFilePath = await this.downloadFile(downloadUriPrefix, enginePackageFileName, 'Downloading Microsoft Python Language Server... ');
56+
localTempFilePath = await this.downloadFile(downloadUri, 'Downloading Microsoft Python Language Server... ');
4457
await this.unpackArchive(context.extensionPath, localTempFilePath);
4558
} catch (err) {
4659
this.output.appendLine('failed.');
@@ -53,8 +66,7 @@ export class LanguageServerDownloader {
5366
}
5467
}
5568

56-
private async downloadFile(location: string, fileName: string, title: string): Promise<string> {
57-
const uri = `${location}/${fileName}`;
69+
private async downloadFile(uri: string, title: string): Promise<string> {
5870
this.output.append(`Downloading ${uri}... `);
5971
const tempFile = await this.fs.createTemporaryFile(downloadFileExtension);
6072

src/client/activation/platformData.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,27 @@ import {
99
language_server_win_x86_sha512
1010
} from './languageServerHashes';
1111

12+
export enum PlatformName {
13+
Windows32Bit = 'win-x86',
14+
Windows64Bit = 'win-x64',
15+
Mac64Bit = 'osx-x64',
16+
Linux64Bit = 'linux-x64'
17+
}
18+
1219
export class PlatformData {
1320
constructor(private platform: IPlatformService, fs: IFileSystem) { }
14-
public async getPlatformName(): Promise<string> {
21+
public async getPlatformName(): Promise<PlatformName> {
1522
if (this.platform.isWindows) {
16-
return this.platform.is64bit ? 'win-x64' : 'win-x86';
23+
return this.platform.is64bit ? PlatformName.Windows64Bit : PlatformName.Windows32Bit;
1724
}
1825
if (this.platform.isMac) {
19-
return 'osx-x64';
26+
return PlatformName.Mac64Bit;
2027
}
2128
if (this.platform.isLinux) {
2229
if (!this.platform.is64bit) {
2330
throw new Error('Microsoft Python Language Server does not support 32-bit Linux.');
2431
}
25-
return 'linux-x64';
32+
return PlatformName.Linux64Bit;
2633
}
2734
throw new Error('Unknown OS platform.');
2835
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
// tslint:disable:no-unused-variable
7+
8+
import * as assert from 'assert';
9+
import * as TypeMoq from 'typemoq';
10+
import { LanguageServerDownloader } from '../../client/activation/downloader';
11+
import { IFileSystem, IPlatformService } from '../../client/common/platform/types';
12+
import { IOutputChannel } from '../../client/common/types';
13+
import { IServiceContainer } from '../../client/ioc/types';
14+
15+
const downloadUriPrefix = 'https://pvsc.blob.core.windows.net/python-language-server';
16+
const downloadBaseFileName = 'Python-Language-Server';
17+
const downloadVersion = '0.1.0';
18+
const downloadFileExtension = '.nupkg';
19+
20+
suite('Activation - Downloader', () => {
21+
let languageServerDownloader: LanguageServerDownloader;
22+
let serviceContainer: TypeMoq.IMock<IServiceContainer>;
23+
let platformService: TypeMoq.IMock<IPlatformService>;
24+
setup(() => {
25+
serviceContainer = TypeMoq.Mock.ofType<IServiceContainer>();
26+
platformService = TypeMoq.Mock.ofType<IPlatformService>();
27+
const fs = TypeMoq.Mock.ofType<IFileSystem>();
28+
const output = TypeMoq.Mock.ofType<IOutputChannel>();
29+
30+
serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IOutputChannel), TypeMoq.It.isAny())).returns(() => output.object);
31+
serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IPlatformService))).returns(() => platformService.object);
32+
serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IFileSystem))).returns(() => fs.object);
33+
34+
languageServerDownloader = new LanguageServerDownloader(serviceContainer.object, '');
35+
});
36+
type PlatformIdentifier = {
37+
windows?: boolean;
38+
mac?: boolean;
39+
linux?: boolean;
40+
is64Bit?: boolean;
41+
};
42+
function setupPlatform(platform: PlatformIdentifier) {
43+
platformService.setup(x => x.isWindows).returns(() => platform.windows === true);
44+
platformService.setup(x => x.isMac).returns(() => platform.mac === true);
45+
platformService.setup(x => x.isLinux).returns(() => platform.linux === true);
46+
platformService.setup(x => x.is64bit).returns(() => platform.is64Bit === true);
47+
}
48+
test('Windows 32Bit', async () => {
49+
setupPlatform({ windows: true });
50+
const link = await languageServerDownloader.getDownloadUri();
51+
assert.equal(link, `${downloadUriPrefix}/${downloadBaseFileName}-win-x86.${downloadVersion}${downloadFileExtension}`);
52+
});
53+
test('Windows 64Bit', async () => {
54+
setupPlatform({ windows: true, is64Bit: true });
55+
const link = await languageServerDownloader.getDownloadUri();
56+
assert.equal(link, `${downloadUriPrefix}/${downloadBaseFileName}-win-x64.${downloadVersion}${downloadFileExtension}`);
57+
});
58+
test('Mac 64Bit', async () => {
59+
setupPlatform({ mac: true, is64Bit: true });
60+
const link = await languageServerDownloader.getDownloadUri();
61+
assert.equal(link, `${downloadUriPrefix}/${downloadBaseFileName}-osx-x64.${downloadVersion}${downloadFileExtension}`);
62+
});
63+
test('Linux 64Bit', async () => {
64+
setupPlatform({ linux: true, is64Bit: true });
65+
const link = await languageServerDownloader.getDownloadUri();
66+
assert.equal(link, `${downloadUriPrefix}/${downloadBaseFileName}-linux-x64.${downloadVersion}${downloadFileExtension}`);
67+
});
68+
});

src/test/activation/platformData.test.ts renamed to src/test/activation/platformData.unit.test.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as assert from 'assert';
66
import * as TypeMoq from 'typemoq';
77
import { PlatformData } from '../../client/activation/platformData';
88
import { IFileSystem, IPlatformService } from '../../client/common/platform/types';
9-
import { initialize } from '../initialize';
109

1110
const testDataWinMac = [
1211
{ isWindows: true, is64Bit: true, expectedName: 'win-x64' },
@@ -31,8 +30,6 @@ const testDataModuleName = [
3130

3231
// tslint:disable-next-line:max-func-body-length
3332
suite('Activation - platform data', () => {
34-
suiteSetup(initialize);
35-
3633
test('Name and hash (Windows/Mac)', async () => {
3734
for (const t of testDataWinMac) {
3835
const platformService = TypeMoq.Mock.ofType<IPlatformService>();
@@ -43,11 +40,11 @@ suite('Activation - platform data', () => {
4340
const fs = TypeMoq.Mock.ofType<IFileSystem>();
4441
const pd = new PlatformData(platformService.object, fs.object);
4542

46-
let actual = await pd.getPlatformName();
43+
const actual = await pd.getPlatformName();
4744
assert.equal(actual, t.expectedName, `${actual} does not match ${t.expectedName}`);
4845

49-
actual = await pd.getExpectedHash();
50-
assert.equal(actual, t.expectedName, `${actual} hash not match ${t.expectedName}`);
46+
const actualHash = await pd.getExpectedHash();
47+
assert.equal(actualHash, t.expectedName, `${actual} hash not match ${t.expectedName}`);
5148
}
5249
});
5350
test('Name and hash (Linux)', async () => {
@@ -62,10 +59,10 @@ suite('Activation - platform data', () => {
6259
fs.setup(x => x.readFile(TypeMoq.It.isAnyString())).returns(() => Promise.resolve(`NAME="name"\nID=${t.name}\nID_LIKE=debian`));
6360
const pd = new PlatformData(platformService.object, fs.object);
6461

65-
let actual = await pd.getPlatformName();
62+
const actual = await pd.getPlatformName();
6663
assert.equal(actual, t.expectedName, `${actual} does not match ${t.expectedName}`);
6764

68-
actual = await pd.getExpectedHash();
65+
const actualHash = await pd.getExpectedHash();
6966
assert.equal(actual, t.expectedName, `${actual} hash not match ${t.expectedName}`);
7067
}
7168
});

0 commit comments

Comments
 (0)