mfussenegger / nvim-dap

Debug Adapter Protocol client implementation for Neovim
GNU General Public License v3.0
5.09k stars 179 forks source link

Duplicate entries in configuration. Need to disable auto `load_launchjs` #1270

Closed tuephan-hi closed 6 days ago

tuephan-hi commented 1 week ago

Debug adapter definition and debug configuration

function() local dap = require("dap")

  require("dap.ext.vscode").json_decode = require("json5").parse

  if not dap.adapters["pwa-node"] then
    require("dap").adapters["pwa-node"] = {
      type = "server",
      host = "localhost",
      port = "${port}",
      executable = {
        command = "node",
        -- 💀 Make sure to update this path to point to your installation
        args = {
          require("mason-registry").get_package("js-debug-adapter"):get_install_path()
            .. "/js-debug/src/dapDebugServer.js",
          "${port}",
        },
      },
    }
  end

  if not dap.adapters["node"] then
    dap.adapters["node"] = function(cb, config)
      if config.type == "node" then
        config.type = "pwa-node"
      end
      local nativeAdapter = dap.adapters["pwa-node"]
      if type(nativeAdapter) == "function" then
        nativeAdapter(cb, config)
      else
        cb(nativeAdapter)
      end
    end
  end

  require("dap.ext.vscode").load_launchjs(nil, { ["pwa-node"] = { "typescript" } })

  for i, config in ipairs(dap.configurations.typescript or {}) do
    dap.configurations.typescript[i] = vim.tbl_deep_extend("force", config, {
      cwd = vim.fn.getcwd(),
      sourceMaps = true,
    })
  end
end

Debug adapter version

6f79b82

Steps to Reproduce

  1. Setup nvim-dap via Lazy
  2. Start debugging session to choose which configuration to run

Expected Result

Only 1 entry of each type should show up.

Actual Result

Duplicated entries are shown.

This is because in my configuration, I need to map the pwa-node type to typescript filetype. Then I have to extend the configuration in launchjson to include cwd which does not exist by default. This is causing the duplication.

      require("dap.ext.vscode").load_launchjs(nil, { ["pwa-node"] = { "typescript" } })

      for i, config in ipairs(dap.configurations.typescript or {}) do
        dap.configurations.typescript[i] = vim.tbl_deep_extend("force", config, {
          cwd = vim.fn.getcwd(),
          sourceMaps = true,
        })
      end
mfussenegger commented 6 days ago

See https://github.com/mfussenegger/nvim-dap/discussions/1263

You could also remove the provider. :h dap-providers-configs should give some pointers on how to do that. But that's "you know what you're doing" territory and I'd caution against doing it, as the remaining functionality is developed under the assumption that it's present.