Skip to content
This repository was archived by the owner on Jan 3, 2024. It is now read-only.

feat(dap): load dap lazily #388

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions lua/rust-tools/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,7 +22,7 @@ function M.get_codelldb_adapter(codelldb_path, liblldb_path)
}
end

function M.setup_adapter()
local function setup_adapter()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is making it private necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not. What's the usecase for making it public?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. It already was so without any reason you should keep it the same
  2. The user could call setup themselves whenever they want (which btw the loaded check maybe could be inside setup_adapter?)

local dap = require("dap")
local opts = rt.config.options

Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions lua/rust-tools/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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