Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/debug/browser/debugProgress.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Event } from '../../../../base/common/event.js';
7
import { IDisposable, dispose } from '../../../../base/common/lifecycle.js';
8
import { IProgressService, ProgressLocation } from '../../../../platform/progress/common/progress.js';
9
import { IWorkbenchContribution } from '../../../common/contributions.js';
10
import { IDebugService, IDebugSession, VIEWLET_ID } from '../common/debug.js';
11
import { IViewsService } from '../../../services/views/common/viewsService.js';
12
13
export class DebugProgressContribution implements IWorkbenchContribution {
14
15
private toDispose: IDisposable[] = [];
16
17
constructor(
18
@IDebugService debugService: IDebugService,
19
@IProgressService progressService: IProgressService,
20
@IViewsService viewsService: IViewsService
21
) {
22
let progressListener: IDisposable | undefined;
23
const listenOnProgress = (session: IDebugSession | undefined) => {
24
if (progressListener) {
25
progressListener.dispose();
26
progressListener = undefined;
27
}
28
if (session) {
29
progressListener = session.onDidProgressStart(async progressStartEvent => {
30
const promise = new Promise<void>(r => {
31
// Show progress until a progress end event comes or the session ends
32
const listener = Event.any(Event.filter(session.onDidProgressEnd, e => e.body.progressId === progressStartEvent.body.progressId),
33
session.onDidEndAdapter)(() => {
34
listener.dispose();
35
r();
36
});
37
});
38
39
if (viewsService.isViewContainerVisible(VIEWLET_ID)) {
40
progressService.withProgress({ location: VIEWLET_ID }, () => promise);
41
}
42
const source = debugService.getAdapterManager().getDebuggerLabel(session.configuration.type);
43
progressService.withProgress({
44
location: ProgressLocation.Notification,
45
title: progressStartEvent.body.title,
46
cancellable: progressStartEvent.body.cancellable,
47
source,
48
delay: 500
49
}, progressStep => {
50
let total = 0;
51
const reportProgress = (progress: { message?: string; percentage?: number }) => {
52
let increment = undefined;
53
if (typeof progress.percentage === 'number') {
54
increment = progress.percentage - total;
55
total += increment;
56
}
57
progressStep.report({
58
message: progress.message,
59
increment,
60
total: typeof increment === 'number' ? 100 : undefined,
61
});
62
};
63
64
if (progressStartEvent.body.message) {
65
reportProgress(progressStartEvent.body);
66
}
67
const progressUpdateListener = session.onDidProgressUpdate(e => {
68
if (e.body.progressId === progressStartEvent.body.progressId) {
69
reportProgress(e.body);
70
}
71
});
72
73
return promise.then(() => progressUpdateListener.dispose());
74
}, () => session.cancel(progressStartEvent.body.progressId));
75
});
76
}
77
};
78
this.toDispose.push(debugService.getViewModel().onDidFocusSession(listenOnProgress));
79
listenOnProgress(debugService.getViewModel().focusedSession);
80
this.toDispose.push(debugService.onWillNewSession(session => {
81
if (!progressListener) {
82
listenOnProgress(session);
83
}
84
}));
85
}
86
87
dispose(): void {
88
dispose(this.toDispose);
89
}
90
}
91
92