diff --git a/lua/rust-tools/dap.lua b/lua/rust-tools/dap.lua index 3aa1b95..45689ec 100644 --- a/lua/rust-tools/dap.lua +++ b/lua/rust-tools/dap.lua @@ -2,6 +2,11 @@ local rt = require("rust-tools") local M = {} +local has_libs = { + ---@type nil|boolean + dap = nil, +} + ---For the heroes who want to use it ---@param codelldb_path string ---@param liblldb_path string @@ -17,7 +22,7 @@ function M.get_codelldb_adapter(codelldb_path, liblldb_path) } end -function M.setup_adapter() +local function setup_adapter() local dap = require("dap") local opts = rt.config.options @@ -50,7 +55,16 @@ local function scheduled_error(err) end function M.start(args) - if not pcall(require, "dap") then + if has_libs.dap == nil then + if pcall(require, "dap") then + has_libs.dap = true + setup_adapter() + else + has_libs.dap = false + end + end + + if not has_libs.dap then scheduled_error("nvim-dap not found.") return end diff --git a/lua/rust-tools/init.lua b/lua/rust-tools/init.lua index ca07557..696c0a9 100644 --- a/lua/rust-tools/init.lua +++ b/lua/rust-tools/init.lua @@ -120,10 +120,6 @@ function M.setup(opts) config.setup(opts) lsp.setup() commands.setup_lsp_commands() - - if pcall(require, "dap") then - rt_dap.setup_adapter() - end end return M