Skip to content

Commit 84abeae

Browse files
committed
WIP: Start support for experimental api for vscode editor inset
1 parent 0d9af97 commit 84abeae

File tree

8 files changed

+344
-155
lines changed

8 files changed

+344
-155
lines changed

src/common/ct_event.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type
6060
CtUpdatedFlow,
6161
CtRunToEntry,
6262
CtRunTracepoints,
63+
CtRunTraceSession,
6364
CtSetupTraceSession,
6465
CtLoadAsmFunction,
6566
CtLoadAsmFunctionResponse,
@@ -68,6 +69,7 @@ type
6869
InternalAddToScratchpadFromExpression,
6970
InternalStatusUpdate,
7071
InternalNewOperation,
72+
InternalTraceMapUpdate,
7173
CtNotification,
7274

7375
when defined(js):

src/frontend/dap.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ const EVENT_KIND_TO_DAP_MAPPING: array[CtEventKind, cstring] = [
100100
CtUpdatedFlow: "ct/updated-flow",
101101
CtRunToEntry: "ct/run-to-entry",
102102
CtRunTracepoints: "ct/run-tracepoints",
103+
CtRunTraceSession: "ct/run-trace-session",
103104
CtSetupTraceSession: "ct/setup-trace-session",
104105
CtLoadAsmFunction: "ct/load-asm-function",
105106
CtLoadAsmFunctionResponse: "",
@@ -108,6 +109,7 @@ const EVENT_KIND_TO_DAP_MAPPING: array[CtEventKind, cstring] = [
108109
InternalAddToScratchpadFromExpression: "",
109110
InternalStatusUpdate: "",
110111
InternalNewOperation: "",
112+
InternalTraceMapUpdate: "",
111113
CtNotification: "ct/notification",
112114
]
113115

src/frontend/middleware.nim

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,38 @@ import communication, dap
55
import 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

941
when 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

153198
when defined(ctInExtension):
154199
when defined(ctInCentralExtensionContext):

src/frontend/styles/components/tracepoint.styl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,6 @@
255255
.fa
256256
color: DROPDOWN_TEXT_BACKGROUND_COLOR
257257

258-
.trace-buttons-container
259-
display: flex
260-
gap: 6px
261-
262258
.run-trace-button
263259
border-radius: 6px;
264260
color: BORDER_COLOR;
@@ -301,6 +297,14 @@
301297
z-index: TRACE_LOG_EDITOR_Z_INDEX + 7
302298
top: 0
303299

300+
.trace-hamburger-svg
301+
height: 24px
302+
width: 24px
303+
background-image: TRACE_HAMBURGER_IMAGE
304+
background-size: 12px 8px
305+
background-repeat: no-repeat
306+
background-position: center
307+
304308
.trace-dropdown-menu
305309
display: none
306310

@@ -364,6 +368,16 @@
364368
margin: 0
365369
padding: 0
366370

371+
.trace-buttons-container
372+
display: flex
373+
gap: 6px
374+
375+
.trace-run-button-svg
376+
height: 24px
377+
width: 24px
378+
background-image: RUN_TRACEPOINT_IMAGE
379+
background-repeat: no-repeat
380+
367381
.kind-dropdown-menu
368382
background: #b8c0cf !important
369383
position: absolute

src/frontend/styles/default_dark_theme.styl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ BREAKPOINT_COLOR=#F87171
2121
TRACEPOINT_COLOR=#6366F1
2222
TRACEPOINT_LINE_NUMBER_COLOR=#c6c6c6
2323

24+
RUN_TRACEPOINT_IMAGE=url("../../public/resources/tracepoints/run_tracepoints_dark.svg")
25+
TRACE_HAMBURGER_IMAGE=url("../../public/resources/tracepoints/trace_hamburger_dark.svg")
26+
2427
NOUI_SLIDER_HANDLER_IMAGE=url("../../public/resources/shared/noUiSlider_handle_icon_dark.svg")
2528
NOUI_SLIDER_ACTIVE_HANDLER_IMAGE=url("../../public/resources/shared/noUiSlider_handle_active_icon_dark.svg")
2629
NOUI_SLIDER_HANDLER_BACKGROUND=#818181

src/frontend/ui/scratchpad.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,6 @@ method render*(self: ScratchpadComponent): VNode =
8484
else:
8585
tdiv(class = "empty-overlay"):
8686
text "You can add values from other components by right clicking on them and then click on 'Add value to scratchpad'."
87+
88+
proc registerScratchpadComponent*(component: ScratchpadComponent, api: MediatorWithSubscribers) {.exportc.} =
89+
component.register(api)

0 commit comments

Comments
 (0)