|
| 1 | +# nvim-dap-vscode-js |
| 2 | + |
| 3 | +[nvim-dap](https://github.com/mfussenegger/nvim-dap) adapter for [vscode-js-debug](https://github.com/microsoft/vscode-js-debug). |
| 4 | + |
| 5 | +## Adapters |
| 6 | + |
| 7 | +Every platform supported by vscode is provided. This includes: |
| 8 | + |
| 9 | +| Adapter | Platform | Support | |
| 10 | +|---------------------|-------------------|-------------| |
| 11 | +| `pwa-node` | Node.js | Full | |
| 12 | +| `pwa-chrome` | Chrome | Partial[^1] | |
| 13 | +| `pwa-msedge` | Edge | Untested | |
| 14 | +| `node-terminal` | Node.js | Untested | |
| 15 | +| `pwa-extensionHost` | VSCode Extensions | Untested | |
| 16 | + |
| 17 | +## Installation |
| 18 | + |
| 19 | +### Plugin |
| 20 | + |
| 21 | +Supports packer, vim-plug, etc. With packer, for example: |
| 22 | + |
| 23 | +```lua |
| 24 | +use { "mxsdev/nvim-dap-vscode-js", requires = {"mfussenegger/nvim-dap"} } |
| 25 | +``` |
| 26 | + |
| 27 | +### Debugger |
| 28 | + |
| 29 | +You must download and build a copy of [vscode-js-debug](https://github.com/microsoft/vscode-js-debug) in order to use this plugin. |
| 30 | + |
| 31 | +#### With Packer |
| 32 | + |
| 33 | +```lua |
| 34 | +use { |
| 35 | + "microsoft/vscode-js-debug", |
| 36 | + opt = true, |
| 37 | + run = "npm install --legacy-peer-deps && npm run compile" |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +#### Manually |
| 42 | + |
| 43 | +```bash |
| 44 | +git clone https://github.com/microsoft/vscode-js-debug |
| 45 | +cd vscode-js-debug |
| 46 | +npm install --legacy-peer-deps |
| 47 | +npm run compile |
| 48 | +``` |
| 49 | + |
| 50 | +## Setup |
| 51 | + |
| 52 | +```lua |
| 53 | +require("nvim-dap-vscode-js").setup({ |
| 54 | + -- node_path = "node", -- Path of node executable. Defaults to $NODE_PATH, and then "node" |
| 55 | + -- debugger_path = "(runtimedir)/site/pack/packer/opt/vscode-js-debug", -- Path to vscode-js-debug installation. |
| 56 | + adapters = { 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost' }, -- which adapters to register in nvim-dap |
| 57 | +}) |
| 58 | + |
| 59 | +for _, language in ipairs({ "typescript", "javascript" }) do |
| 60 | + require("dap").configurations[language] = { |
| 61 | + ... -- see below |
| 62 | + } |
| 63 | +end |
| 64 | +``` |
| 65 | + |
| 66 | +Note that if vscode-js-debug was installed without packer, its root folder location must be set manually in `debugger_path`. |
| 67 | + |
| 68 | +### Configurations |
| 69 | + |
| 70 | +See [here](https://github.com/microsoft/vscode-js-debug/blob/main/OPTIONS.md) for all custom configuration options. |
| 71 | + |
| 72 | +#### Node.js |
| 73 | + |
| 74 | +```lua |
| 75 | +{ |
| 76 | + { |
| 77 | + type = "pwa-node", |
| 78 | + request = "launch", |
| 79 | + name = "Launch file", |
| 80 | + program = "${file}", |
| 81 | + cwd = "${workspaceFolder}", |
| 82 | + }, |
| 83 | + { |
| 84 | + type = "pwa-node", |
| 85 | + request = "attach", |
| 86 | + name = "Attach", |
| 87 | + processId = require'dap.utils'.pick_process, |
| 88 | + cwd = "${workspaceFolder}", |
| 89 | + } |
| 90 | +} |
| 91 | +``` |
| 92 | + |
| 93 | +#### Jest[^2] |
| 94 | + |
| 95 | +```lua |
| 96 | +{ |
| 97 | + { |
| 98 | + type = "pwa-node", |
| 99 | + request = "launch", |
| 100 | + name = "Debug Jest Tests", |
| 101 | + -- trace = true, -- include debugger info |
| 102 | + runtimeExecutable = "node", |
| 103 | + runtimeArgs = { |
| 104 | + "./node_modules/jest/bin/jest.js", |
| 105 | + "--runInBand", |
| 106 | + }, |
| 107 | + rootPath = "${workspaceFolder}", |
| 108 | + cwd = "${workspaceFolder}", |
| 109 | + console = "integratedTerminal", |
| 110 | + internalConsoleOptions = "neverOpen", |
| 111 | + } |
| 112 | +} |
| 113 | +``` |
| 114 | + |
| 115 | +#### Mocha |
| 116 | + |
| 117 | +```lua |
| 118 | +{ |
| 119 | + { |
| 120 | + type = "pwa-node", |
| 121 | + request = "launch", |
| 122 | + name = "Debug Mocha Tests", |
| 123 | + -- trace = true, -- include debugger info |
| 124 | + runtimeExecutable = "node", |
| 125 | + runtimeArgs = { |
| 126 | + "./node_modules/mocha/bin/mocha.js", |
| 127 | + }, |
| 128 | + rootPath = "${workspaceFolder}", |
| 129 | + cwd = "${workspaceFolder}", |
| 130 | + console = "integratedTerminal", |
| 131 | + internalConsoleOptions = "neverOpen", |
| 132 | + } |
| 133 | +} |
| 134 | +``` |
| 135 | + |
| 136 | +## Planned Features |
| 137 | + |
| 138 | + - [ ] Integration with [neotest-jest](https://github.com/haydenmeade/neotest-jest) |
| 139 | + - [ ] Support for switching between child sessions |
| 140 | + |
| 141 | +[^1]: The debugger runs and attaches, however breakpoints may be rejected. |
| 142 | +[^2]: See [here](https://github.com/microsoft/vscode-js-debug/issues/214#issuecomment-572686921) for more details on running jest |
0 commit comments