From 7a0731212f548e2d5929cc1407391195c2f76845 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Sat, 2 Nov 2024 21:44:16 +0100 Subject: [PATCH] Fix "Run with Args" for Java --- lua/lazyvim/plugins/extras/dap/core.lua | 29 ++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lua/lazyvim/plugins/extras/dap/core.lua b/lua/lazyvim/plugins/extras/dap/core.lua index ac6709f1..506167cf 100644 --- a/lua/lazyvim/plugins/extras/dap/core.lua +++ b/lua/lazyvim/plugins/extras/dap/core.lua @@ -1,5 +1,20 @@ +---@param config {args?:string|fun():string?} +local function get_args_as_string(config) + local args = type(config.args) == "function" and (config.args() or "") or config.args or "" + ---@cast args string + if string.len(args) > 0 then + args = args .. " " + end + config = vim.deepcopy(config) + config.args = function() + local new_args = vim.fn.input("Run with args: ", args) --[[@as string]] + return new_args --[[@as string]] + end + return config +end + ---@param config {args?:string[]|fun():string[]?} -local function get_args(config) +local function get_args_as_table(config) local args = type(config.args) == "function" and (config.args() or {}) or config.args or {} config = vim.deepcopy(config) ---@cast args string[] @@ -10,6 +25,18 @@ local function get_args(config) return config end +---@param config {type?:string} +local function get_args(config) + --- Java Dap expects "args" to be a string, not a table + if config.type and config.type == "java" then + ---@cast config {type?:string, args?:string|fun():string?} + return get_args_as_string(config) + else + ---@cast config {type?:string, args?:string[]|fun():string[]?} + return get_args_as_table(config) + end +end + return { { "mfussenegger/nvim-dap",