-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathSetBreakpoint.ts
More file actions
69 lines (60 loc) · 1.64 KB
/
SetBreakpoint.ts
File metadata and controls
69 lines (60 loc) · 1.64 KB
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
import {
Action,
ActionPreferences,
ActionReturnValue,
Graph,
TypedSelection,
} from "../typings/Types";
import {
SourceBreakpoint,
Location,
debug,
Uri,
Range,
Breakpoint,
} from "vscode";
import displayPendingEditDecorations from "../util/editDisplayUtils";
function getBreakpoints(uri: Uri, range: Range) {
return debug.breakpoints.filter(
(breakpoint) =>
breakpoint instanceof SourceBreakpoint &&
breakpoint.location.uri.toString() === uri.toString() &&
breakpoint.location.range.intersection(range) != null
);
}
export default class SetBreakpoint implements Action {
getTargetPreferences: () => ActionPreferences[] = () => [
{ insideOutsideType: "inside", selectionType: "line" },
];
constructor(private graph: Graph) {
this.run = this.run.bind(this);
}
async run([targets]: [
TypedSelection[],
TypedSelection[]
]): Promise<ActionReturnValue> {
await displayPendingEditDecorations(
targets,
this.graph.editStyles.referenced
);
const toAdd: Breakpoint[] = [];
const toRemove: Breakpoint[] = [];
targets.forEach((target) => {
const uri = target.selection.editor.document.uri;
const existing = getBreakpoints(uri, target.selection.selection);
if (existing.length > 0) {
toRemove.push(...existing);
} else {
toAdd.push(
new SourceBreakpoint(
new Location(uri, target.selection.selection.start)
)
);
}
});
debug.addBreakpoints(toAdd);
debug.removeBreakpoints(toRemove);
const thatMark = targets.map((target) => target.selection);
return { thatMark };
}
}