-
Notifications
You must be signed in to change notification settings - Fork 680
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6603 from dibarbet/nuget_restore
Add support for nuget restore commands
- Loading branch information
Showing
7 changed files
with
154 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as vscode from 'vscode'; | ||
import { RoslynLanguageServer } from './roslynLanguageServer'; | ||
import { RestorableProjects, RestoreParams, RestorePartialResult, RestoreRequest } from './roslynProtocol'; | ||
import path = require('path'); | ||
|
||
let _restoreInProgress = false; | ||
|
||
export function registerRestoreCommands( | ||
context: vscode.ExtensionContext, | ||
languageServer: RoslynLanguageServer, | ||
restoreChannel: vscode.OutputChannel | ||
) { | ||
context.subscriptions.push( | ||
vscode.commands.registerCommand('dotnet.restore.project', async (_request): Promise<void> => { | ||
return chooseProjectAndRestore(languageServer, restoreChannel); | ||
}) | ||
); | ||
context.subscriptions.push( | ||
vscode.commands.registerCommand('dotnet.restore.all', async (): Promise<void> => { | ||
return restore(languageServer, restoreChannel); | ||
}) | ||
); | ||
} | ||
async function chooseProjectAndRestore( | ||
languageServer: RoslynLanguageServer, | ||
restoreChannel: vscode.OutputChannel | ||
): Promise<void> { | ||
const projects = await languageServer.sendRequest0( | ||
RestorableProjects.type, | ||
new vscode.CancellationTokenSource().token | ||
); | ||
|
||
const items = projects.map((p) => { | ||
const projectName = path.basename(p); | ||
const item: vscode.QuickPickItem = { | ||
label: vscode.l10n.t(`Restore {0}`, projectName), | ||
description: p, | ||
}; | ||
return item; | ||
}); | ||
|
||
const pickedItem = await vscode.window.showQuickPick(items); | ||
if (!pickedItem) { | ||
return; | ||
} | ||
|
||
await restore(languageServer, restoreChannel, pickedItem.description); | ||
} | ||
|
||
async function restore( | ||
languageServer: RoslynLanguageServer, | ||
restoreChannel: vscode.OutputChannel, | ||
projectFile?: string | ||
): Promise<void> { | ||
if (_restoreInProgress) { | ||
vscode.window.showErrorMessage(vscode.l10n.t('Restore already in progress')); | ||
return; | ||
} | ||
_restoreInProgress = true; | ||
restoreChannel.show(true); | ||
|
||
const request: RestoreParams = { projectFilePath: projectFile }; | ||
await vscode.window | ||
.withProgress( | ||
{ | ||
location: vscode.ProgressLocation.Notification, | ||
title: vscode.l10n.t('Restore'), | ||
cancellable: true, | ||
}, | ||
async (progress, token) => { | ||
const writeOutput = (output: RestorePartialResult) => { | ||
if (output.message) { | ||
restoreChannel.appendLine(output.message); | ||
} | ||
|
||
progress.report({ message: output.stage }); | ||
}; | ||
|
||
progress.report({ message: vscode.l10n.t('Sending request') }); | ||
const responsePromise = languageServer.sendRequestWithProgress( | ||
RestoreRequest.type, | ||
request, | ||
async (p) => writeOutput(p), | ||
token | ||
); | ||
|
||
await responsePromise.then( | ||
(result) => result.forEach((r) => writeOutput(r)), | ||
(err) => restoreChannel.appendLine(err) | ||
); | ||
} | ||
) | ||
.then( | ||
() => { | ||
_restoreInProgress = false; | ||
}, | ||
() => { | ||
_restoreInProgress = false; | ||
} | ||
); | ||
|
||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters