Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving current configurations to launch json #1051

Closed
asmodeus812 opened this issue Oct 8, 2023 · 2 comments
Closed

Saving current configurations to launch json #1051

asmodeus812 opened this issue Oct 8, 2023 · 2 comments

Comments

@asmodeus812
Copy link
Contributor

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
Copy link

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
Copy link
Owner

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

  • nvim-dap by default contains no configuration generation. Saving configurations you couldn't generate seems odd.
  • Lua is a superset of JSON as JSON can't represent the functions
  • Some of the plugins which can generate configurations are also dynamically adding properties. You probably don't want to include these in the persisted JSON config. nvim-dap by itself doesn't know what properties would get dynamically resolved or not. For example. nvim-jdtls always generates javaExec, classpath and modulePaths entries. In most cases you wouldn't want to include them.

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()

@mfussenegger mfussenegger closed this as not planned Won't fix, can't repro, duplicate, stale Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants