From d413046c8325883dec05cd24747f6bd127d09ce9 Mon Sep 17 00:00:00 2001 From: ManuelHentschel <53863351+ManuelHentschel@users.noreply.github.com> Date: Sun, 17 Oct 2021 23:43:44 +0200 Subject: [PATCH] Use task to install R package --- src/installRPackage.ts | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/installRPackage.ts b/src/installRPackage.ts index c28a3ea..9733026 100644 --- a/src/installRPackage.ts +++ b/src/installRPackage.ts @@ -15,12 +15,39 @@ export type VersionCheckLevel = 'none'|'required'|'recommended'; export async function updateRPackage(extensionPath: string, packageName:string = 'vscDebugger'): Promise { - void vscode.window.showInformationMessage('Installing R Packages...'); const url = getRDownloadLink(packageName); - const rPath = (await getRStartupArguments()).path; - const terminal = vscode.window.createTerminal('InstallRPackage'); - terminal.show(); - terminal.sendText(`${rPath} --no-restore --quiet -f "${join(extensionPath, 'R', 'install.R')}" --args "${url}"`); + const rPath = (await getRStartupArguments()).path.replace(/^"(.*)"$/, '$1'); + const taskDefinition: vscode.TaskDefinition = { + type: 'process' + }; + const args = [ + '--no-restore', + '--quiet', + '-f', + `"${join(extensionPath, 'R', 'install.R')}"`, + '--args', + `"${url}"` + ]; + const processExecution = new vscode.ProcessExecution(rPath, args); + const installationTask = new vscode.Task( + taskDefinition, + vscode.TaskScope.Global, + 'Install vscDebugger', + 'R-Debugger', + processExecution + ); + + const taskExecutionRunning = await vscode.tasks.executeTask(installationTask); + + const taskDonePromise = new Promise((resolve) => { + vscode.tasks.onDidEndTask(e => { + if (e.execution === taskExecutionRunning) { + resolve(); + } + }); + }); + + return await taskDonePromise; } export function explainRPackage(writeOutput: (text: string)=>void, message: string = ''): void {