mfussenegger / nvim-dap

Debug Adapter Protocol client implementation for Neovim
GNU General Public License v3.0
5.17k stars 180 forks source link

Saving current configurations to launch json #1051

Closed asmodeus812 closed 9 months ago

asmodeus812 commented 9 months ago

Problem Statement

Would be cool if we could save the current set of configs to a launch json file, or have an api to which we can pass a list of configs we would like to save.

Possible Solutions

No response

Considered Alternatives

Serializing the lua tables to files, instead of json, but it won't be very portable i.e for vscode users.

MahboobMMonza commented 9 months ago

I had a similar suggestion to this. Plugins like nvim-jdtls do quite a bit of setup for the debug configs, but I want to add additional changes to that as well inside the launch.json on a per-project basis.

mfussenegger commented 9 months ago

Thanks for the suggestion but I won't be adding this.

If you can ignore those two aspects, it's pretty simple to do anyways:

local f = assert(io.open(".vscode/launch.json", "w"))
local launch = {
    version = "0.2.0",
    configurations = require("dap").configurations.java
}
f:write(vim.json.encode(launch))
f:close()

And to format it using jq, add:

local obj = vim.system({"jq", ".", ".vscode/launch.json"}, { text = true }):wait()
f = assert(io.open(".vscode/launch.json", "w"))
f:write(obj.stdout)
f:close()