55
66import * as vscode from 'vscode' ;
77import { RoslynLanguageServer } from '../server/roslynLanguageServer' ;
8- import {
9- RestorableProjects ,
10- RestoreParams ,
11- RestorePartialResult ,
12- RestoreRequest ,
13- ProjectNeedsRestoreRequest ,
14- } from '../server/roslynProtocol' ;
8+ import { RestorableProjects , RestoreParams , RestoreRequest } from '../server/roslynProtocol' ;
159import path from 'path' ;
1610import { showErrorMessage } from '../../shared/observers/utils/showMessage' ;
1711import { getCSharpDevKit } from '../../utils/getCSharpDevKit' ;
12+ import { CancellationToken } from 'vscode-jsonrpc' ;
1813
1914let _restoreInProgress = false ;
2015
@@ -32,33 +27,10 @@ export function registerRestoreCommands(
3227 ) ;
3328 context . subscriptions . push (
3429 vscode . commands . registerCommand ( 'dotnet.restore.all' , async ( ) : Promise < void > => {
35- return restore ( languageServer , csharpOutputChannel , [ ] , true ) ;
30+ return restore ( languageServer , csharpOutputChannel , [ ] ) ;
3631 } )
3732 ) ;
3833 }
39-
40- languageServer . registerOnRequest ( ProjectNeedsRestoreRequest . type , async ( params ) => {
41- let projectFilePaths = params . projectFilePaths ;
42- if ( getCSharpDevKit ( ) ) {
43- // Only restore '.cs' files (file-based apps) if CDK is loaded.
44- const csharpFiles = [ ] ;
45- for ( const path of projectFilePaths ) {
46- if ( path . endsWith ( '.cs' ) ) {
47- csharpFiles . push ( path ) ;
48- } else {
49- csharpOutputChannel . debug (
50- `[.NET Restore] Not restoring '${ path } ' from C# extension, because C# Dev Kit is expected to handle restore for it.`
51- ) ;
52- }
53- }
54-
55- projectFilePaths = csharpFiles ;
56- }
57-
58- if ( projectFilePaths . length > 0 ) {
59- await restore ( languageServer , csharpOutputChannel , params . projectFilePaths , false ) ;
60- }
61- } ) ;
6234}
6335
6436async function chooseProjectAndRestore (
@@ -93,63 +65,34 @@ async function chooseProjectAndRestore(
9365 return ;
9466 }
9567
96- await restore ( languageServer , outputChannel , [ pickedItem . description ! ] , true ) ;
68+ await restore ( languageServer , outputChannel , [ pickedItem . description ! ] ) ;
9769}
9870
9971export async function restore (
10072 languageServer : RoslynLanguageServer ,
10173 outputChannel : vscode . LogOutputChannel ,
102- projectFiles : string [ ] ,
103- showOutput : boolean
74+ projectFiles : string [ ]
10475) : Promise < void > {
10576 if ( _restoreInProgress ) {
10677 showErrorMessage ( vscode , vscode . l10n . t ( 'Restore already in progress' ) ) ;
10778 return ;
10879 }
10980 _restoreInProgress = true ;
110- if ( showOutput ) {
111- outputChannel . show ( true ) ;
112- }
81+ outputChannel . show ( true ) ;
11382
11483 const request : RestoreParams = { projectFilePaths : projectFiles } ;
115- await vscode . window
116- . withProgress (
117- {
118- location : vscode . ProgressLocation . Notification ,
119- title : vscode . l10n . t ( 'Restore' ) ,
120- cancellable : true ,
121- } ,
122- async ( progress , token ) => {
123- const writeOutput = ( output : RestorePartialResult ) => {
124- if ( output . message ) {
125- outputChannel . debug ( `[.NET Restore] ${ output . message } ` ) ;
126- }
127-
128- progress . report ( { message : output . stage } ) ;
129- } ;
130-
131- progress . report ( { message : vscode . l10n . t ( 'Sending request' ) } ) ;
132- const responsePromise = languageServer . sendRequestWithProgress (
133- RestoreRequest . type ,
134- request ,
135- async ( p ) => writeOutput ( p ) ,
136- token
137- ) ;
13884
139- await responsePromise . then (
140- ( result ) => result . forEach ( ( r ) => writeOutput ( r ) ) ,
141- ( err ) => outputChannel . error ( `[.NET Restore] ${ err } ` )
142- ) ;
143- }
144- )
145- . then (
146- ( ) => {
147- _restoreInProgress = false ;
148- } ,
149- ( ) => {
150- _restoreInProgress = false ;
151- }
152- ) ;
85+ // server will show a work done progress with cancellation. no need to pass a token to the request.
86+ const resultPromise = languageServer . sendRequest ( RestoreRequest . type , request , CancellationToken . None ) . then (
87+ ( ) => {
88+ _restoreInProgress = false ;
89+ } ,
90+ ( err ) => {
91+ outputChannel . error ( `[.NET Restore] ${ err } ` ) ;
92+ _restoreInProgress = false ;
93+ }
94+ ) ;
15395
96+ await resultPromise ;
15497 return ;
15598}
0 commit comments