@@ -146,10 +146,7 @@ export class ProgressService extends Disposable implements IProgressService {
146146 private withNotificationProgress < P extends Promise < R > , R = unknown > ( options : IProgressNotificationOptions , callback : ( progress : IProgress < { message ?: string , increment ?: number } > ) => P , onDidCancel ?: ( choice ?: number ) => void ) : P {
147147 const toDispose = new DisposableStore ( ) ;
148148
149- const createNotification = ( message : string | undefined , increment ?: number ) : INotificationHandle | undefined => {
150- if ( ! message ) {
151- return undefined ; // we need a message at least
152- }
149+ const createNotification = ( message : string , increment ?: number ) : INotificationHandle => {
153150
154151 const primaryActions = options . primaryActions ? Array . from ( options . primaryActions ) : [ ] ;
155152 const secondaryActions = options . secondaryActions ? Array . from ( options . secondaryActions ) : [ ] ;
@@ -222,29 +219,42 @@ export class ProgressService extends Disposable implements IProgressService {
222219 } ;
223220
224221 let handle : INotificationHandle | undefined ;
222+ let handleSoon : any | undefined ;
223+
224+ let titleAndMessage : string | undefined ; // hoisted to make sure a delayed notification shows the most recent message
225+
225226 const updateNotification = ( message ?: string , increment ?: number ) : void => {
226- if ( ! handle ) {
227- handle = createNotification ( message , increment ) ;
227+
228+ // full message (inital or update)
229+ if ( message && options . title ) {
230+ titleAndMessage = `${ options . title } : ${ message } ` ; // always prefix with overall title if we have it (https://github.com/Microsoft/vscode/issues/50932)
228231 } else {
229- if ( typeof message === 'string' ) {
230- let newMessage : string ;
231- if ( typeof options . title === 'string' ) {
232- newMessage = `${ options . title } : ${ message } ` ; // always prefix with overall title if we have it (https://github.com/Microsoft/vscode/issues/50932)
233- } else {
234- newMessage = message ;
235- }
232+ titleAndMessage = options . title || message ;
233+ }
236234
237- handle . updateMessage ( newMessage ) ;
235+ if ( ! handle && titleAndMessage ) {
236+ // create notification now or after a delay
237+ if ( typeof options . delay === 'number' && options . delay > 0 ) {
238+ if ( typeof handleSoon !== 'number' ) {
239+ handleSoon = setTimeout ( ( ) => handle = createNotification ( titleAndMessage ! , increment ) , options . delay ) ;
240+ }
241+ } else {
242+ handle = createNotification ( titleAndMessage , increment ) ;
238243 }
244+ }
239245
246+ if ( handle ) {
247+ if ( titleAndMessage ) {
248+ handle . updateMessage ( titleAndMessage ) ;
249+ }
240250 if ( typeof increment === 'number' ) {
241251 updateProgress ( handle , increment ) ;
242252 }
243253 }
244254 } ;
245255
246256 // Show initially
247- updateNotification ( options . title ) ;
257+ updateNotification ( ) ;
248258
249259 // Update based on progress
250260 const promise = callback ( {
@@ -255,6 +265,7 @@ export class ProgressService extends Disposable implements IProgressService {
255265
256266 // Show progress for at least 800ms and then hide once done or canceled
257267 Promise . all ( [ timeout ( 800 ) , promise ] ) . finally ( ( ) => {
268+ clearTimeout ( handleSoon ) ;
258269 if ( handle ) {
259270 handle . close ( ) ;
260271 }
0 commit comments