| 15 | */ |
| 16 | @injectable() |
| 17 | export class ProgressReporter implements IProgressReporter { |
| 18 | private progressReporters: VSCProgress<{ message?: string | undefined; increment?: number | undefined }>[] = []; |
| 19 | private actionPhases = new Map<ReportableAction, 'started' | 'completed'>(); |
| 20 | private currentActions: ReportableAction[] = []; |
| 21 | private get currentAction(): ReportableAction | undefined { |
| 22 | return this.currentActions.length === 0 ? undefined : this.currentActions[this.currentActions.length - 1]; |
| 23 | } |
| 24 | |
| 25 | constructor() { |
| 26 | registerReporter(this); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Create and display a progress indicator for starting of Jupyter Notebooks. |
| 31 | * |
| 32 | * @param {string} message |
| 33 | * @returns {(IDisposable & { token: CancellationToken })} |
| 34 | * @memberof ProgressReporter |
| 35 | */ |
| 36 | public createProgressIndicator(message: string, cancellable = false): IDisposable & { token: CancellationToken } { |
| 37 | const cancellation = new CancellationTokenSource(); |
| 38 | const deferred = createDeferred(); |
| 39 | const options = { location: ProgressLocation.Notification, cancellable: cancellable, title: message }; |
| 40 | |
| 41 | window |
| 42 | .withProgress(options, async (progress, cancelToken) => { |
| 43 | cancelToken.onCancellationRequested(() => { |
| 44 | if (cancelToken.isCancellationRequested) { |
| 45 | cancellation.cancel(); |
| 46 | } |
| 47 | deferred.resolve(); |
| 48 | }); |
| 49 | cancellation.token.onCancellationRequested(() => { |
| 50 | deferred.resolve(); |
| 51 | }); |
| 52 | this.progressReporters.push(progress); |
| 53 | await deferred.promise; |
| 54 | }) |
| 55 | .then(noop, noop); |
| 56 | |
| 57 | return { |
| 58 | token: cancellation.token, |
| 59 | dispose: () => deferred.resolve() |
| 60 | }; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Reports progress to the user. |
| 65 | * Keep messages in a stack. As we have new actions taking place place them in a stack and notify progress. |
| 66 | * As they finish pop them from the stack (if currently displayed). |
| 67 | * We need a stack, as we have multiple async actions taking place, and each stat & can complete at different times. |
| 68 | * |
| 69 | * @param {Progress} progress |
| 70 | * @returns {void} |
| 71 | * @memberof JupyterStartupProgressReporter |
| 72 | */ |
| 73 | public report(progress: Progress): void { |
| 74 | if (this.progressReporters.length === 0) { |
nothing calls this directly
no outgoing calls
no test coverage detected