-
Notifications
You must be signed in to change notification settings - Fork 293
/
Copy pathbreakpointTerminationCondition.ts
115 lines (96 loc) · 3.46 KB
/
breakpointTerminationCondition.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import { ITerminationConditionFactory, ITerminationCondition } from './terminationCondition';
import * as nls from 'vscode-nls';
import { injectable } from 'inversify';
import * as vscode from 'vscode';
import * as path from 'path';
import Dap from '../../dap/api';
const localize = nls.loadMessageBundle();
const boolToInt = (v: boolean) => (v ? 1 : 0);
type BreakpointPickItem = { id: number } & vscode.QuickPickItem;
@injectable()
export class BreakpointTerminationConditionFactory implements ITerminationConditionFactory {
public readonly sortOrder = 2;
public readonly label = localize('profile.termination.breakpoint.label', 'Pick Breakpoint');
public readonly description = localize(
'profile.termination.breakpoint.description',
'Run until a specific breakpoint is hit',
);
public async onPick(session: vscode.DebugSession) {
const quickPick = vscode.window.createQuickPick<BreakpointPickItem>();
quickPick.canSelectMany = true;
quickPick.busy = true;
const chosen = await new Promise<ReadonlyArray<BreakpointPickItem> | undefined>(resolve => {
quickPick.onDidAccept(() => resolve(quickPick.selectedItems));
quickPick.onDidHide(() => resolve());
quickPick.show();
session.customRequest('getBreakpoints').then(({ breakpoints }) => {
quickPick.items = quickPick.selectedItems = this.getCandidates(breakpoints);
quickPick.busy = false;
});
});
quickPick.dispose();
if (!chosen) {
return;
}
return new BreakpointTerminationCondition(chosen.map(c => Number(c.id)));
}
private getCandidates(breakpoints: Dap.Breakpoint[]): BreakpointPickItem[] {
const filteredBps: {
relpath: string;
line: number;
column: number;
id: number;
verified: boolean;
}[] = [];
for (const breakpoint of breakpoints) {
if (!breakpoint.source || !breakpoint.id) {
continue;
}
let relpath: string;
if (!breakpoint.source.path) {
relpath = `<unknown>${path.sep}${breakpoint.source.name}`;
} else if (breakpoint.source.sourceReference === 0 && breakpoint.source.path) {
const folder = vscode.workspace.getWorkspaceFolder(vscode.Uri.file(breakpoint.source.path));
relpath = folder
? path.relative(folder.uri.fsPath, breakpoint.source.path)
: breakpoint.source.path;
} else {
relpath = breakpoint.source.name || breakpoint.source.path;
}
filteredBps.push({
relpath,
verified: breakpoint.verified,
id: breakpoint.id,
line: breakpoint.line ?? 1,
column: breakpoint.column ?? 1,
});
}
return filteredBps
.sort(
(a, b) =>
boolToInt(b.verified) - boolToInt(a.verified) ||
a.relpath.localeCompare(b.relpath) ||
a.line - b.line ||
a.column - b.column,
)
.map(c => ({
id: c.id,
label: [path.basename(c.relpath), c.line, c.column].join(':'),
description: c.relpath,
}));
}
}
class BreakpointTerminationCondition implements ITerminationCondition {
public get customData() {
return {
stopAtBreakpoint: this.breakpointIds.slice(),
};
}
constructor(private readonly breakpointIds: ReadonlyArray<number>) {}
public dispose() {
// no-op
}
}