nvim-dap-vscode-js

repository·main·Indexed 43 days ago

https://github.com/mxsdev/nvim-dap-vscode-js

An adapter for nvim-dap that enables debugging for JavaScript and TypeScript using the Microsoft vscode-js-debug engine. It allows Neovim users to debug Node.js, Chrome, and Edge environments with support for adapters such as pwa-node, pwa-chrome, and pwa-msedge.

Tokens
1.5K
Snippets
6
Records
7
Agent score
6%

What's inside nvim-dap-vscode-js

  1. Build and install vscode-js-debug debugger

    main

    This plugin is an adapter for vscode-js-debug. You must download and build a copy of the debugger manually or via a package manager to use it.

    Using Packer

    If using Packer, you can automate the build process:

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

    Manual Installation

    If you are not using Packer, follow these steps:

    1. Clone the repository: git clone https://github.com/microsoft/vscode-js-debug
    2. Enter the directory: cd vscode-js-debug
    3. Install dependencies: npm install --legacy-peer-deps
    4. Build the bundle: npx gulp vsDebugServerBundle
    5. Move the output: mv dist out

    Note: If the build scripts fail, ensure you are using the latest version of vscode-js-debug as the upstream build process may change.

    git clone https://github.com/microsoft/vscode-js-debug
    cd vscode-js-debug
    npm install --legacy-peer-deps
    npx gulp vsDebugServerBundle
    mv dist out
  2. Configure nvim-dap-vscode-js

    main

    Initialize the plugin using require("dap-vscode-js").setup().

    Key configuration options:

    • node_path: Path to the node executable. Defaults to $NODE_PATH or "node".
    • debugger_path: Path to the vscode-js-debug installation. Required if installed manually (not via Packer).
    • debugger_cmd: Command to launch the debug server. This takes precedence over node_path and debugger_path.
    • adapters: A list of adapters to register in nvim-dap. Supported values include 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', and 'pwa-extensionHost'.
    • log_file_path: Path for file logging.
    • log_file_level: Logging level for file output (set to false to disable).
    • log_console_level: Logging level for console output (set to false to disable).
    require("dap-vscode-js").setup({
      -- node_path = "node",
      -- debugger_path = "(runtimedir)/site/pack/packer/opt/vscode-js-debug",
      -- debugger_cmd = { "js-debug-adapter" },
      adapters = { 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost' },
      -- log_file_path = "(stdpath cache)/dap_vscode_js.log",
      -- log_file_level = false,
      -- log_console_level = vim.log.levels.ERROR
    })
    
    for _, language in ipairs({ "typescript", "javascript" }) do
      require("dap").configurations[language] = {
        -- configurations go here
      }
    end
  3. Configure Jest testing debugging

    main

    To debug Jest tests, use the pwa-node type and specify the Jest binary as the runtimeExecutable argument.

    {
      {
        type = "pwa-node",
        request = "launch",
        name = "Debug Jest Tests",
        runtimeExecutable = "node",
        runtimeArgs = {
          "./node_modules/jest/bin/jest.js",
          "--runInBand",
        },
        rootPath = "${workspaceFolder}",
        cwd = "${workspaceFolder}",
        console = "integratedTerminal",
        internalConsoleOptions = "neverOpen",
      }
    }
  4. Configure Node.js debugging in nvim-dap

    main

    To debug Node.js files or attach to running processes, add the following configurations to your dap.configurations for javascript or typescript.

    {
      {
        type = "pwa-node",
        request = "launch",
        name = "Launch file",
        program = "${file}",
        cwd = "${workspaceFolder}",
      },
      {
        type = "pwa-node",
        request = "attach",
        name = "Attach",
        processId = require'dap.utils'.pick_process,
        cwd = "${workspaceFolder}",
      }
    }
  5. Configure Mocha testing debugging

    main

    To debug Mocha tests, use the pwa-node type and specify the Mocha binary in runtimeArgs.

    {
      {
        type = "pwa-node",
        request = "launch",
        name = "Debug Mocha Tests",
        runtimeExecutable = "node",
        runtimeArgs = {
          "./node_modules/mocha/bin/mocha.js",
        },
        rootPath = "${workspaceFolder}",
        cwd = "${workspaceFolder}",
        console = "integratedTerminal",
        internalConsoleOptions = "neverOpen",
      }
    }
  6. Supported Debugger Adapters

    main

    The plugin provides support for the following vscode-js-debug adapters:

    AdapterPlatformSupport Status
    pwa-nodeNode.jsFull
    pwa-chromeChromePartial (breakpoints may be rejected)
    pwa-msedgeEdgeUntested
    node-terminalNode.jsUntested
    pwa-extensionHostVSCode ExtensionsUntested