Repository navigation
Extend customToolReplacesArgs to allow replacing all tool args #3749
Description
This is not working as I expect based on the prior information in this issue. I have created a brand new dart project, a simple cli app. For my launch config, I first tried this:
{
"name": "toolTest",
"request": "launch",
"type": "dart",
"program": "bin/main.dart",
"customTool": "echo",
}
Output:
--enable-asserts --enable-vm-service=0 --pause_isolates_on_start=true --no-serve-devtools --write-service-info=file:///var/folders/h0/y0mhxm317slfr5k149cfxvfr0000gn/T/dart-vm-service-7630.json -DSILENT_OBSERVATORY=true bin/main.dart
So far so good. I then tried to see if I could remove args:
{
"name": "toolTest",
"request": "launch",
"type": "dart",
"program": "bin/main.dart",
"customTool": "echo",
"customToolReplacesArgs": 2,
}
Output:
--enable-asserts --enable-vm-service=0 --pause_isolates_on_start=true --no-serve-devtools --write-service-info=file:///var/folders/h0/y0mhxm317slfr5k149cfxvfr0000gn/T/dart-vm-service-6a28.json -DSILENT_OBSERVATORY=true bin/main.dart
Hmm, that's odd. Nothing got removed. Maybe it need tool args to replace them?
{
"name": "toolTest",
"request": "launch",
"type": "dart",
"program": "bin/main.dart",
"customTool": "echo",
"customToolReplacesArgs": 2,
"toolArgs": [
"test",
"arg"
]
}
Output:
test arg --enable-asserts --enable-vm-service=0 --pause_isolates_on_start=true --no-serve-devtools --write-service-info=file:///var/folders/h0/y0mhxm317slfr5k149cfxvfr0000gn/T/dart-vm-service-6280.json -DSILENT_OBSERVATORY=true bin/main.dart
So it appears that "echo" replaces "dart" as the tool but customToolReplacesArgs maybe does nothing?
{
"name": "toolTest",
"request": "launch",
"type": "dart",
"program": "bin/main.dart",
"customTool": "echo",
"toolArgs": [
"test",
"arg"
]
}
Output:
test arg --enable-asserts --enable-vm-service=0 --pause_isolates_on_start=true --no-serve-devtools --write-service-info=file:///var/folders/h0/y0mhxm317slfr5k149cfxvfr0000gn/T/dart-vm-service-19d2.json -DSILENT_OBSERVATORY=true bin/main.dart
Same thing. How do I get the arg replacement to work?
Additionally, if I try this with a flutter project, it completely ignores "customTool" and continues running as normal even though I'm using the exact same launch config. How does the extension determine whether it's a flutter project or not and why does it ignore the customTool arg?
Originally posted by @point-source in #3656 (comment)
Activity
DanTup commentedon Dec 30, 2021
customToolReplacesArgsis only intended to replace the args that are part of the tool invocation itself and not the arguments passed to it. The goal is to allow you to replace"dart run test: test"with a custom tool, orflutter runwith a custom tool.Replacing the arguments passed to the tool is not possible and would be quite complicated, as these arguments vary depending on a number of things (including SDK version, whether you run with debugging, what you're invoking, etc.) and the order is not guaranteed.
Can you describe what it is you're trying to do, and maybe I can suggest an alternative way?
If it's not working at all, that sounds like a bug - please file a separate issue with repro steps and I'll take a look.
It uses the presence of the Flutter SDK in pubspec.yaml to decide if a project is Flutter or not.
point-source commentedon Dec 30, 2021
The original tool or the custom tool?
What is an example of an arg that is part of the tool invocation but is not passed to it? As for args that are passed, do you mean passed via the "toolArgs" array or the "args" array?
Sorry, this is so hard for me to fully grasp. The terminology could mean so many things because we have two sets of tools and two sets of args and so it makes it difficult to discuss here unless we choose very specific terms for each thing. I propose that we consider the following:
"tool": The original tool that would have been invoked if "customTool" were not set (essentially either "dart" or "flutter" in this case)
"customTool": The tool that will be invoked instead of the original tool ("echo" in this case)
"nativeArgs"?: Guessing these are args that are somehow built into the invocation and not generally modifiable? (such as when "dart" is passed "run" but this doesn't show up in my example echoed output. I would have expected it to originally. But maybe it isn't passed? Is "echo" truly only replacing "dart" or is it replacing "dart run"?)
"args"?: Args pass to the tool by the extension but not by the launch.config (things like
--enable-vm-service=0)"passedArgs"?: Args provided by the user in the launch.config's "args" array (intended for the original tool)
"toolArgs"?: Args provided by the user in the launch.config's "toolArgs" array (intended for the customTool)
Do I have that terminology roughly correct? Can you edit it as necessary to clarify?
Anyway, what I was expecting is that by setting that value to "1", it would change the output of my test from:
--enable-asserts --enable-vm-service=0 --pause_isolates_on_start=true --no-serve-devtools --write-service-info=file:///var/folders/h0/y0mhxm317slfr5k149cfxvfr0000gn/T/dart-vm-service-6a28.json -DSILENT_OBSERVATORY=true bin/main.dartto:
--enable-vm-service=0 --pause_isolates_on_start=true --no-serve-devtools --write-service-info=file:///var/folders/h0/y0mhxm317slfr5k149cfxvfr0000gn/T/dart-vm-service-6a28.json -DSILENT_OBSERVATORY=true bin/main.dartNote that the first arg
--enable-assertsis removed. This would allow me to manually replace that arg with one of my own. If that's not what this is for, can you give me an example of which part of the tool invocation would get removed?Edit: As requested, I filed a new issue for the flutter problem I'm having.
[-]VSCode Dart Extension // customTool arg does not appear to work as intended[/-][+]VSCode Dart Extension // customToolReplacesArgs doesn't appear to have an effect[/+]DanTup commentedon Jan 4, 2022
It turns out the implementations have not been consistent between the Dart-Code DAP and the SDK DAP, so one of them needs to change.
Thinking more about this, I think allowing
customToolReplacesArgsto replace all of the built-in args (eg. indart test --enable-asserts foo.dartallow--enable-assertsto be included, and not onlytest) probably makes the most sense (and is what the new SDK DAP is already doing).So, I think the change I'm going to make is probably what you'd like - allowing
customToolReplacesArgsto replace things like--enable-asserts. However, be mindful that the order of these arguments is not guaranteed, so if you need to just remove one of them (for example the third one), that might not be possible.[-]VSCode Dart Extension // customToolReplacesArgs doesn't appear to have an effect[/-][+]Extend `customToolReplacesArgs` to allow replacing all tool args[/+]Extend customToolReplacesArgs to replace all built-in tool args in ad…
DanTup commentedon Jan 4, 2022
A slight correction from above..
customToolReplacesArgswill replace all built-in tool args added by the debug adapter. The example I gave above--enable-assertsis not one of these, as it is added by the client. That can be removed by settingenableAsserts: falsein the launch config. The other debug adapter-added flags (--start-paused, etc.) are all now replacable.point-source commentedon Jan 4, 2022
DanTup,
Thanks for taking a look and working on this so quickly. To be clear, my use case doesn't necessarily need that specific functionality. I was mostly just trying to conceptualize the operation of the tool so I had my head wrapped around it and could use it in a predictable manner going forward. In my tests, I was not able to figure out what it did.
That said, the changes you made appear to extend functionality in a useful way. My only concern is that it is still rather opaque in what it is doing. I know this was mentioned in the original feature request and the conclusion was that using documentation and the "echo" tool, one could discover the operation.
I just wanted to throw it out there that we could perhaps just do an exclude list of args rather than a iteration based removal. That way, even though discovery remains opaque, the implementation on the config side is explicit and users can see exactly which args are being removed. This also solves the position problem.
Something like:
DanTup commentedon Jan 5, 2022
@point-source yeah, that had crossed my mind recently too, but I don't want this to get too complicated without a solid use case/example. Generally if you want to put a tool in place of Dart/Flutter, it should be very compatible with them, so the best thing is for them to implement the same interface.
The changes made above were a fairly simple extension of existing behaviour that's necessary for internal Bazel workspaces and I think will solve most use cases (even if you have to set the number high to remove everything, then just add things back in
toolArgs), but if you have a concrete use where this isn't sufficient please do file a new issue with the details.Dart-Code will soon move over to an SDK-shipped debug adapter, which means functionality like this needs to be also implemented there, and will be shared by other editors too (and thus becomes harder to change, as we need to consider compatibility) so there will likely be a higher bar for implementing things than when the debug adapter just lived here (and could be changed at the same time as the only editor using it).