You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support "inspect()" method from "dart:developer" library #2137
in debuggingRelates to the debug adapter or process of running debug sessionsis enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
Send a reference to object to any attached debuggers.
Debuggers may open an inspector on the object. Returns the argument.
Dart Code currently doesn't do anything when inspect is called, so I was wondering if adding support for it has ever been considered. Here's how I would imagine this feature to work:
Dart Code detects that inspect was called.
The matching value inside of the "Variables" panel is resolved.
The "Variables" panel is expanded and the resolved value is highlighted.
Is this doable? If it is, I'd be happy to make a pull request. I might need a little heads up on where to start though.
I don't think there are any APIs in VS Code that would let us interact with the Variables pane in that way. Normally VS Code will call us whenever the code pauses and ask for the data that should be listed there, but it doesn't let us push to it, nor control things like expansion or focus.
We are already somewhat handling this event - it's how we navigate to widget code as you're clicking on items in the Flutter inspector (eg. in DevTools).
@devoncarew@jacob314 should we do more with this event here (eg. for non-widgets)? I can't tell from the IntelliJ handler whether it's doing anything more here.
@shroudedcode what's the use case you have in mind? Maybe there's another way we can achieve it (do logpoints help?).
I was looking for a way to quickly jump to a deeply nested object in the "Variables" panel and discovered the inspect() method while looking at the dart:developer docs. I thought it would be the perfect solution and was disappointed to find that it didn't work with Dart Code's debugger.
Maybe there's another way we can achieve it (do logpoints help?).
Yeah, calling inspect() is certainly not the only way to inspect the piece of data I was looking for. I only opened this issue because I felt like Dart Code should support inspect() because one might expect that it does after reading through the dart:developer docs. If VS Code doesn't have an API for focusing elements in the "Variables" panels, there's not really anything that can be done about this though.
I was looking for a way to quickly jump to a deeply nested object in the "Variables" panel
Even with the VS Code API, I'm not sure this would be feasible - there could be several (or zero) variables in the list that have references to your object many levels deep and I'm not sure how you could find them without traversing the tree (which would be very slow, and there may be side-effects if you execute all of the getters as your search).
I wonder if we could dump the object to the debug console, would that be useful? For example here, I'm at a breakpoint and I typed home into the debug console to have it evaluated. The response is an object you can expand/collapse to see it's fields:
It might be possible that we could make inspect(home) behave the same way that typing home into there. If we did, we probably wouldn't want to do it for every item you click in the Widget Inspector though (which I think also fires the same event). @jacob314@devoncarew what do you think? If we can differentiate widget inspector inspect events from those from user code, does this seem like a reasonable use of inspect()? (the docs are a bit vague so it's not clear if users should use it in this way - if not, we should probably make that clearer).
I wonder if we could dump the object to the debug console, would that be useful?
Absolutely! I even think that this would be a better solution and it perfectly fits the definition of open an inspector on the object in my opinion since it's more than just a static "string log". I also think the debug console should be opened automatically (and maybe scrolled to the bottom) to satisfy the open part of the definition and make it more obvious where the output is shown.
Judt upgraded flutter. I sometimes get <evalError>:<collected> when I inspect something. Sometimes it does work, and I am able to expand the inspected object. Any idea what it means?
@danielchan303 please file a new issue about this. I think it would be a nice feature, although I'm not sure how well it would work without VS code having some way to choose whether a logpoint is intended as a message versus an expression whose result should be inspected. Perhaps if the data is a single expression with no prefix/suffix ({foo}) and the expression evaluates to something that is not a simple string/number/etc. then we could do this (and if you only wanted the string representation you could just add a prefix/suffix: foo: {foo}).
in debuggingRelates to the debug adapter or process of running debug sessionsis enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
Activity
DanTup commentedon Dec 2, 2019
I don't think there are any APIs in VS Code that would let us interact with the Variables pane in that way. Normally VS Code will call us whenever the code pauses and ask for the data that should be listed there, but it doesn't let us push to it, nor control things like expansion or focus.
We are already somewhat handling this event - it's how we navigate to widget code as you're clicking on items in the Flutter inspector (eg. in DevTools).
@devoncarew @jacob314 should we do more with this event here (eg. for non-widgets)? I can't tell from the IntelliJ handler whether it's doing anything more here.
@shroudedcode what's the use case you have in mind? Maybe there's another way we can achieve it (do logpoints help?).
jacob314 commentedon Dec 2, 2019
We aren't doing anything more along those lines in IntelliJ today as far as I know.
niklashigi commentedon Dec 2, 2019
I was looking for a way to quickly jump to a deeply nested object in the "Variables" panel and discovered the
inspect()method while looking at thedart:developerdocs. I thought it would be the perfect solution and was disappointed to find that it didn't work with Dart Code's debugger.Yeah, calling
inspect()is certainly not the only way to inspect the piece of data I was looking for. I only opened this issue because I felt like Dart Code should supportinspect()because one might expect that it does after reading through thedart:developerdocs. If VS Code doesn't have an API for focusing elements in the "Variables" panels, there's not really anything that can be done about this though.DanTup commentedon Dec 3, 2019
Even with the VS Code API, I'm not sure this would be feasible - there could be several (or zero) variables in the list that have references to your object many levels deep and I'm not sure how you could find them without traversing the tree (which would be very slow, and there may be side-effects if you execute all of the getters as your search).
I wonder if we could dump the object to the debug console, would that be useful? For example here, I'm at a breakpoint and I typed
homeinto the debug console to have it evaluated. The response is an object you can expand/collapse to see it's fields:It might be possible that we could make
inspect(home)behave the same way that typinghomeinto there. If we did, we probably wouldn't want to do it for every item you click in the Widget Inspector though (which I think also fires the same event). @jacob314 @devoncarew what do you think? If we can differentiate widget inspector inspect events from those from user code, does this seem like a reasonable use ofinspect()? (the docs are a bit vague so it's not clear if users should use it in this way - if not, we should probably make that clearer).niklashigi commentedon Dec 3, 2019
Absolutely! I even think that this would be a better solution and it perfectly fits the definition of open an inspector on the object in my opinion since it's more than just a static "string log". I also think the debug console should be opened automatically (and maybe scrolled to the bottom) to satisfy the open part of the definition and make it more obvious where the output is shown.
Support printing inspected variables to the debug console
Support printing inspected variables to the debug console
ajain-bst commentedon Sep 8, 2020
Judt upgraded flutter. I sometimes get
<evalError>:<collected>when I inspect something. Sometimes it does work, and I am able to expand the inspected object. Any idea what it means?DanTup commentedon Sep 8, 2020
@ajain-bst I've responded over in #2780. Thanks!
danielchan303 commentedon Jan 4, 2023
It will be great if the vscode logpoints can have this feature, instead of outputting the string, can output the expandable object.
DanTup commentedon Jan 4, 2023
@danielchan303 please file a new issue about this. I think it would be a nice feature, although I'm not sure how well it would work without VS code having some way to choose whether a logpoint is intended as a message versus an expression whose result should be inspected. Perhaps if the data is a single expression with no prefix/suffix (
{foo}) and the expression evaluates to something that is not a simple string/number/etc. then we could do this (and if you only wanted the string representation you could just add a prefix/suffix:foo: {foo}).