neovimneovim-pluginnvchad

Is there a way for nvim-dap-ui to display the values of elements in vectors?


When I try to debug my c++ programs with neovim while using nvim-dap-ui along with nvchad. The debugger is gdb along with vscode-cpptools. I am unable to see all the elements inside a vector and instead I see a bunch of pointers and references which ins't helpful for me to be able to debug my code. I am able to see all the elements inside a vector in vscode and I would like that same ability to be inside neovim.

Screenshot of neovim which is only showing me a bunch of pointers when i expand vector v : Screenshot of neovim which is only showing me a bunch of pointers when i expand vector v

Screenshot of vscode which shows me each value at v[0],v[1],v[2],etc : Screenshot of vscode which shows me each value at v[0],v[1],v[2],etc

I tried to google and search solutions to this, but I couldn't find anything about this specific problem. This is the lua code which configures the debugger:

return {
  {
    "rcarriga/nvim-dap-ui",
    event = "VeryLazy",
    dependencies = {
      "mfussenegger/nvim-dap",
      "nvim-neotest/nvim-nio",
    },
    config = function()
      require("dapui").setup()
      local dap, dapui = require("dap"), require("dapui")
      dap.listeners.before.attach.dapui_config = function()
        dapui.open()
      end
      dap.listeners.before.launch.dapui_config = function()
        dapui.open()
      end
      dap.listeners.before.event_terminated.dapui_config = function()
        dapui.close()
      end
      dap.listeners.before.event_exited.dapui_config = function()
        dapui.close()
      end
    end
  },
  {
    "nvim-neotest/nvim-nio",
  },
  {
    "jay-babu/mason-nvim-dap.nvim",
    event = "VeryLazy",
    dependencies = {
      "williamboman/mason.nvim",
      "mfussenegger/nvim-dap",
    },
    opts = {
      handlers = {},
    },
  },
  {
    "mfussenegger/nvim-dap",
    config = function()
      local dap = require('dap')
      dap.adapters.cppdbg = {
        id = 'cppdbg',
        type = 'executable',
        command = '~/.vscode/extensions/ms-vscode.cpptools-1.24.5-linux-x64/debugAdapters/bin/OpenDebugAD7',
      }
      dap.configurations.cpp = {
        {
          name = "Launch file",
          type = "cppdbg",
          request = "launch",
          program = function()
            return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
          end,
          cwd = '${workspaceFolder}',
          stopAtEntry = true,
        },
        --[[{
          name = 'Attach to gdbserver :1234',
          type = 'cppdbg',
          request = 'launch',
          MIMode = 'gdb',
          miDebuggerServerAddress = 'localhost:1234',
          miDebuggerPath = '/usr/bin/gdb',
          cwd = '${workspaceFolder}',
          program = function()
            return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
          end,
        },]]
      }
    end
  },
}

Solution

  • Ok so apparently I'm just blind, because in the nvim-dap-wiki, it mentions how to enable pretty printing, which lets me see the elements in the vector. I just didn't realise before what pretty printing did so I ended up ignoring that section. This is the config that works:

    return {
      {
        "rcarriga/nvim-dap-ui",
        event = "VeryLazy",
        dependencies = {
          "mfussenegger/nvim-dap",
          "nvim-neotest/nvim-nio",
        },
        config = function()
          require("dapui").setup()
          local dap, dapui = require("dap"), require("dapui")
          dap.listeners.before.attach.dapui_config = function()
            dapui.open()
          end
          dap.listeners.before.launch.dapui_config = function()
            dapui.open()
          end
          dap.listeners.before.event_terminated.dapui_config = function()
            dapui.close()
          end
          dap.listeners.before.event_exited.dapui_config = function()
            dapui.close()
          end
        end
      },
      {
        "nvim-neotest/nvim-nio",
      },
      {
        "jay-babu/mason-nvim-dap.nvim",
        event = "VeryLazy",
        dependencies = {
          "williamboman/mason.nvim",
          "mfussenegger/nvim-dap",
        },
        opts = {
          handlers = {},
        },
      },
      {
        "mfussenegger/nvim-dap",
        config = function()
          local dap = require('dap')
          dap.adapters.cppdbg = {
            id = 'cppdbg',
            type = 'executable',
            command = '~/.vscode/extensions/ms-vscode.cpptools-1.24.5-linux-x64/debugAdapters/bin/OpenDebugAD7',
          }
          dap.configurations.cpp = {
            {
              name = "Launch file",
              type = "cppdbg",
              request = "launch",
              program = function()
                return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
              end,
              cwd = '${workspaceFolder}',
              stopAtEntry = true,
              setupCommands = { -- This allows vectors and other data structures to show the values inside them.
                {
                   text = '-enable-pretty-printing',
                   description =  'enable pretty printing',
                   ignoreFailures = false
                },
              },
            },
          }
        end
      },
    }