mfussenegger / nvim-dap

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

Allow filetype in options to dap.continue and dap.run #1090

Closed wookayin closed 1 month ago

wookayin commented 7 months ago

dap.run { filetype = ... } will start a DAP session with the specified filetype, with the configuration dap.configurations[filetype].

NOTE: Currently, no matter what the filetype of the current buffer is picked.

wookayin commented 7 months ago

@mfussenegger any opinions?

mfussenegger commented 6 months ago

I have in mind to add some sort of extensible configuration provider mechanism but I don't have a clear picture yet how that will look like. But I suspect it will move a bit away from the strict filetype coupling so I'm not sure if adding a filetype parameter will then still fit. There might be a more general filtering mechanism/table parameter, given that each provider implementation may take different options.

I can imagine that the two existing ways to define configurations (dap.configurations, launch.json) will then just become bundled configuration provider implementations. The vscode launch.json entries wouldn't get added/loaded into dap .configurations and you'd always get all entries listed in the file.

wookayin commented 6 months ago

The current strict filetype coupling is a limitation that bothers me; it makes remote attaching especially difficult (e.g. run "cpp" or "lua" configuration when on an "empty" buffer, etc.) But I think this might be a good and simple solution until a complex configuration or provider mechanism is landed.

Choosing specific configuration no matter what the current filetype would be the best idea. Let me try if I can implement in that way.

ckyrouac commented 5 months ago

I was about to make a PR with something similar. This works for me to select any run configuration from any filetype:

local function flatten_dap_configurations()
  local configurations = require('dap').configurations
  local flat_configs = {}

  for type, configs in pairs(configurations) do
    for _, conf in ipairs(configs) do
      conf.file_type = type
      table.insert(flat_configs, conf)
    end
  end

  return flat_configs
end

local function select_config_and_run(opts)
  local configurations = flatten_dap_configurations()
  opts = opts or {}
  require('dap.ui').pick_one(
    configurations,
    "Configuration: ",
    function(i) return i.file_type .. ": " .. i.name end,
    function(configuration)
      if configuration then
        require('dap').run(configuration, opts)
      else
        vim.notify('No configuration selected', vim.log.levels.INFO)
      end
    end
  )
end
vim.keymap.set("n", "<F10>", select_config_and_run, { silent = true, desc = 'DAP Select Config' })
mfussenegger commented 1 month ago

Can you check if https://github.com/mfussenegger/nvim-dap/pull/1237 would solve this requirement?

mfussenegger commented 1 month ago

Closing this for now but please let me know if your use cases can't be covered with the provider model