@@ -25,6 +25,11 @@ export const commandState = {
2525 promptToReloadOnVersionChanges : true ,
2626} ;
2727
28+ export interface OperationProgress {
29+ progressReporter : vs . Progress < { message ?: string ; increment ?: number } > ;
30+ cancellationToken : vs . CancellationToken ;
31+ }
32+
2833export class BaseSdkCommands implements IAmDisposable {
2934 protected readonly sdks : DartSdks ;
3035 protected readonly disposables : vs . Disposable [ ] = [ ] ;
@@ -37,11 +42,12 @@ export class BaseSdkCommands implements IAmDisposable {
3742 }
3843
3944 protected async runCommandForWorkspace (
40- handler : ( folder : string , args : string [ ] , shortPath : string , alwaysShowOutput : boolean ) => Promise < RunProcessResult | undefined > ,
45+ handler : ( folder : string , args : string [ ] , shortPath : string , alwaysShowOutput : boolean , operationProgress ?: OperationProgress ) => Promise < RunProcessResult | undefined > ,
4146 placeHolder : string ,
4247 args : string [ ] ,
4348 selection : vs . Uri | undefined ,
4449 alwaysShowOutput = false ,
50+ operationProgress ?: OperationProgress ,
4551 ) : Promise < RunProcessResult | undefined > {
4652 const folderToRunCommandIn = await getFolderToRunCommandIn ( this . logger , placeHolder , selection ) ;
4753 if ( ! folderToRunCommandIn )
@@ -50,20 +56,25 @@ export class BaseSdkCommands implements IAmDisposable {
5056 const containingWorkspace = vs . workspace . getWorkspaceFolder ( vs . Uri . file ( folderToRunCommandIn ) ) ;
5157 const containingWorkspacePath = containingWorkspace ? fsPath ( containingWorkspace . uri ) : undefined ;
5258
53- // Display the relative path from the workspace root to the folder we're running, or if they're
54- // the same then the folder name we're running in.
55- const shortPath = containingWorkspacePath
56- ? path . relative ( containingWorkspacePath , folderToRunCommandIn ) || path . basename ( folderToRunCommandIn )
57- : path . basename ( folderToRunCommandIn ) ;
59+ // Display the relative path from the workspace root to the folder we're running up to two segments.
60+ let shortPath = path . basename ( folderToRunCommandIn ) ;
61+ if ( containingWorkspacePath ) {
62+ const relativePath = path . relative ( containingWorkspacePath , folderToRunCommandIn ) ;
63+ if ( relativePath ) {
64+ shortPath = relativePath . includes ( path . sep )
65+ ? relativePath . split ( path . sep ) . slice ( - 2 ) . join ( path . sep )
66+ : relativePath ;
67+ }
68+ }
5869
59- return handler ( folderToRunCommandIn , args , shortPath , alwaysShowOutput ) ;
70+ return handler ( folderToRunCommandIn , args , shortPath , alwaysShowOutput , operationProgress ) ;
6071 }
6172
62- protected runFlutter ( args : string [ ] , selection : vs . Uri | undefined , alwaysShowOutput = false ) : Promise < RunProcessResult | undefined > {
63- return this . runCommandForWorkspace ( this . runFlutterInFolder . bind ( this ) , `Select the folder to run "flutter ${ args . join ( " " ) } " in` , args , selection , alwaysShowOutput ) ;
73+ protected runFlutter ( args : string [ ] , selection : vs . Uri | undefined , alwaysShowOutput = false , operationProgress ?: OperationProgress ) : Promise < RunProcessResult | undefined > {
74+ return this . runCommandForWorkspace ( this . runFlutterInFolder . bind ( this ) , `Select the folder to run "flutter ${ args . join ( " " ) } " in` , args , selection , alwaysShowOutput , operationProgress ) ;
6475 }
6576
66- protected runFlutterInFolder ( folder : string , args : string [ ] , shortPath : string | undefined , alwaysShowOutput = false , customScript ?: CustomScript ) : Promise < RunProcessResult | undefined > {
77+ protected runFlutterInFolder ( folder : string , args : string [ ] , shortPath : string | undefined , alwaysShowOutput = false , operationProgress ?: OperationProgress , customScript ?: CustomScript ) : Promise < RunProcessResult | undefined > {
6778 if ( ! this . sdks . flutter )
6879 throw new Error ( "Flutter SDK not available" ) ;
6980
@@ -77,25 +88,25 @@ export class BaseSdkCommands implements IAmDisposable {
7788 . concat ( config . for ( vs . Uri . file ( folder ) ) . flutterAdditionalArgs )
7889 . concat ( execution . args ) ;
7990
80- return this . runCommandInFolder ( shortPath , folder , execution . executable , allArgs , alwaysShowOutput ) ;
91+ return this . runCommandInFolder ( shortPath , folder , execution . executable , allArgs , alwaysShowOutput , operationProgress ) ;
8192 }
8293
83- protected runPub ( args : string [ ] , selection : vs . Uri | undefined , alwaysShowOutput = false ) : Promise < RunProcessResult | undefined > {
84- return this . runCommandForWorkspace ( this . runPubInFolder . bind ( this ) , `Select the folder to run "pub ${ args . join ( " " ) } " in` , args , selection , alwaysShowOutput ) ;
94+ protected runPub ( args : string [ ] , selection : vs . Uri | undefined , alwaysShowOutput = false , operationProgress ?: OperationProgress ) : Promise < RunProcessResult | undefined > {
95+ return this . runCommandForWorkspace ( this . runPubInFolder . bind ( this ) , `Select the folder to run "pub ${ args . join ( " " ) } " in` , args , selection , alwaysShowOutput , operationProgress ) ;
8596 }
8697
87- protected runPubInFolder ( folder : string , args : string [ ] , shortPath : string , alwaysShowOutput = false ) : Promise < RunProcessResult | undefined > {
98+ protected runPubInFolder ( folder : string , args : string [ ] , shortPath : string , alwaysShowOutput = false , operationProgress ?: OperationProgress ) : Promise < RunProcessResult | undefined > {
8899 if ( ! this . sdks . dart )
89100 throw new Error ( "Dart SDK not available" ) ;
90101
91102 args = args . concat ( ...config . for ( vs . Uri . file ( folder ) ) . pubAdditionalArgs ) ;
92103
93104 const pubExecution = getPubExecutionInfo ( this . dartCapabilities , this . sdks . dart , args ) ;
94105
95- return this . runCommandInFolder ( shortPath , folder , pubExecution . executable , pubExecution . args , alwaysShowOutput ) ;
106+ return this . runCommandInFolder ( shortPath , folder , pubExecution . executable , pubExecution . args , alwaysShowOutput , operationProgress ) ;
96107 }
97108
98- protected async runCommandInFolder ( shortPath : string | undefined , folder : string , binPath : string , args : string [ ] , alwaysShowOutput : boolean ) : Promise < RunProcessResult | undefined > {
109+ protected async runCommandInFolder ( shortPath : string | undefined , folder : string , binPath : string , args : string [ ] , alwaysShowOutput : boolean , operationProgress ?: OperationProgress ) : Promise < RunProcessResult | undefined > {
99110 shortPath = shortPath || path . basename ( folder ) ;
100111 const commandName = path . basename ( binPath ) . split ( "." ) [ 0 ] ; // Trim file extension.
101112
@@ -113,11 +124,7 @@ export class BaseSdkCommands implements IAmDisposable {
113124 return Promise . resolve ( undefined ) ;
114125 }
115126
116- return await vs . window . withProgress ( {
117- cancellable : true ,
118- location : vs . ProgressLocation . Notification ,
119- title : `${ commandName } ${ args . join ( " " ) } ` ,
120- } , ( progress , token ) => {
127+ const runWithProgress = async ( progress : vs . Progress < { message ?: string ; increment ?: number } > , token : vs . CancellationToken ) => {
121128 if ( existingProcess ) {
122129 progress . report ( { message : "terminating previous command..." } ) ;
123130 existingProcess . cancel ( ) ;
@@ -127,7 +134,7 @@ export class BaseSdkCommands implements IAmDisposable {
127134
128135 const process = new ChainedProcess ( ( ) => {
129136 channel . appendLine ( `[${ shortPath } ] ${ commandName } ${ args . join ( " " ) } ` ) ;
130- progress . report ( { message : "running ..." } ) ;
137+ progress . report ( { message : ` ${ shortPath } ...` } ) ;
131138 const proc = safeToolSpawn ( folder , binPath , args ) ;
132139 channels . runProcessInOutputChannel ( proc , channel ) ;
133140 this . logger . info ( `(PROC ${ proc . pid } ) Spawned ${ binPath } ${ args . join ( " " ) } in ${ folder } ` , LogCategory . CommandProcesses ) ;
@@ -148,7 +155,16 @@ export class BaseSdkCommands implements IAmDisposable {
148155 token . onCancellationRequested ( ( ) => process . cancel ( ) ) ;
149156
150157 return process . completed ;
151- } ) ;
158+ } ;
159+
160+ if ( operationProgress )
161+ return runWithProgress ( operationProgress . progressReporter , operationProgress . cancellationToken ) ;
162+
163+ return await vs . window . withProgress ( {
164+ cancellable : true ,
165+ location : vs . ProgressLocation . Notification ,
166+ title : `${ commandName } ${ args . join ( " " ) } ` ,
167+ } , ( progress , token ) => runWithProgress ( progress , token ) ) ;
152168 }
153169
154170 public dispose ( ) : any {
0 commit comments