Skip to content
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

Support object inspection through DAP #97585

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rsubtil
Copy link
Contributor

@rsubtil rsubtil commented Sep 28, 2024

Closes #97182.

Implements object inspection through DAP. All object properties are bundled in Categories for organization, similarly to what is shown from Godot:
image
image

Object inspection is done in a lazy fashion, as the performance impact of querying them is quite significant. DAP IDs are generated for detected object types when parsing Variants, and information is only requested from the debuggee when an explicit variables request is made.

@rsubtil rsubtil requested a review from a team as a code owner September 28, 2024 12:07
Copy link
Collaborator

@Faless Faless left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, please see changes to avoid including std:optional.

As @AThousandShips pointed out, we might also want to remove the lambdas too (though there are some use in other editor code, we still try to avoid them, especially in combination with auto).

editor/debugger/debug_adapter/debug_adapter_protocol.cpp Outdated Show resolved Hide resolved
editor/debugger/debug_adapter/debug_adapter_protocol.h Outdated Show resolved Hide resolved
editor/debugger/debug_adapter/debug_adapter_parser.cpp Outdated Show resolved Hide resolved
editor/debugger/debug_adapter/debug_adapter_protocol.h Outdated Show resolved Hide resolved
Copy link
Collaborator

@Faless Faless left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 , nice work!

editor/debugger/debug_adapter/debug_adapter_parser.cpp Outdated Show resolved Hide resolved
editor/debugger/debug_adapter/debug_adapter_protocol.cpp Outdated Show resolved Hide resolved
editor/debugger/debug_adapter/debug_adapter_protocol.cpp Outdated Show resolved Hide resolved
editor/debugger/debug_adapter/debug_adapter_parser.cpp Outdated Show resolved Hide resolved
editor/debugger/debug_adapter/debug_adapter_protocol.cpp Outdated Show resolved Hide resolved
editor/debugger/debug_adapter/debug_adapter_protocol.cpp Outdated Show resolved Hide resolved
editor/debugger/debug_adapter/debug_adapter_protocol.cpp Outdated Show resolved Hide resolved
editor/debugger/debug_adapter/debug_adapter_protocol.cpp Outdated Show resolved Hide resolved
editor/debugger/debug_adapter/debug_adapter_protocol.cpp Outdated Show resolved Hide resolved
editor/debugger/debug_adapter/debug_adapter_protocol.cpp Outdated Show resolved Hide resolved
@rsubtil rsubtil force-pushed the feature-dap_object_inspection branch 2 times, most recently from 948a2fc to 56c08f6 Compare September 28, 2024 15:53
@van800
Copy link
Contributor

van800 commented Sep 30, 2024

Awesome!
I have tried it a little bit.
It works great for variables request, as your mentioned.
I wonder, why have you decided to not enable it for evaluate requests?
image

@rsubtil
Copy link
Contributor Author

rsubtil commented Sep 30, 2024

I wonder, why have you decided to not enable it for evaluate requests?

Whoops, I forgot about the evaluate request, I'm sorry 😅

This one is a bit trickier because Godot receives a plain string to evaluate, rather than a variable ID. This exists already for evaluating script tokens, so the result is the same here from Godot (the cursor isn't visible, but it is hovering the self token at line 11):
image

But I can actually easily store this mapping between variable name and DAP variable ID when the stack frame is being parsed, so it shouldn't be difficult to support this. So, while the result string would stay the same, the variablesReference would now point to a valid ID, which I assume IDEs will then use to generate a variables request for more info.

@van800
Copy link
Contributor

van800 commented Sep 30, 2024

Sure, I would be willing to test.

Evaluate is not only for hovering but also for expression evaluation. Like in "Watch" in vscode or similar in Rider.
image

Unfortunately I don't know how to configure vscode to use DAP for a proper comparison.

@rsubtil rsubtil force-pushed the feature-dap_object_inspection branch from 56c08f6 to 870254b Compare September 30, 2024 13:16
@rsubtil
Copy link
Contributor Author

rsubtil commented Sep 30, 2024

Turned out to be simple indeed; I've implemented support for it when an evaluated variable has been parsed, please test to see if behavior is correct now. VSCode seems to be working correctly:
image

Unfortunately I don't know how to configure vscode to use DAP for a proper comparison.

You can check this guide in the docs on how to set up LSP/DAP support on VSCode.

@van800
Copy link
Contributor

van800 commented Sep 30, 2024

Please try to evaluate expression in vscode:
image

I confirm that evaluating self now works, but the self.position expression evaluates to empty string (left-bottom corner).
Special thanks for linking the guide, now I am using it.

@rsubtil
Copy link
Contributor Author

rsubtil commented Sep 30, 2024

I confirm that evaluating self now works, but the self.position expression evaluates to empty string (left-bottom corner).

As it's currently implemented, the evaluate expression only looks at any existing variable that matches the requested content. self.position is not a variable, and so it returns empty.

What you're asking for is REPL, which Godot doesn't support... yet; there's some activity around it, like #60134 (and #97647 which was open... just 4 hours ago 😁)

@van800
Copy link
Contributor

van800 commented Oct 1, 2024

Interestingly, evaluating expressions almost works in VS Code when using legacy non-DAP mode, which led me to believe it could be added to DAP mode as well. That said, I’m very happy with this pull request regardless.

@rsubtil
Copy link
Contributor Author

rsubtil commented Oct 1, 2024

I see. I had a quick peek at the VSCode plugin, and keeping in mind I'm not familiarized with the codebase at all, I'd wager it is building an internal tree of variables when variable information comes, which is then used for this scenario when there is a variable access. So, it is something the addon itself is doing, and not Godot.

Again, I can be completely wrong here, but if that's what the addon does, instead of replicating this from Godot, I'd wait to see if REPL functionality is implemented in the meantime, as it is a much better solution for this.

EDIT: Ok, the PR I talked about was merged an hour ago, lol 🎉. I'll have a look to see if it can use this new system.

@akien-mga
Copy link
Member

Does the above discussion imply that you'd prefer to do further work here @rsubtil based on #97647, or is that for follow-up work / specific to the VS code extension?

@rsubtil
Copy link
Contributor Author

rsubtil commented Oct 2, 2024

Does the above discussion imply that you'd prefer to do further work here @rsubtil based on #97647, or is that for follow-up work / specific to the VS code extension?

This would replace the changes I did in the meantime for the evaluate request, so I think it's worth it to replace them already with this new system. I also don't expect this to be difficult, and should be ready in the next coming days.

@rsubtil rsubtil force-pushed the feature-dap_object_inspection branch from 870254b to 66c2b7b Compare October 3, 2024 20:42
@rsubtil
Copy link
Contributor Author

rsubtil commented Oct 3, 2024

I've changed the evaluate request to go through the new REPL system, so more advanced expressions should work properly now:
image

Since these two requests require information from the debuggee, I've also increased the default timeout from 1 to 5 seconds to give it more "breathing room" when having to complete potentially heavy requests.

@rsubtil rsubtil force-pushed the feature-dap_object_inspection branch from 66c2b7b to 9dd7a8a Compare October 3, 2024 20:57
@van800
Copy link
Contributor

van800 commented Oct 4, 2024

Great! Tried it in Rider and VScode.

Out of scope, but I'd rather ask, if Completions Request from the spec is not implemented, right?
It made it hard to figure out that why evaluation self.path was null, while I should have called self.get_path().

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work as usual! Thanks for your dedication to maintaining the DAP support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants