forked from kiddkai/atom-node-debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-debugger.coffee
More file actions
108 lines (93 loc) · 3.14 KB
/
node-debugger.coffee
File metadata and controls
108 lines (93 loc) · 3.14 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
{CompositeDisposable} = require 'atom'
{Debugger} = require './debugger'
logger = require './logger'
os = require 'os'
fs = require 'fs'
processManager = null
_debugger = null
onBreak = null
module.exports =
config:
nodePath:
type: 'string'
default: if os.platform() is 'win32' then 'node.exe' else '/bin/node'
debugPort:
type: 'number'
minium: 5857
maxium: 65535
default: 5858
debugHost:
type: 'string'
default: '127.0.0.1'
nodeArgs:
type: 'string'
default: ''
scriptMain:
type: 'string'
default: ''
appArgs:
type: 'string'
default: ''
env:
type: 'string'
default: ''
activate: () ->
@disposables = new CompositeDisposable()
_debugger = new Debugger(atom)
@disposables.add _debugger.subscribeDisposable 'connected', ->
#atom.notifications.addSuccess('connected, enjoy debugging : )')
@disposables.add _debugger.subscribeDisposable 'disconnected', ->
#atom.notifications.addInfo('finish debugging : )')
@disposables.add atom.commands.add('atom-workspace', {
'node-debugger:start-resume': => @startOrResume()
'node-debugger:start-active-file': => @startActiveFile()
'node-debugger:stop': => @stop()
'node-debugger:toggle-breakpoint': => @toggleBreakpoint()
'node-debugger:step-next': => @stepNext()
'node-debugger:step-in': => @stepIn()
'node-debugger:step-out': => @stepOut()
'node-debugger:attach': => @attach()
'node-debugger:toggle-debugger': => @toggleDebugger()
})
startOrResume: ->
if _debugger.isConnected()
_debugger.reqContinue()
else
@saveAll()
_debugger.start()
attach: ->
return if _debugger.isConnected()
_debugger.attach()
startActiveFile: ->
return if _debugger.isConnected()
@saveAll()
_debugger.startActiveFile()
toggleBreakpoint: ->
editor = atom.workspace.getActiveTextEditor()
path = editor.getPath()
{row} = editor.getCursorBufferPosition()
_debugger.breakpointManager.toggleBreakpoint editor, path, row
stepNext: ->
_debugger.step('next', 1) if _debugger.isConnected()
stepIn: ->
_debugger.step('in', 1) if _debugger.isConnected()
stepOut: ->
_debugger.step('out', 1) if _debugger.isConnected()
stop: ->
_debugger.cleanup()
deactivate: ->
logger.info 'deactive', 'stop running plugin'
@stop()
@disposables.dispose()
_debugger.dispose()
toggleDebugger: ->
_debugger.toggle()
saveAll: ->
# code shamelessly copied from https://github.com/BrownBear2/atom-save-all/blob/master/lib/atom-save-all.coffee
current = atom.workspace?.getActiveEditor?()
current ?= atom.workspace?.getActiveTextEditor?()
if current? and current.getURI?()? and current.isModified?() and paneItem?.getPath?()? and (!fs.existsSync(paneItem.getPath()) or !fs.statSync(current.getPath()).isFile())
current.save()
for paneItem in atom.workspace.getPaneItems()
if paneItem.getURI?()? and paneItem.isModified?() and paneItem?.getPath?()? and fs.existsSync(paneItem.getPath()) and fs.statSync(paneItem.getPath()).isFile()
paneItem.save()