Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,24 @@ use { "mxsdev/nvim-dap-vscode-js", requires = {"mfussenegger/nvim-dap"} }

### Debugger

You must download and build a copy of [vscode-js-debug](https://github.com/microsoft/vscode-js-debug) in order to use this plugin.
You must download and build a copy of [vscode-js-debug](https://github.com/microsoft/vscode-js-debug) in order to use this plugin.

#### With lazy.nvim

```lua
{
"microsoft/vscode-js-debug",
build = "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out"
}
```

#### With Packer

```lua
use {
"microsoft/vscode-js-debug",
opt = true,
run = "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out"
run = "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out"
}
```

Expand All @@ -55,7 +64,7 @@ mv dist out
```lua
require("dap-vscode-js").setup({
-- node_path = "node", -- Path of node executable. Defaults to $NODE_PATH, and then "node"
-- debugger_path = "(runtimedir)/site/pack/packer/opt/vscode-js-debug", -- Path to vscode-js-debug installation.
-- debugger_path = Path to vscode-js-debug directory. Set manually if using custom lazy.nvim/packer path.
-- debugger_cmd = { "js-debug-adapter" }, -- Command to use to launch the debug server. Takes precedence over `node_path` and `debugger_path`.
adapters = { 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost' }, -- which adapters to register in nvim-dap
-- log_file_path = "(stdpath cache)/dap_vscode_js.log" -- Path for file logging
Expand All @@ -70,7 +79,7 @@ for _, language in ipairs({ "typescript", "javascript" }) do
end
```

Note that if vscode-js-debug was installed without packer, its root folder location must be set manually in `debugger_path`.
Note that if vscode-js-debug was installed without lazy.nvim/packer, its root folder location must be set manually in `debugger_path`.

### Configurations

Expand Down
2 changes: 1 addition & 1 deletion lua/dap-vscode-js/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local utils = require("dap-vscode-js.utils")

local defaults = {
node_path = os.getenv("NODE_PATH") or "node",
debugger_path = utils.join_paths(utils.get_runtime_dir(), "site/pack/packer/opt/vscode-js-debug"),
debugger_path = utils.get_debugger_path(),
debugger_cmd = nil,
log_file_path = utils.join_paths(utils.get_cache_dir(), "dap_vscode_js.log"),
log_file_level = false,
Expand Down
2 changes: 1 addition & 1 deletion lua/dap-vscode-js/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

---@class Settings @Plugin configuration options
---@field node_path string: Path of node executable. Defaults to $NODE_PATH, and then "node"
---@field debugger_path string: Path to vscode-js-debug. Defaults to (runtimedir)/site/pack/packer/opt/vscode-js-debug
---@field debugger_path string: Path to vscode-js-debug. Set manually if using custom lazy.nvim/packer path.
---@field debugger_cmd string[]: The command to use to launch the debug server. This option takes precedence over both `node_path` and `debugger_path`.
---@field adapters string[]: List of adapters to configure. Options are 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost'. Defaults to all. See https://github.com/microsoft/vscode-js-debug/blob/main/OPTIONS.md for configuration options.
---@field log_file_path string: Log file path. Defaults to (stdpath cache)/dap_vscode_js.log
Expand Down
9 changes: 9 additions & 0 deletions lua/dap-vscode-js/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ function M.join_paths(...)
return result
end

function M.get_debugger_path()
local lazy_avail, lazy_config = pcall(require, "lazy.core.config")
if lazy_avail then
return M.join_paths(lazy_config.defaults.root, "vscode-js-debug")
else
return M.join_paths(M.get_runtime_dir(), "site/pack/packer/opt/vscode-js-debug")
end
end

function M.dap_breakpoint_by_state(state)
local bps = breakpoints.get()

Expand Down