Elffuss BraidHub

kikocis/continue public

main · 2.3 KiBRawPermalink
1import * as vscode from "vscode";
2
3import type { VsCodeIde } from "../VsCodeIde";
4import type { VsCodeWebviewProtocol } from "../webviewProtocol";
5
6export const threadStopped: Map<number, boolean> = new Map();
7// Arrays has better perf but you probably won't have thousands of threads in a single debug session
8
9export function registerDebugTracker(
10 webviewProtocol: VsCodeWebviewProtocol,
11 ide: VsCodeIde,
12) {
13 vscode.debug.registerDebugAdapterTrackerFactory("*", {
14 createDebugAdapterTracker(_session: vscode.DebugSession) {
15 const updateThreads = async () => {
16 webviewProtocol?.request("refreshSubmenuItems", {
17 providers: ["debugger"],
18 });
19 };
20
21 return {
22 async onWillStopSession() {
23 threadStopped.clear();
24 updateThreads();
25 },
26 async onDidSendMessage(message: any) {
27 if (message.type === "event") {
28 switch (message.event) {
29 case "continued":
30 case "stopped":
31 if (typeof message.body.threadId !== "undefined") {
32 threadStopped.set(
33 Number(message.body.threadId),
34 message.event === "stopped",
35 );
36 }
37
38 if (message.body.allThreadsStopped) {
39 threadStopped.forEach((_, key) =>
40 threadStopped.set(key, true),
41 );
42 }
43
44 if (message.body.allThreadsContinued) {
45 threadStopped.forEach((_, key) =>
46 threadStopped.set(key, false),
47 );
48 }
49
50 updateThreads();
51 break;
52
53 case "thread":
54 if (message.body.reason === "exited") {
55 threadStopped.delete(Number(message.body.threadId));
56 } else if (message.body.reason === "started") {
57 threadStopped.set(Number(message.body.threadId), false);
58 }
59 // somehow the threadId does not respect the specification in my vscodium (debugging C++)
60 // expecting a number but got a string instead
61 break;
62
63 default:
64 break;
65 }
66 }
67 },
68 };
69 },
70 });
71}