Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@
],
"default": "stable"
},
"language-1c-bsl.languageServerDownloadProxy": {
"description": "Proxy URL for downloading BSL LS binaries",
"type": "string",
"default": ""
},
"language-1c-bsl.languageServerExternalJar": {
"description": "Use external bsl-language-server.jar",
"type": "boolean",
Expand Down Expand Up @@ -355,6 +360,7 @@
"request": "^2.88.0",
"request-progress": "^3.0.0",
"request-promise-native": "^1.0.8",
"https-proxy-agent": "^5.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

кажется, тут лишний пакет

"semver": "^7.1.1",
"vsce": "^1.71.0",
"vscode-languageclient": "^6.1.0",
Expand Down
6 changes: 4 additions & 2 deletions src/util/downloadUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ const requestProgress = require("request-progress");
export function download(
srcUrl: string,
destPath: fs.PathLike,
progress: (percent: number) => void
progress: (percent: number) => void,
proxySettings: string = null
): Promise<void> {
return new Promise((resolve, reject) => {
requestProgress(request.get(srcUrl))
var proxiedRq = request.defaults({proxy: proxySettings})
requestProgress(proxiedRq.get(srcUrl))
.on("progress", state => progress(state.percent))
.on("complete", () => resolve())
.on("error", err => reject(err))
Expand Down
26 changes: 21 additions & 5 deletions src/util/serverDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import BSLLanguageServerDownloadChannel from "./bsllsDownloadChannel";
import { download } from "./downloadUtils";
import { IGitHubReleasesAPIResponse } from "./githubApi";
import { IStatus } from "./status";
import * as vscode from "vscode";
import { LANGUAGE_1C_BSL_CONFIG } from "../const";

const extractZip = promisify(extractZipWithCallback);

Expand All @@ -56,6 +58,7 @@ export class ServerDownloader {
private readonly assetName: string;
private readonly installDir: string;
private readonly token: string;
private readonly proxySettings: string;

constructor(
displayName: string,
Expand All @@ -71,6 +74,12 @@ export class ServerDownloader {
this.installDir = installDir;
this.assetName = assetName;
this.token = token;

const configuration = vscode.workspace.getConfiguration(LANGUAGE_1C_BSL_CONFIG);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

по аналогии с token это лучше передавать из-вне

var proxyFromConfig:string = configuration.get("languageServerDownloadProxy");
if(proxyFromConfig) {
this.proxySettings = proxyFromConfig;
}
}

public async downloadServerIfNeeded(status: IStatus, channel: BSLLanguageServerDownloadChannel): Promise<string> {
Expand Down Expand Up @@ -150,7 +159,10 @@ export class ServerDownloader {

const rawJsonReleases = await requestPromise.get(
`https://api.github.com/repos/${this.githubOrganization}/${this.githubProjectName}/releases`,
{ headers }
{
headers,
proxy: this.proxySettings || null
}
);

const releases = JSON.parse(rawJsonReleases, jsonDateParser) as IGitHubReleasesAPIResponse[];
Expand All @@ -172,7 +184,10 @@ export class ServerDownloader {

const rawJson = await requestPromise.get(
`https://api.github.com/repos/${this.githubOrganization}/${this.githubProjectName}/releases/${id}`,
{ headers }
{
headers,
proxy: this.proxySettings || null
}
);
return JSON.parse(rawJson) as IGitHubReleasesAPIResponse;
}
Expand Down Expand Up @@ -211,9 +226,10 @@ export class ServerDownloader {
status.update(`Downloading ${this.displayName} ${version}...`);
await download(downloadUrl, downloadDest, percent => {
status.update(
`Downloading ${this.displayName} ${version} :: ${(percent * 100).toFixed(2)} %`
);
});
`Downloading ${this.displayName} ${version} :: ${(percent * 100).toFixed(2)} %`);
},
this.proxySettings
);

status.update(`Unpacking ${this.displayName} ${version}...`);
await extractZip(downloadDest, { dir: path.join(this.installDir, version) });
Expand Down