-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebugger-scope-view.js
172 lines (117 loc) · 4.46 KB
/
debugger-scope-view.js
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
'use babel'
/* @flow */
import DebuggerPanelSection from './debugger-panel-section'
import type {
DebuggerController,
DebuggerProxy,
SessionEvent,
Variable,
VariableEvent
} from 'debugger'
const errorHandler = (error: mixed) => {
const message = (error && error.msg) ? error.msg : 'Unknown error occured'
atom.notifications.addError(message, { dismissable: true })
}
class DebuggerScopeViewPrivate {
element: DebuggerPanelSection;
variableListElement: HTMLElement;
debuggerProxy: DebuggerProxy;
createCallbacks(): void {
const proxy = this.debuggerProxy
proxy.onVariableEvent( (event: VariableEvent) => {
if (event.type !== 'entered-scope') { return }
this.createVariableView(event.variable, this.variableListElement)
})
proxy.onVariableEvent( (event: VariableEvent) => {
if (event.type !== 'left-scope') { return }
const element = document.querySelector(`[data-id='${event.variable.id}']`)
if (!element) { throw new Error('Could not find corresponding element') }
const parent = element.parentElement
if (parent) { parent.removeChild(element) }
})
}
createScopeView(): void {
const list = document.createElement('ul')
list.classList.add('list-tree', 'has-collapsable-children')
this.element.appendChild(list)
this.variableListElement = list
}
createVariableView(variable: Variable, parent: HTMLElement): void {
let variableView = document.createElement('li')
parent.appendChild(variableView)
variableView.dataset.id = variable.id
if (variable.has_children) {
variableView.classList.add('list-nested-item', 'collapsed')
let variableHeader = document.createElement('div')
variableView.appendChild(variableHeader)
variableHeader.classList.add('list-item')
const view = variableView
variableHeader.addEventListener('click', event => {
if (event.shiftKey || event.metaKey || event.ctrlKey) { return }
if (view.classList.contains('collapsed')) {
view.classList.remove('collapsed')
if (!view.querySelector('.list-tree')) {
const proxy = this.debuggerProxy
const childView = document.createElement('ul')
childView.classList.add('list-tree')
view.appendChild(childView)
proxy.getVariableChildren(variable)
.then( (children: Array<Variable>) => {
for (let i=0; i<children.length; i++) {
this.createVariableView(children[i], childView)
}
}, errorHandler)
}
} else {
view.classList.add('collapsed')
}
})
variableView = variableHeader
} else {
variableView.classList.add('list-item')
}
variableView.classList.add('variable')
const nameDiv = document.createElement('div')
const nameElement = document.createElement('span')
variableView.appendChild(nameDiv)
nameDiv.appendChild(nameElement)
nameDiv.classList.add('name')
nameElement.classList.add('name', 'highlight')
nameElement.appendChild(new Text(variable.name))
const typeElement = document.createElement('span')
variableView.appendChild(typeElement)
typeElement.classList.add('type')
typeElement.appendChild(new Text(variable.type))
const spacerElement = document.createElement('span')
variableView.appendChild(spacerElement)
spacerElement.classList.add('spacer')
if (variable.value !== undefined) {
const valueElement = document.createElement('span')
variableView.appendChild(valueElement)
valueElement.classList.add('value')
if (variable.value !== null) {
valueElement.appendChild(new Text(variable.value))
} else {
valueElement.appendChild(new Text('unknown'))
valueElement.classList.add('unknown')
}
}
}
activate(controller: DebuggerController): void {
this.debuggerProxy = controller.debuggerRegistry.getDebuggerProxy()
this.createCallbacks()
this.createScopeView()
}
}
export default class DebuggerScopeView {
element: DebuggerPanelSection;
constructor() {
const p = new DebuggerScopeViewPrivate
p.element = new DebuggerPanelSection
p.element.classList.add('scope-view')
this.getElement = () => { return p.element }
this.activate = (controller) => { p.activate(controller) }
}
activate: (controller: DebuggerController) => void;
getElement: () => DebuggerPanelSection;
}