-
Notifications
You must be signed in to change notification settings - Fork 755
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
debug: support customizable pretty-printing of a struct #158
Comments
Found the feature I was referring to in the original ticket. Would be amazing if vscode-go had something similar. Feature and example linked below (using CPoint as an example) |
@esinek Where exactly does a variable get displayed like this? Are you looking for a mechanism to specify your own prettyprint logic or for the editor to provide some default option? Would it print something like what You can view the variable in the VARIABLES panel with all the nesting and options to expand and load each level. It can be tedious to expand all the nested fields, but I think you only need to do it once. The UI will keep them expanded and you will see as they change as the session progresses. You can also view the variable in the WATCH panel. The same behavior with expanded fields preserved applies. Or you can use a function to print the variable with a recently implemented "call" expression. We could also look into enabling supportsEvaluateForHovers, so the data hover triggers an Evaluate Request, which could return some kind of flattened string representation instead of a nested variable. |
In either VARIABLES or WATCH panes.
Yes, I think it would be reasonable to say I'm looking for a way to specify the prettyprint logic for a type, such that when that type appears in the VARIABLES or WATCH panes, VSCode will prettyprint in the format specified. Also with a way to switch between the prettyprinted value represented as a string and the raw value showing all the properties of the type.
The value add of having a configurable prettyprint per type is to reduce the noise in the VARIABLES or WATCH panes - in a single prettyprinted string, you can see the relevant information without having to use all the available real estate with opened trees of variables
Will the "call" expression support printf like support (I haven't looked into that yet)? That would be a nice feature. It would still require making the "call" multiple times during a single debug session. And if you had multiple types you wanted prettyprinted, it could get tedious.
The hover eval also sounds promising. If the hover is possible with some config per type, I would imagine the prettyprint config per type would also be possible Thank you for your feedback and work on this topic and VSCode in general. It's always a tough trade-off between having an integrated set of really useful features vs a bag of unrelated features (which by themselves may be useful) which, in the end, makes the product a mess. |
We could look into some built-in pretty printing features on our end, but they would be based on built-in types and predefined. This could be made available either with hover or with a custom "print expression" option from the Debug Console or Watch, but there will not be a way for you to configure the pretty printing logic with those. The best I can think of is defining I am not aware of a central way to configure anything type-specific by the user. Maybe there are some custom editor plugins that could intercept the VariablesRequest in the editor and alter the way the UI reports them? But as far as I know nothing like this is available from inside the debug adapter. I do see If you want this type of functionality made available in the editor+adapter, you need to file issues against: |
Thanks @polinasok for investigating this issue and providing background, and @esinek for providing constructive user feedback. To summarize, currently feasible options are:
I don't see anything else which is feasible from this extension beyond these. I propose to close this issue. (*) this expression interpolation is too javascript specific :-( |
Will this cover formatting/pretty-printing |
@rajveermalviya If we were to add better pretty-printing, it would not be customized for |
@hyangah Currently |
@hyangah kindly pointed out this issue on the back of https://groups.google.com/g/delve-dev/c/jXDUDvZErGM/m/9WQSb8mGBAAJ. In my case, such pretty-printing is not limited to structs. I would like to see different string representations of a value. For example, a UX in which different string representations of a variable are presented in a hierarchical display, e.g. nodes for:
for some variable @aarzilli raised the following questions/concerns:
Regarding point 1, I would simply see the different string representations as apparent elements of the slice. Slice elements are already indicated by their index, so I don't think it would be confusing to the user. Perhaps something like:
They could potentially be gathered under a single node that needs to be expanded to keep things tidy. (The example above is not very interesting obviously, but hopefully the sketch gives an idea of what I mean). And this feature could be something that is not turned on by default - but again, I'm straying into territory I know little about when it comes to options etc with respect to DAP. Regarding point 2, I'm not clear how something like this would be useful cross-language, because the very nature of this is Go specific (unless I misunderstood the point?). Also, pushing this to the client means replicating the work for each client (assuming it is possible for each client), when arguably something like this is a common requirement and hence better implemented in the server (from an efficiency and consistency point of view at least). Regarding point 3: is this something that is being tracked elsewhere? I would certainly be interested in following progress on that, thank you. @hyangah also replied in Slack to say "I don't know how to call these for many values rendered in the Variable view safely and efficiently." Whilst it does sound like there are currently challenges in doing something like this, I think it would be a hugely powerful feature. So please consider my comment as a "wish list" item! Thanks again for the work on Delve, dlv-dap et al. |
It's something that would have to be supported by the runtime: golang/go#31132
If you scroll up to the top message you can see an example of an XML formatting language that applies to C# but could apply just as well to Go.
For slices yes, but what about maps or structs? Also is it always the three formatting strings |
Thank you; I've subscribed to that and related issues!
In the case I am considering types implement
I would suggest it needs to be configurable in some way, configurable by type. Hence my suggestion of a node under which to gather these different string representations. Configurable because it's impossible in the general case to know a) what the user wants and b) what verbs etc are supported by a given type. That way, developers using a given package could simply copy-paste and append the configuration to add pretty-printing of types from that package according to certain |
There is a related discussion at #1459, which resulted in adding a string representation "child" to arrays/slices of runes/bytes. |
Per-type customization would be a large undertaking that we are not equipped to take on at this time. To do this with custom XML as shown in a comment on on Jun 2, 2020, we would need support from the vscode editor (you can file a request here). An alternative approach is being discussed in the delve repo at go-delve/delve#2887, so let's move the discussion there. In the meantime, we made a number of improvements to general pretty printing that should make variable inspection easier. See updates below on some specific points/concerns from before:
Since this comment, we added single-line pretty printing of the values like in dlv cli. This is not customizable, but does supply much of the underlying field information without having to expand.
Logpoints have been added and we have code that interprets embedded
This has been addressed as a special case in go-delve/delve#2865, which is will be available with the next release (1.8.3) in a couple of days (or if you install
Since this comment was made, we started printing top-level variable values similar to |
See the original request in microsoft/vscode-go#3032.
As @hyangah says, this is related to #100.
The text was updated successfully, but these errors were encountered: