Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wookayin
Copy link
Contributor

@wookayin wookayin commented Nov 12, 2023

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.

`dap.run { filetype = ... }` will start a DAP session with the specified
filetype, with the configuration `dap.configurations[filetype]`.
@wookayin
Copy link
Contributor Author

@mfussenegger any opinions?

@mfussenegger
Copy link
Owner

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
Copy link
Contributor Author

wookayin commented Dec 30, 2023

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
Copy link

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' })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants