aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/installation/language_server.ts
diff options
context:
space:
mode:
authorVeetaha <[email protected]>2020-02-09 12:18:05 +0000
committerVeetaha <[email protected]>2020-02-09 12:18:05 +0000
commitf3240e22c6de69b408a83b59e85f40fb913acfab (patch)
tree25c9a71ec7a98efe33209fcd370668610c61aa1e /editors/code/src/installation/language_server.ts
parenta63659badb75d22ad834b7524e77505790c10dd0 (diff)
vscode: move throtting of download progress to call site
Diffstat (limited to 'editors/code/src/installation/language_server.ts')
-rw-r--r--editors/code/src/installation/language_server.ts27
1 files changed, 16 insertions, 11 deletions
diff --git a/editors/code/src/installation/language_server.ts b/editors/code/src/installation/language_server.ts
index a169eae47..c1f37f978 100644
--- a/editors/code/src/installation/language_server.ts
+++ b/editors/code/src/installation/language_server.ts
@@ -1,8 +1,9 @@
1import { spawnSync } from "child_process";
2import * as vscode from "vscode"; 1import * as vscode from "vscode";
3import * as path from "path"; 2import * as path from "path";
4import { strict as assert } from "assert"; 3import { strict as assert } from "assert";
5import { promises as fs } from "fs"; 4import { promises as fs } from "fs";
5import { spawnSync } from "child_process";
6import { throttle } from "throttle-debounce";
6 7
7import { BinarySource } from "./interfaces"; 8import { BinarySource } from "./interfaces";
8import { fetchLatestArtifactMetadata } from "./fetch_latest_artifact_metadata"; 9import { fetchLatestArtifactMetadata } from "./fetch_latest_artifact_metadata";
@@ -28,19 +29,23 @@ export async function downloadLatestLanguageServer(
28 { 29 {
29 location: vscode.ProgressLocation.Notification, 30 location: vscode.ProgressLocation.Notification,
30 cancellable: false, // FIXME: add support for canceling download? 31 cancellable: false, // FIXME: add support for canceling download?
31 title: `Downloading language server ${releaseName}` 32 title: `Downloading language server (${releaseName})`
32 }, 33 },
33 async (progress, _cancellationToken) => { 34 async (progress, _cancellationToken) => {
34 let lastPrecentage = 0; 35 let lastPrecentage = 0;
35 await downloadFile(downloadUrl, installationPath, (readBytes, totalBytes) => { 36 await downloadFile(downloadUrl, installationPath, throttle(
36 const newPercentage = (readBytes / totalBytes) * 100; 37 200,
37 progress.report({ 38 /* noTrailing: */ true,
38 message: newPercentage.toFixed(0) + "%", 39 (readBytes, totalBytes) => {
39 increment: newPercentage - lastPrecentage 40 const newPercentage = (readBytes / totalBytes) * 100;
40 }); 41 progress.report({
41 42 message: newPercentage.toFixed(0) + "%",
42 lastPrecentage = newPercentage; 43 increment: newPercentage - lastPrecentage
43 }); 44 });
45
46 lastPrecentage = newPercentage;
47 })
48 );
44 } 49 }
45 ); 50 );
46 51