-
Notifications
You must be signed in to change notification settings - Fork 29.4k
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] Expose the contribution.menus for Variable view #70377
Comments
We could easily expose a new Here's a proposal:
Not sure if that would be helpful. Could the extension identify the scope just by those, or some id of the stackFrame would be needed as well. I believe the some sort of stack frame ID would be needed |
When customize the format, we care more about the variable type instead of name. For different variable types, enable different format options in the context menu. Here is the updated proposal:
With the information above, it will allow the debugger to refresh the whole variables in the specified stack frame with the latest format. If we want to apply the changed format to the selected variable only, we may need carry more variable details in the menu context. Currently i don't figure out which metadata is enough for the debugger to restore the specified variable instance in the back end. It looks like |
@isidorn is there any update on the proposal? |
@testforstephen I have discussed with @weinand and it is still not quite clear how to expose a proper context. |
@testforstephen Before we can proceed here, we have to investigate/decide how we can represent the "variable" element to the action in the extension API. Currently the abstractions used in the DAP are not surfaced anywhere in the extension API. If we start doing that, we have to design the whole DAP surface area. We cannot just surface a "variable". We can plan this design work for a future milestone but there will be no support for this or the next release. There is already another debt item for this work: #70742 |
Good to know the status, thanks. I'd love to get involved in the design discussion or anything else. Feel free to bug me. |
I would love to see this happen as it would open up for a completely new class of extensions for VS Code! For the use cases I'm thinking of the type, value and name of a variable would be enough but I realize you must consider all kinds of use cases. Is there any update on this? |
This feature request asks for two "sub features":
First a proposal for the context menu contributions: As suggested by @isidorn the contribution selector is More complex is the question what information to pass to the context menu command so that the extension code can identify the underlying variable. DAP's For this reason I propose to pass the following context object to the menu command (at least conceptually): {
container: Scope & Variable; // intersection of properties of Scope and Variable
variable: Variable;
} However, there is a problem with this approach: the /**
* A DebugProtocolVariableContainer is an opaque stand-in type for the intersection of the Scope and Variable types defined in the Debug Adapter Protocol. See https://microsoft.github.io/debug-adapter-protocol/specification#Types_Scope and https://microsoft.github.io/debug-adapter-protocol/specification#Types_Variable.
*/
export interface DebugProtocolVariableContainer {
// Properties: the intersection of DAP's Scope and Variable types.
}
/**
* A DebugProtocolVariable is an opaque stand-in type for the Variable type defined in the Debug Adapter Protocol. See https://microsoft.github.io/debug-adapter-protocol/specification#Types_Variable.
*/
export interface DebugProtocolVariable {
// Properties: see details [here](https://microsoft.github.io/debug-adapter-protocol/specification#Base_Protocol_Variable).
} With these definitions the API becomes: {
container: DebugProtocolVariableContainer;
variable: DebugProtocolVariable;
} Some open issues and design and implementation notes:
{
stackFrame: DebugProtocolStackFrame;
container: DebugProtocolVariableContainer;
variable: DebugProtocolVariable;
} @isidorn @testforstephen I'd appreciate your feedback. |
Proposal for API to make VS Code refetch variables: The original feature request asks for a new DAP event to trigger a refetch and refresh of variables in VS Code. This feature requests already exists as microsoft/debug-adapter-protocol#128 and I suggest to continue the discussion about the DAP request there. But I think that a DAP mechanism is not enough because context menu commands are implemented in extensions and not in a debug adapter and there must be an easy way to notify the UI about changes that require to refetch variables and update the UI. @isidorn any idea what we should here? |
@weinand thanks for your proposal, and sorry for the slow response
Alternative name for |
@isidorn thanks for your feedback.
|
Introducing a Variable ID would be great for the UI since I could use it as well for preserving tree expansion state. Though I am not sure how hard it is for adapter to keep these ID's stable between steps. If the ID's are not stable between steps then it is not really an ID... Let's continue the discussion there... |
@isidorn I suggest we start implementing this proposal: The contribution selector is A "when" context variable "contributes": {
"menus": {
"debug/variables/context": [
{
"command": "variables-view.showAsHexValue",
"when": "debugConfigurationType == 'java' && viewItem == 'variable-item'"
}
]
}
} I'll add the following new proposed API in /**
* A DebugProtocolVariableContainer is an opaque stand-in type for the intersection of the Scope and Variable types defined in the Debug Adapter Protocol. See https://microsoft.github.io/debug-adapter-protocol/specification#Types_Scope and https://microsoft.github.io/debug-adapter-protocol/specification#Types_Variable.
*/
export interface DebugProtocolVariableContainer {
// Properties: the intersection of DAP's Scope and Variable types.
}
/**
* A DebugProtocolVariable is an opaque stand-in type for the Variable type defined in the Debug Adapter Protocol. See https://microsoft.github.io/debug-adapter-protocol/specification#Types_Variable.
*/
export interface DebugProtocolVariable {
// Properties: see details [here](https://microsoft.github.io/debug-adapter-protocol/specification#Base_Protocol_Variable).
} And the following context structure will be passed to the commands contributed to {
container: DebugProtocolVariableContainer;
variable: DebugProtocolVariable;
} |
@weinand this makes sense. Please let me know once you add the proposed API in |
@isidorn I've added the two stand-in types |
@weinand @isidorn It's a great proposal. One remaining question is how to refresh Variables view with more granularity.
This is useful if allowed to enable menu on "empty space". For example, if i can enable a formatter menu such as "Show hex" on empty space, i would expect to refresh the whole Variables view in current debug session. The context object can be
Allowed to contribute different menus on different kind of node is also helpful. For example, if the node is a List/Collections/Map object, i would like to add menus such as "Show as Object", "Show as List", etc. This will ask the "when" context key to contain more info. An ideal solution is to let the debugger to return a customized contextValue for each variable in the variable response. Also, if i enabled a menu on an inner or leaf nodes, i would expect to apply the new formatter to the selected node only. Does |
@testforstephen thanks for the feedback
|
As agreed I have pushed a change to allow extensions to contribute to the variables context menu.
Since context menu is not enabled on @testforstephen it would be great if you can give this a try from next week and provide feedback |
@testforstephen looking at your initial comment and after discussing with @weinand it seems like you need the |
Yes, adding a A better solution would be to support "custom" properties in "when" clauses. "contributes": {
"menus": {
"debug/variables/context": [
{
"command": "variables-view.showAsDataTable",
"when": "debugConfigurationType == 'java'
&& viewItem.getCustomProperty('customJavaVariableMenuSelector') == 'array'"
}
]
}
} But this "dynamic" approach is not (yet) supported by VS Code. Another static approach is to use a fixed but VS Code private property name that is not part of the DAP spec, e.g. "__vscode_menuaction_key". DAP stays clean and debug adapters can still contribute VS Code specific stuff. This is OK because the context menu actions in the package.json are VS Code specific too. And a debug adapter could even check the "clientId" and provide this property only for VS Code. |
The
If introducing a new property officially to DAP is a little too far gone, a private property for VS Code only is OK for me.
sure, i will find some time at this week to have a try. Since the Variable refresh event is still on discussing, i can only check whether the menus are added, but cannot run the full e2e. |
@testforstephen thanks for your feedback.
Let's use a VS Code specific property then and find good names for the context and the Variable property. Since we are already using two underscores ("__") as a prefix for VS Code specific properties, I suggest that we extend this prefix to "__vscode" (so that it becomes clear that this is for VS Code only) and then append a "ContextMenuSelector". Now the context name: With this a menu contribution for an "array" Variable would look like this: "contributes": {
"menus": {
"debug/variables/context": [
{
"command": "variables-view.showArrayAsDataTable",
"when": "debugConfigurationType == 'java' && debugProtocolVariableContextMenuSelector == 'array'"
}
]
}
} (...and if we think that @isidorn @testforstephen what do you think? |
@weinand I like this approach, I am just not sure about the name. I would go with the following So instead of Alternative is |
@isidorn there are actually two names:
Using your suggestion, we would have these names then:
So the prefix indicates what is targeted ('vscode') and where it does come from ('debugProtocol'). |
@weinand yes, that sounds good. |
Let me know if you would like me to add this context key on the vscode side. If you are happy with these names. |
@isidorn yes please. |
I have tackled this via 4b54344 Try it out and let me know how it goes. So to recap:
|
@testforstephen Can you do me a small favor, get latest VS Code insiders and post a new picture of the context menu. More about the groups: The Variables context menus has the following default groups which the extensions can contribute to:
|
@isidorn Below is a new picture with formatter menus under |
@testforstephen Lovely, thanks a lot! That's going in our release notes. |
The Java Debugger extension received much feedback to support customizing the Variable Formatter. For example:
But current VS Code doesn't provide the frontend UI or the protocol for changing the Variable Format dynamically. See the docs here, https://code.visualstudio.com/api/references/contribution-points#contributes.menus, it doesn't say the extension could contribute context menus to the debug Variable view.
The request is to expose the contribution.menus for Variable view, and carry the hovered variable
type
info in the menu context. Besides, the DAP should provide some approach to re-request the variable info after dynamically changing the variable format.The text was updated successfully, but these errors were encountered: