1- import ui_imports, ../ types, ../ ui_helpers, ../ renderer
1+ import ui_imports, ../ types, ../ ui_helpers, ../ renderer, ../ communication, ../../ common / ct_event
22
33const 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
110126proc clear (self: LowLevelCodeComponent , location: types.Location ) =
@@ -141,19 +157,24 @@ proc clear(self: LowLevelCodeComponent, location: types.Location) =
141157
142158proc reloadLowLevel * (self: LowLevelCodeComponent ) =
143159 self.clear ()
144- discard self.getAsmCode (data.services.debugger.location)
160+ self.getAsmCode (data.services.debugger.location)
145161
146162method 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
151172method 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