Skip to content

Commit 761790f

Browse files
committed
make some enhancements
1 parent ce65832 commit 761790f

File tree

2 files changed

+88
-8
lines changed

2 files changed

+88
-8
lines changed

lib/breakpoint-store.coffee

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ class BreakpointStore
2121
d = editor.decorateMarker(marker, type: "line-number", class: "line-number-red")
2222
d.setProperties(type: "line-number", class: "line-number-red")
2323
breakpoint.decoration = d
24+
return "b"
2425
else
2526
editor = atom.workspace.getActiveTextEditor()
2627
ds = editor.getLineNumberDecorations(type: "line-number", class: "line-number-red")
2728
for d in ds
2829
marker = d.getMarker()
2930
marker.destroy() if marker.getBufferRange().start.row == breakpoint.lineNumber-1
31+
return "cl"
3032

3133
containsBreakpoint: (bp) ->
3234
for breakpoint in @breakpoints

lib/python-debugger-view.coffee

Lines changed: 86 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,67 @@ class PythonDebuggerView extends View
3232
@subview "commandEntryView", new TextEditorView
3333
mini: true,
3434
placeholderText: "> Enter debugger commands here"
35+
@button outlet: "breakpointBtn", click: "toggleBreak", class: "btn", =>
36+
@span "break point"
37+
@button class: "btn", =>
38+
@span " "
3539
@button outlet: "runBtn", click: "runApp", class: "btn", =>
3640
@span "run"
3741
@button outlet: "stopBtn", click: "stopApp", class: "btn", =>
3842
@span "stop"
39-
@button outlet: "clearBtn", click: "clearOutput", class: "btn", =>
40-
@span "clear"
43+
@button class: "btn", =>
44+
@span " "
4145
@button outlet: "stepOverBtn", click: "stepOverBtnPressed", class: "btn", =>
4246
@span "next"
4347
@button outlet: "stepInBtn", click: "stepInBtnPressed", class: "btn", =>
4448
@span "step"
45-
@button outlet: "continueBtn", click: "continueBtnPressed", class: "btn", =>
46-
@span "continue"
49+
@button outlet: "varBtn", click: "varBtnPressed", class: "btn", =>
50+
@span "variables"
51+
@button class: "btn", =>
52+
@span " "
4753
@button outlet: "returnBtn", click: "returnBtnPressed", class: "btn", =>
4854
@span "return"
55+
@button outlet: "continueBtn", click: "continueBtnPressed", class: "btn", =>
56+
@span "continue"
57+
@button class: "btn", =>
58+
@span " "
59+
@button outlet: "upBtn", click: "upBtnPressed", class: "btn", =>
60+
@span "up"
61+
@button outlet: "callstackBtn", click: "callstackBtnPressed", class: "btn", =>
62+
@span "callstack"
63+
@button outlet: "downBtn", click: "downBtnPressed", class: "btn", =>
64+
@span "down"
65+
@button class: "btn", =>
66+
@span " "
67+
@button outlet: "clearBtn", click: "clearOutput", class: "btn", =>
68+
@span "clear"
4969
@div class: "panel-body", outlet: "outputContainer", =>
5070
@pre class: "command-output", outlet: "output"
5171

72+
toggleBreak: ->
73+
editor = atom.workspace.getActiveTextEditor()
74+
filename = editor.getTitle()
75+
lineNumber = editor.getCursorBufferPosition().row + 1
76+
breakpoint = new Breakpoint(filename, lineNumber)
77+
cmd = @breakpointStore.toggle(breakpoint)
78+
if @backendDebugger
79+
@backendDebugger.stdin.write(cmd + " " + @getCurrentFilePath() + ":" + lineNumber + "\n")
80+
@output.empty()
81+
for breakpoint in @breakpointStore.breakpoints
82+
@output.append(breakpoint.toCommand() + "\n")
83+
84+
upBtnPressed: ->
85+
@output.empty()
86+
@backendDebugger?.stdin.write("up\nbt\n")
87+
88+
callstackBtnPressed: ->
89+
@output.empty()
90+
@backendDebugger?.stdin.write("bt\n")
91+
92+
downBtnPressed: ->
93+
@output.empty()
94+
@backendDebugger?.stdin.write("down\nbt\n")
95+
5296
stepOverBtnPressed: ->
5397
@backendDebugger?.stdin.write("n\n")
5498

@@ -78,12 +122,39 @@ class PythonDebuggerView extends View
78122
return
79123
@runBackendDebugger()
80124

125+
varBtnPressed: ->
126+
@output.empty()
127+
128+
@backendDebugger?.stdin.write("for (__k, __v) in [(__k, __v) for __k, __v in globals().items() if not __k.startswith('__')]: print __k, '=', __v\n")
129+
@backendDebugger?.stdin.write("print '-------------'\n")
130+
@backendDebugger?.stdin.write("for (__k, __v) in [(__k, __v) for __k, __v in locals().items() if __k != 'self' and not __k.startswith('__')]: print __k, '=', __v\n")
131+
@backendDebugger?.stdin.write("for (__k, __v) in [(__k, __v) for __k, __v in (self.__dict__ if 'self' in locals().keys() else {}).items()]: print 'self.{0}'.format(__k), '=', __v\n")
132+
133+
134+
81135
# Extract the file name and line number output by the debugger.
82136
processDebuggerOutput: (data) ->
83137
data_str = data.toString().trim()
84138
lineNumber = null
85139
fileName = null
86-
140+
call_stack_str = "Call stack: \n"
141+
142+
m = /[^-]> (.*[.]py)[(]([0-9]*)[)].*/.exec(data_str)
143+
if m
144+
[fileName, lineNumber] = [m[1], m[2]]
145+
`
146+
re = /[\n](>*)[ \t]*(.*[.]py)[(]([0-9]*)[)]([^\n]*)[\n]([^\n]*)/gi;
147+
while ((match = re.exec(data_str)))
148+
{
149+
if (match[1].includes('>'))
150+
call_stack_str += '--> ';
151+
else
152+
call_stack_str += ' ';
153+
call_stack_str += match[5].replace("->", "") + " in " + match[4] + " @ " + match [2] + ": " + match[3] + "\n";
154+
}
155+
`
156+
data_str = call_stack_str
157+
87158
[data_str, tail] = data_str.split("line:: ")
88159
if tail
89160
[lineNumber, tail] = tail.split("\n")
@@ -98,9 +169,16 @@ class PythonDebuggerView extends View
98169

99170
if lineNumber && fileName
100171
lineNumber = parseInt(lineNumber)
101-
options = {initialLine: lineNumber-1, initialColumn:0}
102-
atom.workspace.open(fileName, options) if fs.existsSync(fileName)
103-
# TODO: add decoration to current line?
172+
editor = atom.workspace.getActiveTextEditor()
173+
if fileName.toLowerCase() == editor.getPath().toLowerCase()
174+
position = Point(lineNumber-1, 0)
175+
editor.setCursorBufferPosition(position)
176+
editor.unfoldBufferRow(lineNumber)
177+
editor.scrollToBufferPosition(position)
178+
else
179+
options = {initialLine: lineNumber-1, initialColumn:0}
180+
atom.workspace.open(fileName, options) if fs.existsSync(fileName)
181+
# TODO: add decoration to current line?
104182

105183
@addOutput(data_str.trim())
106184

0 commit comments

Comments
 (0)