Automatically inject pathMappings into your nvim-dap configurations for
docker compose projects.
Anyone that has to debug a project that runs in a docker container knows the
pain of needing to set up the pathMappings manually for their DAP
configuration, otherwise the given debug adapter will complain about being
unable to find the file being debugged.
This plugin attempts to automatically set the pathMappings for every debugging
session, by extracting all the bind mount information directly from docker
compose.
This works by wrapping all your DAP adapters and adding a custom enrich_config
function, which at runtime will get all the necessary info from docker and
inject it into the DAP configuration's pathMappings setting. I'm fairly
careful about not clobbering any existing adapter/configuration values, so ex.
if an adapter already has an enrich_config it's preserved and wrapped
automatically, and any pathMappings already set on a configuration are merged
with the ones automatically generated by this plugin.
Via lazy.nvim:
{
'loganswartz/dap-path-mapper.nvim',
dependencies = 'mfussenegger/nvim-dap',
config = true,
}This should work for most cases, assuming all of your DAP adapters are created
in your nvim-dap config. When it comes down to it, calling
require('dap-path-mapper').setup() after all DAP adapters have been
created is really all that's required for this plugin to work. This can be
accomplished by making sure all plugins that create adapters are in the
dependencies array for this plugin, so that lazy.nvim sets them up first.
For example, nvim-dap-python adds a python adapter, so we want our spec to
look like this if we were using that plugin:
{
'loganswartz/dap-path-mapper.nvim',
dependencies = {
'mfussenegger/nvim-dap',
'mfussenegger/nvim-dap-python',
},
config = true,
}If you want to have all your nvim-dap configuration to happen in the config
method for nvim-dap, an alternative solution like this would also work:
{
'mfussenegger/nvim-dap',
dependencies = {
'mfussenegger/nvim-dap-python',
'loganswartz/dap-path-mapper.nvim',
},
config = function()
local dap = require('nvim-dap')
-- define our own adapter
dap.adapters.something = {
-- ...
}
-- adds a 'python' adapter
require('dap-python').setup()
-- etc...
-- now that all adapters are set up, run this plugin
require('dap-path-mapper').setup()
end,
}