Skip to content

Commit

Permalink
Fix broken scope navigation. Now clicking on scopes or objects evaluates
Browse files Browse the repository at this point in the history
the correct scope or object.

Python lambdas capture references not values at the time they are
instantiated. Capture a variable length tuple of args instead.
Seems more Pythonic?
  • Loading branch information
danmoseley committed Aug 2, 2015
1 parent bd2fc64 commit d74274c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
24 changes: 10 additions & 14 deletions swi.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ def run(self, edit):
line = 0

if scriptId and line > 0:
v.print_click(edit, v.size(), "%s:%d" % (url, line), lambda: open_script_and_focus_line(scriptId, str(line)))
v.print_click(edit, v.size(), "%s:%d" % (url, line), open_script_and_focus_line, scriptId, str(line))
else:
v.insert(edit, v.size(), "%s:%d" % (url, line))

Expand All @@ -856,8 +856,7 @@ def run(self, edit):
if len(message.parameters) > 0:
for param in message.parameters:
if param.type == 'object': #if channel here
callback = lambda: channel.send(webkit.Runtime.getProperties(param.objectId, True), console_add_properties, {'objectId': param.objectId})
v.print_click(edit, v.size(), str(param) + ' ', callback)
v.print_click(edit, v.size(), str(param) + ' ', channel.send, webkit.Runtime.getProperties(param.objectId, True), console_add_properties, {'objectId': param.objectId})
else:
v.insert(edit, v.size(), str(param) + ' ')
else:
Expand All @@ -875,8 +874,7 @@ def run(self, edit):
v.insert(edit, v.size(), '\t\u21E1 ')

if scriptId:
callback = lambda: open_script_and_focus_line(scriptId, str(callFrame.lineNumber))
v.print_click(edit, v.size(), "%s:%s %s" % (file_name, callFrame.lineNumber, callFrame.functionName), callback)
v.print_click(edit, v.size(), "%s:%s %s" % (file_name, callFrame.lineNumber, callFrame.functionName), open_script_and_focus_line, scriptId, str(callFrame.lineNumber))
else:
v.insert(edit, v.size(), "%s:%s %s" % (file_name, callFrame.lineNumber, callFrame.functionName))

Expand Down Expand Up @@ -947,8 +945,7 @@ def run(self, edit):
v.insert(edit, v.size(), prop.name + ': ')
if(prop.value):
if prop.value.type == 'object':
callback = lambda: channel.send(webkit.Runtime.getProperties(prop.value.objectId, True), console_add_properties, {'objectId': prop.value.objectId, 'file': file, 'line': line, 'name': prop.name, 'prev': prev})
v.print_click(edit, v.size(), str(prop.value) + '\n', callback)
v.print_click(edit, v.size(), str(prop.value) + '\n', channel.send, webkit.Runtime.getProperties(prop.value.objectId, True), console_add_properties, {'objectId': prop.value.objectId, 'file': file, 'line': line, 'name': prop.name, 'prev': prev})
else:
v.insert(edit, v.size(), str(prop.value) + '\n')

Expand All @@ -974,13 +971,13 @@ def run(self, edit):
v.erase(edit, sublime.Region(0, v.size()))

v.insert(edit, v.size(), "\n")
v.print_click(edit, v.size(), " Resume ", lambda: self.view.window().run_command('swi_debug_pause_resume'))
v.print_click(edit, v.size(), " Resume ", self.view.window().run_command, 'swi_debug_pause_resume')
v.insert(edit, v.size(), " ")
v.print_click(edit, v.size(), " Step Over ", lambda: self.view.window().run_command('swi_debug_step_over'))
v.print_click(edit, v.size(), " Step Over ", self.view.window().run_command, 'swi_debug_step_over')
v.insert(edit, v.size(), " ")
v.print_click(edit, v.size(), " Step Into ", lambda: self.view.window().run_command('swi_debug_step_into'))
v.print_click(edit, v.size(), " Step Into ", self.view.window().run_command, 'swi_debug_step_into')
v.insert(edit, v.size(), " ")
v.print_click(edit, v.size(), " Step Out ", lambda: self.view.window().run_command('swi_debug_step_out'))
v.print_click(edit, v.size(), " Step Out ", self.view.window().run_command, 'swi_debug_step_out')
v.insert(edit, v.size(), "\n\n")

for callFrame in callFrames:
Expand All @@ -993,7 +990,7 @@ def run(self, edit):
file_name = '-'

if file_name != '-':
v.print_click(edit, v.size(), "%s:%s" % (file_name, line), lambda: change_to_call_frame(callFrame))
v.print_click(edit, v.size(), "%s:%s" % (file_name, line), change_to_call_frame, callFrame)
else:
v.insert(edit, v.size(), "%s:%s" % (file_name, line))

Expand All @@ -1002,8 +999,7 @@ def run(self, edit):
for scope in callFrame.scopeChain:
v.insert(edit, v.size(), "\t")
if scope.object.type == 'object':
callback = lambda: channel.send(webkit.Runtime.getProperties(scope.object.objectId, True), console_add_properties, {'objectId': scope.object.objectId, 'name': "%s:%s (%s)" % (file_name, line, scope.type)})
v.print_click(edit, v.size(), "%s\n" % (scope.type), callback)
v.print_click(edit, v.size(), "%s\n" % (scope.type), channel.send, webkit.Runtime.getProperties(scope.object.objectId, True), console_add_properties, {'objectId': scope.object.objectId, 'name': "%s:%s (%s)" % (file_name, line, scope.type)})
else:
v.insert(edit, v.size(), "%s\n" % (scope.type))

Expand Down
6 changes: 3 additions & 3 deletions views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def rows(self, lines):
lines = [lines]
return [self.view.rowcol(line.begin())[0] + 1 for line in lines]

def print_click(self, edit, position, text, callback):
def print_click(self, edit, position, text, callback, *args):
""" Inserts the specified text and creates a clickable "button"
around it.
"""
Expand All @@ -106,7 +106,7 @@ def print_click(self, edit, position, text, callback):
break
insert_before += 1

self.callbacks.insert(insert_before, callback)
self.callbacks.insert(insert_before, { "callback": callback, "args": args })

regions.append(new_region)
self.view.add_regions('swi_log_clicks', regions, scope=utils.get_setting('interactive_scope'), flags=sublime.DRAW_NO_FILL)
Expand Down Expand Up @@ -137,7 +137,7 @@ def check_click(self):

if index < len(self.callbacks):
callback = self.callbacks[index]
callback()
callback["callback"](*callback["args"])

index += 1

Expand Down

0 comments on commit d74274c

Please sign in to comment.