Skip to content

Commit f53f080

Browse files
authored
Replace node-inspect with chrome-remote-interface (#21)
1 parent 85e8dc2 commit f53f080

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+3574
-4509
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
breakpoints
33
vim-node-config.json
44
vim-node-session.json
5+
node_modules
56

67
# Sometimes I'm on Mac
78
.DS_Store

README.md

+21-26
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Interactive node debugger for (n)vim.
33

44
## Description
5-
Node debugging capabilities for (n)vim using the devtools protocol. Under the hood it wraps a modified version of node-inspect *(https://github.com/nodejs/node-inspect)*.
5+
Node debugging capabilities for (n)vim using the devtools protocol.
66

77

88
[![asciicast](https://asciinema.org/a/NOCL8Fc3LcQjVDD0CIR08I698.svg)](https://asciinema.org/a/NOCL8Fc3LcQjVDD0CIR08I698)
@@ -18,13 +18,14 @@ Plug 'eliba2/vim-node-inspect'
1818
```
1919

2020
## How to use
21-
Either start a node script or attach to an already running script. Both can be done manually (NodeIndpectStart/NodeInspectRun) or using the configuration file vim-node-config.json. The later is encouraged.
2221

23-
For full documentation see :h vim-node-inspect.
22+
Use the plugin to start a script with *NodeInspectStart*/*NodeInspectRun* or attach to an already running script using *NodeInspectConnect*. Additional configuration can be set with the vim-node-config.json configuration file.
2423

25-
### Starting Manually ###
24+
For full documentation see `:h vim-node-inspect`.
2625

27-
Either start debugging a local js file (via NodeInspectStart or NodeInspectRun) or connect to a running instance using NodeInspectConnect. In the later case the target must start with --inspect (e.g. node --inspect server.js).
26+
### W/O A configuration file ###
27+
28+
Use NodeInspectStart or NodeInspectRun which starts the script in the current buffer using `node --inspect <script>`. An already running script can be attached using NodeInspectConnect address:port. In the later case the target must start with --inspect (e.g. `node --inspect server.js`).
2829

2930
### Using the configuration file ###
3031

@@ -123,8 +124,6 @@ Usage in this case would be either *NodeInspectStart "run"* or *NodeInspectStart
123124

124125
## Available Commands
125126

126-
The following commands are available:
127-
128127
**NodeInspectStart [config name] [args]** - Starts debugger, paused
129128

130129
**NodeInspectRun [config name] [args]** - Continue / Start and run immediatly
@@ -150,13 +149,16 @@ The following commands are available:
150149

151150
There are no default bindings; the following is added for convinience:
152151
```
153-
nnoremap <silent><F4> :NodeInspectStart<cr>
154-
nnoremap <silent><F5> :NodeInspectRun<cr>
155-
nnoremap <silent><F6> :NodeInspectConnect("127.0.0.1:9229")<cr>
156-
nnoremap <silent><F7> :NodeInspectStepInto<cr>
157-
nnoremap <silent><F8> :NodeInspectStepOver<cr>
158-
nnoremap <silent><F9> :NodeInspectToggleBreakpoint<cr>
159-
nnoremap <silent><F10> :NodeInspectStop<cr>
152+
nnoremap <silent><leader>dd :NodeInspectStart<cr>
153+
nnoremap <silent><leader>dr :NodeInspectRun<cr>
154+
nnoremap <silent><leader>dc :NodeInspectConnect("127.0.0.1:9229")<cr>
155+
nnoremap <silent><leader>ds :NodeInspectStepOver<cr>
156+
nnoremap <silent><leader>di :NodeInspectStepInto<cr>
157+
nnoremap <silent><leader>do :NodeInspectStepOut<cr>
158+
nnoremap <silent><leader>dq :NodeInspectStop<cr>
159+
nnoremap <silent><leader>db :NodeInspectToggleBreakpoint<cr>
160+
nnoremap <silent><leader>da :NodeInspectRemoveAllBreakpoints<cr>
161+
nnoremap <silent><leader>dw :NodeInspectToggleWindow<cr>
160162
```
161163

162164
## Breakpoints
@@ -200,13 +202,6 @@ The debugger windows appear on the bottom by default. Change it by using
200202
let g:nodeinspect_window_pos = 'right'|'left'|'bottom'
201203
```
202204

203-
The command window starts in repl mode by default. It gives you a javascript shell corresponding to the current scope. If you are familiar with node-inspect and/or want to use the command mode - which enables executing debugging commands manually - use the following setting:
204-
205-
```
206-
let g:nodeinspect_start_repl = 0
207-
```
208-
209-
210205
## Remarks
211206
In beta. Means its useful; things may change or fail.
212207

@@ -217,21 +212,21 @@ Tested on Linux (debian), OSX, Windows.
217212

218213
* Debugging window
219214
* Detachable
220-
* position change
215+
* ~~position change~~
221216
* Watches
222-
* Auto watches
223-
* Open/Close properties
217+
* ~~Auto watches~~
218+
* ~~Open/Close properties~~
224219
* On the fly evaluation (popup)
225220
* Breakpoints
226221
* Breakpoints window
227222
* Call stack
228223
* Auto jump
229-
* Windows Support
224+
* ~~Windows Support~~
230225

231226

232227
## Contributing
233228

234-
PR are welcome. Open a new issue in case you find a bug; you can also create a PR fixing it yourself of course.
229+
PRs welcome. Open a new issue in case you find a bug; you can also create a PR fixing it yourself of course.
235230
Please follow the general code style (look@the code) and in your pull request explain the reason for the proposed change.
236231

237232

autoload/nodeinspect.vim

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let s:status = 0 " 0 - not started. 1 - started 2 - session ended (bridge exists, node exited) 3 - restarting
1+
let s:status = 0 " 0 - not started. 1 - started 2 - session ended (bridge exists, node exited) 3 - restarting (not used)
22
let s:plugin_path = expand('<sfile>:h:h')
33
let s:sign_id = 2
44
let s:brkpt_sign_id = 3
@@ -171,6 +171,12 @@ endfunction
171171
" remove all breakpoints. removes the signs is any
172172
" node inspect notification will ocuur only if started
173173
function! s:NodeInspectRemoveAllBreakpoints(inspectNotify)
174+
" notify bride if up
175+
if a:inspectNotify == 1 && s:status == 1
176+
let remoteFiles = s:getRemoteBreakpointsObj(s:breakpoints)
177+
call nodeinspect#utils#SendEvent('{"m": "nd_removeallbrkpts", "breakpoints":' . json_encode(remoteFiles) . '}')
178+
endif
179+
" remove vim breakpoints
174180
for filename in keys(s:breakpoints)
175181
for line in keys(s:breakpoints[filename])
176182
let signId = s:breakpoints[filename][line]
@@ -180,10 +186,6 @@ function! s:NodeInspectRemoveAllBreakpoints(inspectNotify)
180186
endif
181187
endfor
182188
endfor
183-
if a:inspectNotify == 1 && s:status == 1
184-
let remoteFiles = s:getRemoteBreakpointsObj(s:breakpoints)
185-
call nodeinspect#utils#SendEvent('{"m": "nd_removeallbrkpts", "breakpoints":' . json_encode(remoteFiles) . '}')
186-
endif
187189
endfunction
188190

189191
" called when node resolves this to a location.
@@ -318,7 +320,7 @@ function! s:onDebuggerStopped(mes)
318320
call nodeinspect#backtrace#ClearBacktraceWindow('Debugger Stopped. Source file is not available')
319321
endif
320322
" request watches update
321-
call nodeinspect#watches#UpdateWatches()
323+
" call nodeinspect#watches#UpdateWatches()
322324
endfunction
323325

324326

@@ -396,10 +398,8 @@ function! OnNodeMessage(channel, msgs)
396398
call nodeinspect#NodeInspectStepInto()
397399
elseif mes["m"] == "nd_repl_stepout"
398400
call nodeinspect#NodeInspectStepOut()
399-
" if the repl was started node-inspect, go to repl mode there (js
400-
" command mode)
401-
elseif mes["m"] == "nd_repl_started"
402-
call nodeinspect#utils#StartRepl()
401+
elseif mes["m"] == "nd_resolvedobject"
402+
call nodeinspect#watches#ResolvedObject(mes['objectId'], mes['tokens'])
403403
else
404404
echo "vim-node-inspect: unknown message ".mes["m"]
405405
endif
@@ -582,8 +582,8 @@ function! s:NodeInspectStart()
582582
let s:session["script"] = expand('%:p')
583583
endif
584584
endif
585-
" set the status to running, might be at ended(2)
586-
let s:status = 3
585+
" set the status to started, might be at ended(2)
586+
let s:status = 1
587587
" restarting might need to restart external jobs, if any
588588
let repl_result = nodeinspect#repl#StartExternalJobs(s:session)
589589
if repl_result != 0
@@ -592,6 +592,8 @@ function! s:NodeInspectStart()
592592
return
593593
endif
594594
" remove all breakpoint, they will be resolved by node-inspect
595+
echom "status is ".s:status
596+
595597
call s:removeSign()
596598
call nodeinspect#backtrace#ClearBacktraceWindow()
597599
call nodeinspect#utils#SendEvent('{"m": "nd_restart", "script": "'. s:session["script"] . '","args": ' . json_encode(s:session["args"]) . '}')
@@ -616,7 +618,6 @@ function! s:NodeInspectStart()
616618
for watch in keys(s:session["watches"])
617619
call nodeinspect#watches#AddBulk(s:session["watches"])
618620
endfor
619-
620621
endfunction
621622

622623

@@ -655,7 +656,7 @@ endfunction
655656

656657
function! nodeinspect#NodeInspectStepOver()
657658
if s:status != 1
658-
echo "node-inspect not started"
659+
echo "node-inspect not started ".s:status
659660
return
660661
endif
661662
call s:NodeInspectStepOver()

autoload/nodeinspect/backtrace.vim

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ function! nodeinspect#backtrace#ShowBacktraceWindow(startWin)
6161
" open split for call stack
6262
if s:backtrace_buf == -1
6363
if g:nodeinspect_window_pos == 'right' || g:nodeinspect_window_pos == 'left'
64-
execute winheight(a:startWin)/3."new | setlocal nobuflisted buftype=nofile statusline=Callstack"
64+
execute winheight(a:startWin)/5*2."new | setlocal nobuflisted buftype=nofile statusline=Callstack"
6565
else
66-
execute "rightb ".winwidth(a:startWin)/3."vnew | setlocal nobuflisted buftype=nofile statusline=Callstack"
66+
execute "rightb ".winwidth(a:startWin)/5*2."vnew | setlocal nobuflisted buftype=nofile statusline=Callstack"
6767
endif
6868

6969
let s:backtrace_buf = bufnr('%')
7070
set nonu
7171
else
7272
if g:nodeinspect_window_pos == 'right' || g:nodeinspect_window_pos == 'left'
73-
execute winheight(a:startWin)/3."new | buffer ". s:backtrace_buf
73+
execute winheight(a:startWin)/5*2."new | buffer ". s:backtrace_buf
7474
else
75-
execute "rightb ".winwidth(a:startWin)/3."vnew | buffer ". s:backtrace_buf
75+
execute "rightb ".winwidth(a:startWin)/5*2."vnew | buffer ". s:backtrace_buf
7676
endif
7777
endif
7878
let s:backtrace_win = win_getid()

0 commit comments

Comments
 (0)