1

In dap-mode, is it possible to define a debug template that will ask the operator for one of its :args?

For instance, in the following example, I'd like to debug something like python example.py --arg1 PROMPTED:

(dap-register-debug-template "Example" (list :type "python" :request "launch" :program "example.py" :args (lambda () "Prompt the operator for the value of one argument" (list "--arg1" (read-string "Please provide value for arg1: "))) ) ) 

Now I get a warning Initialize request failed: Invalid message: "args"[1] must be str and the debug session is killed.

1 Answer 1

1

This issue primarily depends on the capabilities of the debugger you are using, as dap-mode itself is just a client for the underlying debugger and does not perform the debugging itself. It essentially forwards the configuration template you provide to the debugger with minimal preprocessing.

If you are using debugpy (commonly used for Python), you should consult its documentation to verify which parameters and values are supported: debugpy Launch/Attach Settings.

Unfortunately, dap-mode does not evaluate or dynamically process templates before sending them to the debugger. This is why using a lambda or function call inside the :args field does not work. The :args key in the template is expected to be a static list of strings.

As for implementing dynamic prompts (e.g., asking the user for input when starting the debugging session), this feature is currently not supported in dap-mode. It would require a modification to the dap-register-debug-template function to allow, for example a third parameter or a flag to indicate that the template needs to be evaluated dynamically before sending it to the debugger.

If this feature is essential for your workflow, you could consider submitting a feature request or pull request to the dap-mode repository to add support for dynamically evaluated templates. For now, a workaround would be to predefine multiple templates for different argument sets or to manually edit the args field in your template before launching the debugger.

2
  • 1
    » "...dap-mode does not evaluate or dynamically process templates before sending them to the debugger..." Thanks for clarifying this point. Yes, I have a bunch of similar templates with different arguments :) Before bothering the dap-mode guys, I'll try to write a function that generates a new template on the fly by asking the user for the arguments I need, applying them to the "template of a debug-template", and start the debugger with it (seems a bit convoluted...) Commented Dec 13, 2024 at 8:29
  • @MatteoGamboz Feel free to accept the answer if it helped you understand the behavior and solve the problem (even if you ended up solving it differently) :) Commented Dec 13, 2024 at 13:31

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.