So this is huge... I just started poking at Micros...
# development
b
So this is huge... I just started poking at Microsoft's DAP for editor-agnostic debugging and turns out it would be trivial to get working (at least for Python, likely easy for other languages). What does this mumbo jumbo mean? YOU CAN USE IN-EDITOR BREAKPOINTS TO DEBUG YOUR CODE/TESTS RUN BY PANTS! It's quite trivial to support too! See 🧵
(Focusing on Python because that's where I am 🙂) So turbo speed-run on DAP: Generic protocol Editors can opt into to allow language-agnostic debugging experience. Then lagnuage-specific server does the language-specific finagling under the hood. Python's DAP is
debugpy
: https://github.com/microsoft/debugpy So essentially there's two halves: • A
debugpy
server must be launched with the relevant code running • Your Editor (like VS Code) connects to it via a client, and sends the breakpoint and other info to it. So if you wanted to do this today (try it!) Put the following at the top of your code:
Copy code
import debugpy
debugpy.listen(5678)  # Thats the port, localhost by debugpy.wait_for_client()
Running your code (
./pants test --debug
or
./pants run
) then launches the server and waits for connection. In your editor pick the "remote attach" option using the right port. Then F5 to launch the debugger. This connects to the server and tells it the current debugging info (breakpoints and other settings). 🎉
What does this have to do with Pants?
We can add an option to Pants to launch the relevant DAP when requested, so no code instrumentation is needed.
debugpy
comes with a "launched" out of the box for this. So (and details to be discussed)
./pants debug <spec>
would run your code with the DAP server launched and waiting for a connection.
I gotta get a PoC going, we can figure out the right CLI sauce though
w
very nice!
DAP is lightly related to BSP, as it is the protocol supported by `debugSession/start`: https://build-server-protocol.github.io/docs/specification.html#debug-request
1
we don’t support it yet for Scala, but we’d like to
b
In this case, I think it can be done seprately. In this instance I'm happy to tackle Python because of how easy it is
w
bsp is launched via
experimental-bsp
… so
experimental-dap
might be a good parallel
b
One goofy bit is ambiguity between
run
and
test
.
./pants dap path/to/test_file.py
should probably run the file like the test goal, but with my proposal might be ambiguous
An alternative is to add
--use-dap
to
run
and
test
w
yea. fwiw:
test
has
--debug
, which supports conditionally adding additional arguments
b
Yeah thats what you need to do to (cleanly, you dont have to) get this working with the instrumentation
w
…correction. the conditional additional arguments are JVM specific. so that’s more of a convention. but: when you set
--debug
, the JVM code adds
[jvm] debug_args
: https://www.pantsbuild.org/docs/reference-jvm#section-debug-args
b
Yeah I think it could be as simple as
--debug-dap
(or similar) flags. I think we'd wanna compare Python's "drop-in" ability to maybe Java's or GO's DAP
w
yea, good idea.
b
So thinking about this,
debugpy
need to be launching the python script/module which makes it conflict a bit with the pytest PEX. I'm gonna have to finagle this one
w
woot!
b
Bump on the PR. I'd like another set of eyes before I make the same change to
--run
👍 1
w
looks good!