Skip to content

Commit 9484168

Browse files
committed
Package update:
Enhanchement: Watch expressions are now supported. (Kindari/SublimeXdebug#71). Performance: Minimized amount of requests by setting 'max_depth' and 'max_children' on session start.
1 parent 957b1c5 commit 9484168

9 files changed

+257
-69
lines changed

Context.sublime-menu

+13-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,24 @@
1313
"command": "xdebug_conditional_breakpoint"
1414
},
1515
{
16-
"caption": "Clear All Breakpoints",
16+
"caption": "Clear Breakpoints",
1717
"command": "xdebug_clear_breakpoints"
1818
},
1919
{
2020
"caption": "-"
2121
},
22+
{
23+
"caption": "Set Watch Expression",
24+
"command": "xdebug_watch"
25+
},
26+
{
27+
"caption": "Clear Watch Expressions",
28+
"command": "xdebug_watch",
29+
"args" : {"clear" : true}
30+
},
31+
{
32+
"caption": "-"
33+
},
2234
{
2335
"caption": "Run",
2436
"command": "xdebug_continue",

Default.sublime-commands

+10-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,18 @@
3131
"command": "xdebug_conditional_breakpoint"
3232
},
3333
{
34-
"caption": "Xdebug: Clear All Breakpoints",
34+
"caption": "Xdebug: Clear Breakpoints",
3535
"command": "xdebug_clear_breakpoints"
3636
},
37+
{
38+
"caption": "Xdebug: Set Watch Expression",
39+
"command": "xdebug_watch"
40+
},
41+
{
42+
"caption": "Xdebug: Clear Watch Expressions",
43+
"command": "xdebug_watch",
44+
"args" : {"clear" : true}
45+
},
3746
{
3847
"caption": "Xdebug: Session - Evaluate",
3948
"command": "xdebug_evaluate"

Main.sublime-menu

+13-1
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,24 @@
4343
"command": "xdebug_conditional_breakpoint"
4444
},
4545
{
46-
"caption": "Clear All Breakpoints",
46+
"caption": "Clear Breakpoints",
4747
"command": "xdebug_clear_breakpoints"
4848
},
4949
{
5050
"caption": "-"
5151
},
52+
{
53+
"caption": "Set Watch Expression",
54+
"command": "xdebug_watch"
55+
},
56+
{
57+
"caption": "Clear Watch Expressions",
58+
"command": "xdebug_watch",
59+
"args" : {"clear" : true}
60+
},
61+
{
62+
"caption": "-"
63+
},
5264
{
5365
"caption": "Evaluate",
5466
"command": "xdebug_evaluate"

Xdebug.tmLanguage

+54
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,60 @@
184184
<key>name</key>
185185
<string>xdebug.output.breakpoint.line</string>
186186
</dict>
187+
<dict>
188+
<key>captures</key>
189+
<dict>
190+
<key>1</key>
191+
<dict>
192+
<key>name</key>
193+
<string>entity.other.attribute-name.anchor.settings</string>
194+
</dict>
195+
<key>2</key>
196+
<dict>
197+
<key>name</key>
198+
<string>keyword.operator.settings</string>
199+
</dict>
200+
<key>3</key>
201+
<dict>
202+
<key>name</key>
203+
<string>variable.other.settings</string>
204+
</dict>
205+
<key>4</key>
206+
<dict>
207+
<key>name</key>
208+
<string>keyword.operator.settings</string>
209+
</dict>
210+
<key>5</key>
211+
<dict>
212+
<key>name</key>
213+
<string>support.type.settings</string>
214+
</dict>
215+
<key>6</key>
216+
<dict>
217+
<key>name</key>
218+
<string>string.quoted.settings</string>
219+
</dict>
220+
<key>7</key>
221+
<dict>
222+
<key>name</key>
223+
<string>support.type.settings</string>
224+
</dict>
225+
<key>8</key>
226+
<dict>
227+
<key>name</key>
228+
<string>variable.parameter.settings</string>
229+
</dict>
230+
<key>9</key>
231+
<dict>
232+
<key>name</key>
233+
<string>comment.line.settings</string>
234+
</dict>
235+
</dict>
236+
<key>match</key>
237+
<string>^(?:(\|\+\|)|(\|-\|)|)\s+(\S*)\s+(?:(=)\s+(?:(\(.*?\))\s(.*)|(\S*)(\[.*\])|(&lt;.*&gt;))|.*)</string>
238+
<key>name</key>
239+
<string>xdebug.output.watch.entry</string>
240+
</dict>
187241
</array>
188242
<key>scopeName</key>
189243
<string>xdebug.output</string>

main.py

+72-6
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,21 @@ def run(self, edit):
166166
self.view.window().run_command('xdebug_execute', {'command': 'run'})
167167

168168

169-
class XdebugRunToLineCommand(sublime_plugin.TextCommand):
169+
class XdebugRunToLineCommand(sublime_plugin.WindowCommand):
170170
"""
171171
Run script to current selected line in view, ignoring all other breakpoints.
172172
"""
173-
def run(self, edit):
173+
def run(self):
174+
view = sublime.active_window().active_view()
175+
# Unable to run to line when no view available
176+
if view is None:
177+
return
174178
# Determine filename for current view and check if is a valid filename
175-
filename = self.view.file_name()
179+
filename = view.file_name()
176180
if not filename or not os.path.isfile(filename):
177181
return
178182
# Get first line from selected rows and make sure it is not empty
179-
rows = V.region_to_rows(self.view.sel(), filter_empty=True)
183+
rows = V.region_to_rows(filter_empty=True)
180184
if rows is None or len(rows) == 0:
181185
return
182186
lineno = rows[0]
@@ -188,8 +192,8 @@ def run(self, edit):
188192
if not breakpoint_exists:
189193
S.BREAKPOINT_RUN = { 'filename': filename, 'lineno': lineno }
190194
# Set breakpoint and run script
191-
self.view.run_command('xdebug_breakpoint', {'rows': [lineno], 'enabled': True, 'filename': filename})
192-
self.view.window().run_command('xdebug_execute', {'command': 'run'})
195+
view.run_command('xdebug_breakpoint', {'rows': [lineno], 'enabled': True, 'filename': filename})
196+
self.window.run_command('xdebug_execute', {'command': 'run'})
193197

194198
def is_enabled(self):
195199
return S.BREAKPOINT_ROW is not None and session.is_connected()
@@ -231,6 +235,20 @@ def connected(self):
231235
# Connection initialization
232236
init = S.SESSION.read()
233237

238+
# More detailed internal information on properties
239+
S.SESSION.send(dbgp.FEATURE_SET, n='show_hidden', v=1)
240+
response = S.SESSION.read()
241+
242+
# Set max depth limit
243+
max_depth = S.get_project_value('max_depth') or S.get_package_value('max_depth') or S.MAX_DEPTH
244+
S.SESSION.send(dbgp.FEATURE_SET, n=dbgp.FEATURE_NAME_MAXDEPTH, v=max_depth)
245+
response = S.SESSION.read()
246+
247+
# Set max children limit
248+
max_children = S.get_project_value('max_children') or S.get_package_value('max_children') or S.MAX_CHILDREN
249+
S.SESSION.send(dbgp.FEATURE_SET, n=dbgp.FEATURE_NAME_MAXCHILDREN, v=max_children)
250+
response = S.SESSION.read()
251+
234252
# Set breakpoints for files
235253
for filename, breakpoint_data in S.BREAKPOINT.items():
236254
if breakpoint_data:
@@ -389,6 +407,9 @@ def run(self, command=None):
389407
stack = session.get_stack_values()
390408
V.show_content(V.DATA_STACK, stack)
391409

410+
# Watch expressions
411+
V.show_content(V.DATA_WATCH)
412+
392413
# Reload session when session stopped, by reaching end of file or interruption
393414
if response.get(dbgp.ATTRIBUTE_STATUS) == dbgp.STATUS_STOPPING or response.get(dbgp.ATTRIBUTE_STATUS) == dbgp.STATUS_STOPPED:
394415
self.window.run_command('xdebug_session_stop')
@@ -549,6 +570,50 @@ def is_visible(self):
549570
return session.is_connected()
550571

551572

573+
class XdebugWatchCommand(sublime_plugin.WindowCommand):
574+
"""
575+
Add/Remove watch condition.
576+
"""
577+
watch_index = None
578+
def run(self, clear=False):
579+
if clear:
580+
S.WATCH.clear()
581+
# Update watch view
582+
try:
583+
if sublime.active_window().get_layout() == S.LAYOUT_DEBUG:
584+
V.show_content(V.DATA_WATCH)
585+
except:
586+
pass
587+
else:
588+
# Show user input for setting watch expression
589+
self.window.show_input_panel('Watch expression', '', self.on_done, self.on_change, self.on_cancel)
590+
591+
def on_done(self, expression):
592+
if not expression:
593+
return
594+
# Add/update watch expression to session
595+
watch = {'expression': expression, 'enabled': True, 'value': None, 'type': None}
596+
if self.watch_index and isinstance(self.watch_index, int):
597+
try:
598+
S.WATCH[self.watch_index]['expression'] = expression
599+
except:
600+
S.WATCH.insert(self.watch_index, watch)
601+
else:
602+
S.WATCH.append(watch)
603+
# Update watch view
604+
try:
605+
if sublime.active_window().get_layout() == S.LAYOUT_DEBUG:
606+
V.show_content(V.DATA_WATCH)
607+
except:
608+
pass
609+
610+
def on_change(self, line):
611+
pass
612+
613+
def on_cancel(self):
614+
pass
615+
616+
552617
class XdebugViewUpdateCommand(sublime_plugin.TextCommand):
553618
"""
554619
Update content of sublime.Edit object in view, instead of using begin_edit/end_edit.
@@ -583,6 +648,7 @@ def run(self, layout='default', keymap=False):
583648
if not layout == 'debug':
584649
return
585650
# Reset data in debugging related windows
651+
V.show_content(V.DATA_WATCH)
586652
V.show_content(V.DATA_CONTEXT)
587653
V.show_content(V.DATA_BREAKPOINT)
588654
V.show_content(V.DATA_STACK)

xdebug/load.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import settings as S
1010

1111
# Load modules
12-
from .view import DATA_BREAKPOINT, DATA_CONTEXT, DATA_STACK, show_content, render_regions
12+
from .view import DATA_BREAKPOINT, DATA_CONTEXT, DATA_STACK, DATA_WATCH, show_content, render_regions
1313
from .util import load_breakpoint_data
1414
from .log import clear_output, debug, info
1515

@@ -30,6 +30,7 @@ def xdebug():
3030

3131
# Reset debug windows
3232
if sublime.active_window().get_layout() == S.LAYOUT_DEBUG:
33+
show_content(DATA_WATCH)
3334
show_content(DATA_CONTEXT)
3435
show_content(DATA_BREAKPOINT)
3536
show_content(DATA_STACK)

0 commit comments

Comments
 (0)