Skip to content

Commit d4ccfef

Browse files
committed
fix: try to restore low level component with new communication
not sure if functional, as i think i don't have a record with asm events
1 parent 02a325c commit d4ccfef

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

src/frontend/dap.nim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ func commandToCtResponseEventKind(command: cstring): CtEventKind =
155155
of "continue": DapContinueResponse
156156
of "stepBack": DapStepBackResponse
157157
of "reverseContinue": DapReverseContinueResponse
158-
of "ct/reverseStepIn": CtReverseStepIn
159-
of "ct/reverseStepOut": CtReverseStepOut
158+
of "ct/reverseStepIn": CtReverseStepInResponse
159+
of "ct/reverseStepOut": CtReverseStepOutResponse
160+
of "ct/load-asm-function": CtLoadAsmFunctionResponse
160161
else: raise newException(
161162
ValueError,
162163
"no ct event kind response for command: \"" & $command & "\" defined")

src/frontend/types.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ type
750750
viewDom*: JsAssoc[int, kdom.Node]
751751
mutationObserver*: MutationObserver
752752
path*: cstring
753+
partialTabInfo*: TabInfo
753754

754755
EditorViewComponent* = ref object of Component
755756
editorView*: EditorView

src/frontend/ui/low_level_code.nim

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ui_imports, ../types, ../ui_helpers, ../renderer
1+
import ui_imports, ../types, ../ui_helpers, ../renderer, ../communication, ../../common/ct_event
22

33
const NO_LINE = -1
44

@@ -83,16 +83,32 @@ proc findHighlight(self: LowLevelCodeComponent, selectedLine: int): int =
8383

8484
return -1
8585

86-
proc getAsmCode(self: LowLevelCodeComponent, location: types.Location) {.async.} =
87-
var tabInfo = TabInfo(
86+
proc loadAsm*(self: LowLevelCodeComponent, location: types.Location) =
87+
var functionLocation = FunctionLocation(
88+
path: location.path,
89+
name: location.functionName,
90+
key: location.key,
91+
forceReload: location.path.split(".")[^1] == "nr" # Force reload on move for noir files
92+
)
93+
self.api.emit(CtLoadAsmFunction, functionLocation)
94+
95+
96+
proc getAsmCode(self: LowLevelCodeComponent, location: types.Location) =
97+
let tabInfo = TabInfo(
8898
name: self.editor.name,
8999
location: location,
90100
loading: false,
91101
noInfo: false,
92102
lang: LangAsm,
93103
)
94104

95-
tabInfo.instructions = await data.services.editor.asmLoad(location)
105+
self.partialTabInfo = tabInfo
106+
self.location = location
107+
self.loadAsm(location)
108+
109+
proc onLoadAsmFunctionResponse(self: LowLevelCodeComponent, instructions: Instructions) =
110+
var tabInfo = self.partialTabInfo
111+
tabInfo.instructions = instructions
96112
tabInfo.sourceLines = tabInfo.instructions.instructions.mapIt(formatLine(it))
97113
tabInfo.source = tabInfo.sourceLines.join(jsNl) & jsNl
98114
self.editor.tabInfo = tabInfo
@@ -104,7 +120,7 @@ proc getAsmCode(self: LowLevelCodeComponent, location: types.Location) {.async.}
104120
50
105121
)
106122

107-
self.editor.tabInfo.highlightLine = self.findHighlight(location.highLevelLine)
123+
self.editor.tabInfo.highlightLine = self.findHighlight(self.location.highLevelLine)
108124
self.data.redraw()
109125

110126
proc clear(self: LowLevelCodeComponent, location: types.Location) =
@@ -141,19 +157,24 @@ proc clear(self: LowLevelCodeComponent, location: types.Location) =
141157

142158
proc reloadLowLevel*(self: LowLevelCodeComponent) =
143159
self.clear()
144-
discard self.getAsmCode(data.services.debugger.location)
160+
self.getAsmCode(data.services.debugger.location)
145161

146162
method onCompleteMove*(self: LowLevelCodeComponent, response: MoveState) {.async.} =
147163
if response.location.path != "":
148164
self.clear(response.location)
149-
discard self.getAsmCode(response.location)
165+
self.getAsmCode(response.location)
166+
167+
method register*(self: LowLevelCodeComponent, api: MediatorWithSubscribers) =
168+
self.api = api
169+
self.api.subscribe(CtLoadAsmFunctionResponse, proc(kind: CtEventKind, instructions: Instructions, sub: Subscriber) =
170+
self.onLoadAsmFunctionResponse(instructions))
150171

151172
method render*(self: LowLevelCodeComponent): VNode =
152173
if self.editor.renderer.isNil:
153174
self.editor.renderer = kxiMap[fmt"lowLevelCodeComponent-{self.id}"]
154175

155176
if self.editor.tabInfo.isNil: # or self.editor.tabInfo.instructions.instructions.len() == 0
156-
discard self.getAsmCode(data.services.debugger.location)
177+
self.getAsmCode(data.services.debugger.location)
157178

158179
result = buildHtml(
159180
tdiv(class = componentContainerClass("low-level-code"))

0 commit comments

Comments
 (0)