sponsor Vim development Vim logo Vim Book Ad

vim-node-inspect : Interactive Node.js debugger

 script karma  Rating 5/2, Downloaded by 152  Comments, bugs, improvements  Vim wiki

created by
Eli Babila
 
script type
utility
 
description
Get the latest version @
https://github.com/eliba2/vim-node-inspect

Requirements
Vim8.1+/Recent Neovim. Node in the path.

Installation
Install with your favorite package manager. For vim-plug its

Plug 'eliba2/vim-node-inspect'
How to use
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.

For full documentation see :h vim-node-inspect.

Starting Manually
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).

Using the configuration file
Use the configuration file to define the starting method. Create a file named "vim-node-config.json" in the current working directory. The format is json, and the available options are:

"request" - either "launch" or "attach". The former is for executing a script. The second is for connecting to a running node instance.

"program" - in the case of "launch", this is the script's filename and must be present.

A sample configuration for launch would be:

{
"request": "launch",
"program": "/Users/eli/Tests/test.js",
"args": ["first", "second"]
}
Use absolute paths. "${workspaceFolder}" can be used, it equals to the current working directory (:pwd).

"args" - an array list of script arguments. Relevant only to "launch", optional.

"address" - in the case of "attach", this is the address to connect to. Can be omitted, in this case it defaults to "127.0.0.1".

"port" - in the case of "attach", this is the port to connect to. Must be present.

A sample configuration for attach would be:

{
"request": "attach",
"port": 9229
}
Automatically restarting the debug session
When using an application to monitor changes and restart the node session (such as nodemon or pm2) it is useful to restart the debug session as well. This can be done with the restart parameter, relevant only to an attach request:

{
"request": "attach",
"port": 9229,
"restart": true
}
Available Commands
The following commands are available:

NodeInspectStart [args] - Starts debugger, paused

NodeInspectRun [args] - Continue / Start and run immediatly

NodeInspectConnect host:port - Connect to a running instance

NodeInspectStepOver - Step over

NodeInspectStepInto - Step into

NodeInspectStepOut - Step out

NodeInspectStop - Stop debugging (and kill the node instance)

NodeInspectToggleBreakpoint - Toggle breakpoint

NodeInspectRemoveAllBreakpoints - Removes all breakpoints

NodeInspectAddWatch - Add the word under the cursor to the watch window

There are no default bindings; the following is added for convinience:

nnoremap <silent><F4> :NodeInspectStart<cr>
nnoremap <silent><F5> :NodeInspectRun<cr>
nnoremap <silent><F6> :NodeInspectConnect("127.0.0.1:9229")<cr>
nnoremap <silent><F7> :NodeInspectStepInto<cr>
nnoremap <silent><F8> :NodeInspectStepOver<cr>
nnoremap <silent><F9> :NodeInspectToggleBreakpoint<cr>
nnoremap <silent><F10> :NodeInspectStop<cr>
Breakpoints
The plugin saves your breakpoint's locations between Vim sessions. Once the plugin is started it will try and re-activate the breakpoints for the current location, that's for all the breakpoints which root in the current working directory.

Note breakpoints are triggered through Vim and resolved in node, so resolved locations might differ from the triggered ones. The breakpoints signs appear in the resolved locations.

Watches
There are two ways to add a watch. One is to use the NodeInspectAddWatch command which will add the word under the cursor as a watch. The other is by directly editing the watch window: this will resolve the watches, one per line. Remove a watch by deleting it from the watch window.

Connecting to a running container
You'll need to configure the local and remote directories when connecting to a remote host or the local instance will set the wrong breakpoints locations. Use the configuration file to set these directories, such as:

{
"request": "attach",
"port": 9229,
  "localRoot": "/Users/eli/projects/my-test-project",
  "remoteRoot": "/app"
}
Make sure to use full paths.

Remarks
In beta. Means its useful; things may change or fail. NOT tested on Windows.

License
MIT.
 
install details
Unzip ~/.vim or using your favorite package manager. For vim-plug its

Plug 'eliba2/vim-node-inspect'
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
vimnodeinspect.zip 0.6 2020-05-08 8.0 Eli Babila Argument support. Bug fix.
vimnodeinspect.zip 0.5 2020-03-16 8.0 Eli Babila Start options. bug fix.
vimnodeinspect.zip 0.4 2020-02-28 8.0 Eli Babila Watches support; bug fix.
vimnodeinspect.zip 0.3 2020-01-26 8.0 Eli Babila Connection to remote containers. Backtrace window. Bug fix.
vimnodeinspect.zip 0.2 2020-01-10 8.0 Eli Babila Requires Vim8.1+
vimnodeinspect.zip 0.1 2020-01-10 8.0 Eli Babila Initial upload
ip used for rating: 18.204.227.117

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
OSDN.net Logo