-
Notifications
You must be signed in to change notification settings - Fork 3
/
debugger-context.coffee
88 lines (71 loc) · 2.05 KB
/
debugger-context.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
StateMachine = require 'javascript-state-machine'
q = require 'q'
Client = require './client'
module.exports =
class DebuggerContext
constructor: ->
@client = new Client()
@backtrace = []
@locals = []
@globals = []
@state = StateMachine.create
initial: 'disconnected'
events: [
{ name: 'connect', from: 'disconnected', to: 'connected' }
{ name: 'start', from: 'connected', to: 'running' }
{ name: 'pause', from: 'running', to: 'paused' }
{ name: 'continue', from: 'paused', to: 'running' }
{ name: 'disconnect', from: '*', to: 'disconnected' }
]
@client.onPaused (args...) => @paused(args...)
@client.onDisconnected => @disconnected()
isConnected: =>
not @isDisconnected()
isDisconnected: =>
@state.is('disconnected')
isRunning: ->
@state.is('running')
isPaused: =>
@state.is('paused')
connect: =>
@client
.connect()
.then => @state.connect()
.catch (e) ->
# most probably "Error: connect ECONNREFUSED 127.0.0.1:1234" because rdebug-ide hasn't been started
atom.notifications.addError e.toString(), dismissable: true
disconnect: =>
@client.disconnect()
disconnected: ->
@state.disconnect()
pause: ->
@client.pause()
stepIn: ->
@state.continue()
@client.stepIn()
stepOut: ->
@state.continue()
@client.stepOut()
stepOver: ->
@state.continue()
@client.stepOver()
# TODO: when to reset @backtrace etc to be empty? look at how Chrome debugger does it. maybe write some tests
paused: (breakpoint) ->
@state.pause()
atom.workspace.open(breakpoint.file, initialLine: breakpoint.line - 1)
q.all([
@client.backtrace()
@client.localVariables()
@client.globalVariables()
])
.then ([@backtrace, @locals, @globals]) => null
.done()
play: ->
if @state.can('start')
@client.start()
@state.start()
else
@client.continue()
@state.continue()
destroy: ->
@client.destroy()