@@ -5,6 +5,38 @@ import communication, dap
55import event_helpers
66
77# backend(dap) <-> middleware <-> view (self-contained, can be separate: 0, 1 or more components);
8+ var tracepointMap: JsAssoc [cstring , JsAssoc [int , Tracepoint ]] = Jsassoc [cstring , JsAssoc [int , Tracepoint ]]{}
9+ var sessionCounter = 0
10+
11+ proc getTraceSession (name: cstring = " /home/nedy/calls.rb" ): TraceSession =
12+ var results = JsAssoc [int , seq [Stop ]]{}
13+ var tracepoints: seq [Tracepoint ] = @ []
14+
15+ for line, trace in tracepointMap[name]:
16+ if trace.expression != " " and trace.isChanged:
17+ tracepoints.add (trace)
18+
19+ result = TraceSession (
20+ tracepoints: tracepoints,
21+ lastCount: 0 ,
22+ results: results,
23+ id: sessionCounter
24+ )
25+ sessionCounter += 1
26+
27+ return result
28+
29+ proc updateTraceMap (tracepoint: Tracepoint ) =
30+ if not tracepointMap.hasKey (tracepoint.name):
31+ tracepointMap[tracepoint.name] = JsAssoc [int , Tracepoint ]{}
32+ tracepointMap[tracepoint.name][tracepoint.line] = tracepoint
33+ return
34+
35+ if not tracepointMap[tracepoint.name].hasKey (tracepoint.line):
36+ tracepointMap[tracepoint.name][tracepoint.line] = tracepoint
37+ return
38+
39+ tracepointMap[tracepoint.name][tracepoint.line] = tracepoint
840
941when not defined (ctInExtension):
1042 import utils
@@ -149,6 +181,19 @@ proc setupMiddlewareApis*(dapApi: DapApi, viewsApi: MediatorWithSubscribers) {.e
149181 if not lastCompleteMove.isNil:
150182 viewsApi.emit (CtCompleteMove , lastCompleteMove.toJs)
151183 )
184+ viewsApi.subscribe (InternalTraceMapUpdate , proc (kind: CtEventKind , value: Tracepoint , sub: Subscriber ) =
185+ updateTraceMap (value)
186+ )
187+ viewsApi.subscribe (CtRunTraceSession , proc (kind: CtEventKind , value: EmptyArg , sub: Subscriber ) =
188+ let traceSession = getTraceSession (" /home/nedy/calls.rb" .cstring )
189+ dapApi.sendCtRequest (
190+ CtRunTracepoints ,
191+ RunTracepointsArg (
192+ session: traceSession,
193+ stopAfter: NO_LIMIT
194+ ).toJs
195+ )
196+ )
152197
153198when defined (ctInExtension):
154199 when defined (ctInCentralExtensionContext):
0 commit comments