Skip to content

Commit 4338a9b

Browse files
committed
feat(dap): load dap lazily
PR: simrat39#388
1 parent 58b99c2 commit 4338a9b

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

lua/rust-tools/dap.lua

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ local rt = require("rust-tools")
22

33
local M = {}
44

5+
local has_libs = {
6+
---@type nil|boolean
7+
dap = nil,
8+
}
9+
510
---For the heroes who want to use it
611
---@param codelldb_path string
712
---@param liblldb_path string
@@ -17,7 +22,7 @@ function M.get_codelldb_adapter(codelldb_path, liblldb_path)
1722
}
1823
end
1924

20-
function M.setup_adapter()
25+
local function setup_adapter()
2126
local dap = require("dap")
2227
local opts = rt.config.options
2328

@@ -50,7 +55,16 @@ local function scheduled_error(err)
5055
end
5156

5257
function M.start(args)
53-
if not pcall(require, "dap") then
58+
if has_libs.dap == nil then
59+
if pcall(require, "dap") then
60+
has_libs.dap = true
61+
setup_adapter()
62+
else
63+
has_libs.dap = false
64+
end
65+
end
66+
67+
if not has_libs.dap then
5468
scheduled_error("nvim-dap not found.")
5569
return
5670
end

lua/rust-tools/init.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ function M.setup(opts)
127127
config.setup(opts)
128128
lsp.setup()
129129
commands.setup_lsp_commands()
130-
131-
if pcall(require, "dap") then
132-
rt_dap.setup_adapter()
133-
end
134130
end
135131

136132
return M

0 commit comments

Comments
 (0)