vscode-java
vscode-java copied to clipboard
Add support to view inherited members #2342
The reference view API is used to show the document outline with inherited symbols using the new java.ls extension method.
Signed-off-by: Gayan Perera [email protected]
@rgrunber please have a look at the patch and let me know what you think ?
Is it possible to display them in the outline
view?
My thought is: we can register a switch button at the navigation bar of the outline
view like this:
"menus": {
"view/title": [
{
"command": "<Enable Inherited Members Command>",
"when": "view == outline",
"group": "navigation"
},
...
],
}
Then JDT.LS will provide different content based on current mode.
@jdneo You mean using the new ls extension method ?
@gayanper
Not exactly. I'm thinking that we should use the existing LSP request for document symbols. At JDT.LS side, it will store a preference saying that which mode is enabled now (show inherited members or not) and return the response accordingly.
@jdneo ahhh i see, thats sounds neat. I can have a look at it this weekend.
BTW, one thing might be tricky and risk: I'm not sure if it's possible to let outline view do a refresh programmatically. Since when the mode is changed, the content needs to do a refresh.
Seems impossible now: https://github.com/microsoft/vscode/issues/108722
@jdneo the refreshing is a issue. One possibility is try to trigger a file change event, but I couldn’t find a way to that either.
Another issue is when we add the menu item into view/title it is also shown for other languages as well, I couldn’t find away to remove or disable it based on the active editor which is presented by outline.
Even finding a way to disable it, it will be shown for all languages. Therefore it seems to be better that showing inherited members comes from vscode it self so we have more control over the action/menus.
Another issue is when we add the menu item into view/title it is also shown for other languages as well
Will adding editorLangId == typescript
to the when clause works in this case?
But the 'refresh' blocks us anyway. What if we do not expose the shortcut at the navigation bar of the outline view? Instead, we just exposing a setting first.
Because when user is changing the setting's value, the user must switch between editors and the change of the editor will kick off a new document symbol request (if I remeber it correctly) and thus refresh the outline view?
Another issue is when we add the menu item into view/title it is also shown for other languages as well
Will adding
editorLangId == typescript
to the when clause works in this case?
No it doesn't work. Seems like editorLangId is not present I this view context.
But the 'refresh' blocks us anyway. What if we do not expose the shortcut at the navigation bar of the outline view? Instead, we just exposing a setting first.
Because when user is changing the setting's value, the user must switch between editors and the change of the editor will kick off a new document symbol request (if I remeber it correctly) and thus refresh the outline view?
I can try that out and see if it solves.
I tried the approach you mentioned @jdneo. We have few issues
- When opening the file the symbols are cached, so basically you need to close and open editor to send another request to LS to consider the preference when loading symbols or the file must change.
- The vscode outline UI always use the document uri to open the symbol. This is because it assume what is shown are only part of current document. So even we send SymbolInformation which has the support to send the URI it doesn't work when trying to select a symbol
Therefore I guess for now we can only have our own outline UI with our own LS extension since otherwise the document symbol quick picker will have symbols which cannot be navigated to.
WDYT ?
@gayanper, thank you for trying that approach!
I filed an issue at VS Code repo about the uri support for document symbol: https://github.com/microsoft/vscode/issues/157461
Therefore I guess for now we can only have our own outline UI with our own LS extension since otherwise the document symbol quick picker will have symbols which cannot be navigated to.
Yes, looks like in short term we have to forget about the integrated outline view 😥. The reference view in your initial commit might be an option.
@testforstephen @rgrunber What do you think? Should we go forward to use reference view to show the inherited members, or we wait for VS Code team's opinion a little bit then decide where will we go?
I want to give some inputs on how Eclipse shows inherited fields and members:
Eclipse
Outline View
Type Hierarchy (with "Show all inherited members" enabled)
Navigation from Type Hierarchy panel
Visual Studio Code
Outline and References: Class Hierarchy
Navigation from Class Hierarchy
The upstream request is in the stage of collecting upvotes now. For anyone want to have this capability, please vote (👍) at https://github.com/microsoft/vscode/issues/157461.
The change works pretty well for me. I would be fine with reviewing the 2 contributions (JDT-LS + vscode-java) to at least get this merged until we can use the outline view instead.
We could then also add some of the options available to the outline view. (eg. sort elements, exclude fields, static members, non-public members, etc.)
Overall though, it would be nice to expose the "extended members" from the symbol outline of the command palette This is the closest thing to ctrl+o
within Eclipse, and a faster way to navigate.
Hello, can we please have this merged? Thanks!
Looks like the API change for outline view won't happen in the near future, we can go with the reference view now. I'll review this PR recently.
@CsCherrYY @rgrunber @jdneo @testforstephen I would like to reiterate on this. I was looking into vscode quick outline and outline view are more build toward the document outline. Therefore my new suggestion is, we introduce outline hierarchy similar to call hierarchy or type hierarchy as a separate command. We can use the same reference view to start with.
WDYT ?
@gayanper I'm fine with that approach. It looks like the VS Code team will expose the required APIs for the outline view. We can go with the reference view first.
May this feature please be merged? :)