-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebugger-controller.js
More file actions
136 lines (97 loc) · 3.09 KB
/
debugger-controller.js
File metadata and controls
136 lines (97 loc) · 3.09 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
'use babel'
/* @flow */
import Breakpoint from './breakpoint'
import DebuggerRegistry from './debugger-registry'
import ProjectConfig from './project-config'
import ViewRegistry from './view-registry'
import type { Debugger, DebuggerView } from './types'
export default class DebuggerController {
debuggerRegistry: DebuggerRegistry;
viewRegistry: ViewRegistry;
constructor() {
this.debuggerRegistry = new DebuggerRegistry()
this.viewRegistry = new ViewRegistry(this)
atom.commands.add('atom-text-editor', {
'debugger:start': () => { this.start() },
'debugger:stop': () => { this.stop() },
'debugger:resume': () => { this.resume() },
'debugger:pause': () => { this.pause() },
'debugger:step-into': () => { this.stepInto() },
'debugger:step-over': () => { this.stepOver() },
'debugger:step-out': () => { this.stepOut() },
'debugger:toggle-breakpoint-at-current-line': () => { this.toggleBreakpoint() }
})
}
addDebugger(debug: Debugger): void {
this.debuggerRegistry.add(debug)
}
addView(view: DebuggerView): void {
this.viewRegistry.add(view);
}
deleteView(view: DebuggerView): void {
this.viewRegistry.delete(view)
}
/* Commands */
start(): void {
let proxy = this.debuggerRegistry.getDebuggerProxy()
let config
if (proxy.getActiveDebugger() != null) {
atom.notifications.addError(
'There is a session in progress. Please, exit first.')
return
}
config = new ProjectConfig()
config.tryLoad()
if (!config.data) {
atom.notifications.addError('The project has no config.')
return
}
if (!config.data.target) {
atom.notifications.addError('The project has no target set.')
return
}
if (!config.data.debugger) {
atom.notifications.addError('The project has no debugger set.')
return
}
const target = config.data.target
const debug = this.debuggerRegistry.get(config.data.debugger)
if (!debug) {
atom.notifications.addFatalError('The debugger is unknown.')
return
}
proxy.startSession(target, debug)
}
stop(): void {
this.debuggerRegistry.getDebuggerProxy().stop()
}
resume(): void {
this.debuggerRegistry.getDebuggerProxy().resume()
}
pause(): void {
this.debuggerRegistry.getDebuggerProxy().pause()
}
stepInto(): void {
this.debuggerRegistry.getDebuggerProxy().stepInto()
}
stepOver(): void {
this.debuggerRegistry.getDebuggerProxy().stepOver()
}
stepOut(): void {
this.debuggerRegistry.getDebuggerProxy().stepOut()
}
toggleBreakpoint(): void {
const activeEditor = atom.workspace.getActiveTextEditor()
if (!activeEditor || activeEditor.hasMultipleCursors()) {
return
}
let breakpoint = new Breakpoint({
filePath: activeEditor.getPath(),
bufferRow: activeEditor.getCursorBufferPosition().row
})
const debug = this.debuggerRegistry.getDebuggerProxy()
if (debug.removeBreakpoint(breakpoint) == false) {
debug.insertBreakpoint(breakpoint)
}
}
}