Dap support

This commit is contained in:
mathijs-bakker
2025-08-21 10:21:27 +02:00
parent b22f882b68
commit 3994ae2237
6 changed files with 96 additions and 21 deletions

37
lua/godotdev/dap.lua Normal file
View File

@@ -0,0 +1,37 @@
local M = {}
function M.setup(config)
local dap = require("dap")
local dapui = require("dapui")
require("godotdev.keymaps").attach_dap()
dap.adapters.godot = {
type = "server",
host = config.editor_host or "127.0.0.1",
port = config.debug_port or 6006,
}
dap.configurations.gdscript = {
{
type = "godot",
request = "launch",
name = "Launch scene",
project = "${workspaceFolder}",
launch_scene = true,
},
}
dapui.setup()
dap.listeners.after.event_initialized["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
return M

View File

@@ -1,2 +1 @@
-- lua/godotdev/init.lua
return require("godotdev.setup")

View File

@@ -1,6 +1,6 @@
local M = {}
function M.attach(bufnr)
function M.attach_lsp(bufnr)
local opts = { buffer = bufnr }
local has_telescope, telescope_builtin = pcall(require, "telescope.builtin")
@@ -57,4 +57,26 @@ function M.attach(bufnr)
map("n", "]d", vim.diagnostic.goto_next, "LSP: Next diagnostic")
end
function M.attach_dap()
local dap = require("dap")
local dapui = require("dapui")
local function map(mode, lhs, rhs, desc)
vim.keymap.set(mode, lhs, rhs, { desc = desc })
end
-- Basic debugger controls
map("n", "<F5>", dap.continue, "DAP: Continue/Start")
map("n", "<F10>", dap.step_over, "DAP: Step over")
map("n", "<F11>", dap.step_into, "DAP: Step into")
map("n", "<F12>", dap.step_out, "DAP: Step out")
map("n", "<leader>db", dap.toggle_breakpoint, "DAP: Toggle breakpoint")
map("n", "<leader>dB", function()
dap.set_breakpoint(vim.fn.input("Breakpoint condition: "))
end, "DAP: Conditional breakpoint")
-- UI
map("n", "<leader>du", dapui.toggle, "DAP: Toggle UI")
map("n", "<leader>dr", dap.repl.open, "DAP: Open REPL")
end
return M

View File

@@ -29,7 +29,7 @@ M.setup = function(config)
capabilities = capabilities,
on_attach = function(client, bufnr)
utils.suppress_unsupported_lsp_messages(client, { "Method not found: godot/reloadScript" })
keymaps.attach(bufnr)
keymaps.attach_lsp(bufnr)
end,
})
end

View File

@@ -3,12 +3,29 @@ local M = {}
M.opts = {
editor_host = "127.0.0.1",
editor_port = 6005,
debug_port = 6006,
}
function M.setup(opts)
M.opts = vim.tbl_extend("force", M.opts, opts or {})
require("godotdev.lsp").setup({ editor_host = M.opts.editor_host, editor_port = M.opts.editor_port })
require("godotdev.health").setup({ port = M.opts.editor_port })
require("godotdev.lsp").setup({
editor_host = M.opts.editor_host,
editor_port = M.opts.editor_port,
})
require("godotdev.health").setup({
port = M.opts.editor_port,
})
local dap_ok, dap = pcall(require, "dap")
if dap_ok then
dap.adapters.godot = {
type = "server",
host = M.opts.editor_host,
port = M.opts.debug_port,
}
end
end
return M

View File

@@ -3,22 +3,22 @@ local M = {}
--- Suppress specific LSP messages
-- @param client vim.lsp.Client
-- @param patterns table List of string patterns to ignore in client messages
function M.suppress_lsp_messages(client, patterns)
local orig_handler = vim.lsp.handlers["window/showMessage"]
vim.lsp.handlers["window/showMessage"] = function(err, method, params, client_id)
local lsp_client = vim.lsp.get_client_by_id(client_id)
if lsp_client and lsp_client.name == client.name then
if params and params.message then
for _, pat in ipairs(patterns) do
if params.message:match(pat) then
return -- silently ignore this message
end
end
end
end
-- fallback to original handler for all other messages
orig_handler(err, method, params, client_id)
end
function M.suppress_unsupported_lsp_messages(client, patterns)
local orig_handler = vim.lsp.handlers["window/showMessage"]
vim.lsp.handlers["window/showMessage"] = function(err, method, params, client_id)
local lsp_client = vim.lsp.get_client_by_id(client_id)
if lsp_client and lsp_client.name == client.name then
if params and params.message then
for _, pat in ipairs(patterns) do
if params.message:match(pat) then
return -- silently ignore this message
end
end
end
end
-- fallback to original handler for all other messages
orig_handler(err, method, params, client_id)
end
end
return M