nvimのrustデバッガーへプロジェクトごとに引数を設定する

lldb plugin(nvim-dap)の設定をいじる。argsにfunctionで毎回.nvim/debug.luaのテーブルから読めるようにする。

~/.config/nvim/lua/plugins/lldb.lua

{
    "mfussenegger/nvim-dap",
    config = function()
      local dap = require("dap")

      dap.adapters.codelldb = {
       -- ~~
      }

      dap.configurations.rust = {
        {
          name = "Launch Rust",
          type = "codelldb",
          request = "launch",
          program = function()
           j
            return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/target/debug/", "file")
          end,
          cwd = "${workspaceFolder}",
          -- 引数をproject-root/.nvim/debug.luaから読み込む
          args = function()
            local ok, result = pcall(dofile, vim.fn.getcwd() .. "/.nvim/debug.lua")
            if ok and type(result) == "table" then return result.args or {} end
            return {}
          end,
          stopOnEntry = false,
        },
      }
    end,
  }

プロジェクトディレクトリに.nvim/debug.luaを置く。

.nvim/debug.lua

return {
  args = {
    "next",
    "seq",
  },
}

これでcargo run -- next seqと同等の処理になる。