Closed MahboobMMonza closed 1 year ago
I implemented something that does exactly that. But I mapped it to a keystroke, so I can use it if neccessary:
specifyArgsForJava = function()
--- refresh ?= JdtDebugRefreshConfigs
local dap = require("dap")
if dap.configurations.java == nil then
print("Dap does not hava java config yet")
return
end
local opts = {}
for i, key in pairs(dap.configurations.java) do
opts[i] = key.mainClass
-- for k, j in pairs(key) do
-- if type(j) == "table" then
-- print("K: " .. k .. " table")
-- else
-- print("K: " .. k .. " J:" .. j)
-- end
-- end
end
local onSelectClass = function(s, idx)
if s == nil then
return
end
print("Got: " .. s)
local onInputParams = function(i)
print("Input for " .. s .. ": " .. i)
dap.configurations.java[idx].args = i
end
vim.ui.input(
{ prompt = "Commandline params for " .. s .. ":", default = dap.configurations.java[idx].args },
onInputParams
)
end
vim.ui.select(opts, { prompt = "Main Class" }, onSelectClass)
end
Unfortunately, I did not find a way to specify the spring profile, as adding -Dspring.profile.active
does not work (it is passed to the Main class not Spring).
You can either override/extend the configuration using the config_overrides
option of setup_dap_main_class_configs
. For example:
:lua require("jdtls.dap").setup_dap_main_class_configs( { config_overrides = { args = function() return vim.fn.input("Args: ") end } })
See :help jdtls.dap.setup_dap_main_class_configs
Or you can use fetch_main_configs
and customize the configurations completely.
See :help jdtls.dap.fetch_main_configs
I won't be adding more specific custom options as the combinations that people may want explode very quickly.
I'd in general recommend to add a .vscode/launch.json
file to a project if it's frequently launched with the same arguments or if it requires custom options.
And if the arguments frequently change you're probably better of creating test cases and debug those.
Does the launch.json
file have to be located in a .vscode
folder?
You can also specify the path. See :help dap.ext.vscode.load_launchjs
Thank you
Is is possible to export the current dap configs inside nvim-jdtls
for a project as a JSON? Was hoping to use this feature to speed up creation of my own customized launchs.
Problem Statement
Currently,
nvim-jdtls
's default DAP configuration for Main classes does not have any way to pass in command line arguments, and this issue is a request to place this as an option (e.g.Launch yourProject : Main with command line args
in addition to the default configurations).Ideas or possible solutions
Add a "duplicate" configuration with the following passed in for the
args
parameter:Provide the user with the choice between a no-args configuration and an argument-friendly configuration to run.