This commit is contained in:
锦恢 2024-10-08 11:08:53 +08:00
parent 5231b22181
commit ba126f651d
2 changed files with 40 additions and 20 deletions

View File

@ -47,13 +47,8 @@ async function launch(context: vscode.ExtensionContext) {
});
await vscode.window.withProgress({
location: vscode.ProgressLocation.Window,
title: t('progress.active-lsp-server')
}, async (progress: vscode.Progress<IProgress>, token: vscode.CancellationToken) => {
await lspClient.activate(context, progress, versionString);
await LspClient.DigitalIDE?.onReady();
});
await lspClient.activate(context, versionString);
await LspClient.DigitalIDE?.onReady();
await vscode.window.withProgress({
location: vscode.ProgressLocation.Window,

View File

@ -10,7 +10,7 @@ import * as path from 'path';
import * as fs from 'fs';
import { platform } from "os";
import { IProgress, LspClient } from '../../global';
import axios from "axios";
import axios, { AxiosResponse } from "axios";
import { getGiteeDownloadLink, getPlatformPlatformSignature } from "./cdn";
@ -23,7 +23,7 @@ function getLspServerExecutionName() {
return 'digital-lsp';
}
async function checkAndDownload(context: vscode.ExtensionContext, progress: vscode.Progress<IProgress>, version: string): boolean {
async function checkAndDownload(context: vscode.ExtensionContext, version: string): boolean {
const { t } = vscode.l10n;
const versionFolderPath = context.asAbsolutePath(
@ -35,22 +35,47 @@ async function checkAndDownload(context: vscode.ExtensionContext, progress: vsco
return true;
}
// 流式下载
progress.report({ message: t('progress.download-digital-lsp') });
const signature = getPlatformPlatformSignature().toString();
const giteeDownloadLink = getGiteeDownloadLink(signature, version)
console.log('download link ', giteeDownloadLink);
await vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
title: t('progress.download-digital-lsp')
}, async (progress: vscode.Progress<IProgress>, token: vscode.CancellationToken) => {
progress.report({ increment: 0 });
const signature = getPlatformPlatformSignature().toString();
const downloadLink = getGiteeDownloadLink(signature, version);
const response = await axios.get(downloadLink, { responseType: 'stream' });
const response = await axios.get(giteeDownloadLink, { responseType: 'stream' });
const totalLength = response.headers['content-length'];
console.log('totalLength ', totalLength);
});
function streamDownload(progress: vscode.Progress<IProgress>, response: AxiosResponse<any, any>): Promise<void> {
const totalLength = response.headers['content-length'];
const totalSize = parseInt(totalLength);
let downloadSize = 0;
const savePath = context.asAbsolutePath(
path.join('resources', 'dide-lsp', 'server', 'tmp.tar.gz')
);
const fileStream = fs.createWriteStream(savePath);
response.data.on('data', (chunk: Buffer) => {
downloadSize += chunk.length;
let increment = Math.ceil(downloadSize / totalSize * 100);
progress.report({ message: t('progress.download-digital-lsp'), increment });
});
return new Promise((resolve, reject) => {
fileStream.on('finish', () => {
resolve();
});
fileStream.on('error', (error) => {
reject(error);
});
});
}
return false;
}
export async function activate(context: vscode.ExtensionContext, progress: vscode.Progress<IProgress>, version: string) {
await checkAndDownload(context, progress, version);
export async function activate(context: vscode.ExtensionContext, version: string) {
await checkAndDownload(context, version);
const lspServerName = getLspServerExecutionName();