diff --git a/l10n/bundle.l10n.json b/l10n/bundle.l10n.json index ecb759f80e..43bb44f3e9 100644 --- a/l10n/bundle.l10n.json +++ b/l10n/bundle.l10n.json @@ -190,7 +190,6 @@ "Suppress notification": "Suppress notification", "Restore {0}": "Restore {0}", "Restore already in progress": "Restore already in progress", - "Sending request": "Sending request", "C# Project Context Status": "C# Project Context Status", "Active File Context": "Active File Context", "Initializing dotnet-trace.../dotnet-trace is a command name and should not be localized": { diff --git a/src/lsptoolshost/projectRestore/restore.ts b/src/lsptoolshost/projectRestore/restore.ts index f9e58d9681..413a9be153 100644 --- a/src/lsptoolshost/projectRestore/restore.ts +++ b/src/lsptoolshost/projectRestore/restore.ts @@ -5,16 +5,11 @@ import * as vscode from 'vscode'; import { RoslynLanguageServer } from '../server/roslynLanguageServer'; -import { - RestorableProjects, - RestoreParams, - RestorePartialResult, - RestoreRequest, - ProjectNeedsRestoreRequest, -} from '../server/roslynProtocol'; +import { RestorableProjects, RestoreParams, RestoreRequest } from '../server/roslynProtocol'; import path from 'path'; import { showErrorMessage } from '../../shared/observers/utils/showMessage'; import { getCSharpDevKit } from '../../utils/getCSharpDevKit'; +import { CancellationToken } from 'vscode-jsonrpc'; let _restoreInProgress = false; @@ -32,33 +27,10 @@ export function registerRestoreCommands( ); context.subscriptions.push( vscode.commands.registerCommand('dotnet.restore.all', async (): Promise => { - return restore(languageServer, csharpOutputChannel, [], true); + return restore(languageServer, csharpOutputChannel, []); }) ); } - - languageServer.registerOnRequest(ProjectNeedsRestoreRequest.type, async (params) => { - let projectFilePaths = params.projectFilePaths; - if (getCSharpDevKit()) { - // Only restore '.cs' files (file-based apps) if CDK is loaded. - const csharpFiles = []; - for (const path of projectFilePaths) { - if (path.endsWith('.cs')) { - csharpFiles.push(path); - } else { - csharpOutputChannel.debug( - `[.NET Restore] Not restoring '${path}' from C# extension, because C# Dev Kit is expected to handle restore for it.` - ); - } - } - - projectFilePaths = csharpFiles; - } - - if (projectFilePaths.length > 0) { - await restore(languageServer, csharpOutputChannel, params.projectFilePaths, false); - } - }); } async function chooseProjectAndRestore( @@ -93,63 +65,34 @@ async function chooseProjectAndRestore( return; } - await restore(languageServer, outputChannel, [pickedItem.description!], true); + await restore(languageServer, outputChannel, [pickedItem.description!]); } export async function restore( languageServer: RoslynLanguageServer, outputChannel: vscode.LogOutputChannel, - projectFiles: string[], - showOutput: boolean + projectFiles: string[] ): Promise { if (_restoreInProgress) { showErrorMessage(vscode, vscode.l10n.t('Restore already in progress')); return; } _restoreInProgress = true; - if (showOutput) { - outputChannel.show(true); - } + outputChannel.show(true); const request: RestoreParams = { projectFilePaths: projectFiles }; - 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) { - outputChannel.debug(`[.NET Restore] ${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) => outputChannel.error(`[.NET Restore] ${err}`) - ); - } - ) - .then( - () => { - _restoreInProgress = false; - }, - () => { - _restoreInProgress = false; - } - ); + // server will show a work done progress with cancellation. no need to pass a token to the request. + const resultPromise = languageServer.sendRequest(RestoreRequest.type, request, CancellationToken.None).then( + () => { + _restoreInProgress = false; + }, + (err) => { + outputChannel.error(`[.NET Restore] ${err}`); + _restoreInProgress = false; + } + ); + await resultPromise; return; } diff --git a/src/lsptoolshost/server/roslynProtocol.ts b/src/lsptoolshost/server/roslynProtocol.ts index 83b4e167ef..f51b7cf94d 100644 --- a/src/lsptoolshost/server/roslynProtocol.ts +++ b/src/lsptoolshost/server/roslynProtocol.ts @@ -227,9 +227,8 @@ export interface RestoreParams extends WorkDoneProgressParams, PartialResultPara projectFilePaths: string[]; } -export interface RestorePartialResult { - stage: string; - message: string; +export interface RestoreResult { + success: boolean; } export interface ProjectNeedsRestoreName { @@ -336,13 +335,7 @@ export namespace CodeActionFixAllResolveRequest { export namespace RestoreRequest { export const method = 'workspace/_roslyn_restore'; export const messageDirection: MessageDirection = MessageDirection.clientToServer; - export const type = new ProtocolRequestType< - RestoreParams, - RestorePartialResult[], - RestorePartialResult, - void, - void - >(method); + export const type = new RequestType(method); } export namespace RestorableProjects { @@ -351,12 +344,6 @@ export namespace RestorableProjects { export const type = new RequestType0(method); } -export namespace ProjectNeedsRestoreRequest { - export const method = 'workspace/_roslyn_projectNeedsRestore'; - export const messageDirection: MessageDirection = MessageDirection.serverToClient; - export const type = new RequestType(method); -} - export namespace SourceGeneratorGetTextRequest { export const method = 'sourceGeneratedDocument/_roslyn_getText'; export const messageDirection: MessageDirection = MessageDirection.clientToServer;