vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

Add support to view inherited members #2342

Open gayanper opened this issue 1 year ago • 14 comments

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]

gayanper avatar Jul 22 '22 13:07 gayanper

@rgrunber please have a look at the patch and let me know what you think ?

gayanper avatar Jul 22 '22 14:07 gayanper

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 avatar Jul 27 '22 07:07 jdneo

@jdneo You mean using the new ls extension method ?

gayanper avatar Jul 27 '22 16:07 gayanper

@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 avatar Jul 28 '22 01:07 jdneo

@jdneo ahhh i see, thats sounds neat. I can have a look at it this weekend.

gayanper avatar Jul 28 '22 05:07 gayanper

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 avatar Jul 28 '22 05:07 jdneo

@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.

gayanper avatar Jul 31 '22 11:07 gayanper

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?

jdneo avatar Aug 01 '22 01:08 jdneo

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.

gayanper avatar Aug 01 '22 18:08 gayanper

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 avatar Aug 06 '22 18:08 gayanper

@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?

jdneo avatar Aug 08 '22 01:08 jdneo

I want to give some inputs on how Eclipse shows inherited fields and members:

Eclipse

Outline View

image

Type Hierarchy (with "Show all inherited members" enabled)

image

Navigation from Type Hierarchy panel

image

Visual Studio Code

Outline and References: Class Hierarchy

image

Navigation from Class Hierarchy

image

manojbaishya avatar Aug 31 '22 10:08 manojbaishya

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.

jdneo avatar Sep 07 '22 06:09 jdneo

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.

rgrunber avatar Sep 08 '22 00:09 rgrunber

Hello, can we please have this merged? Thanks!

manojbaishya avatar Nov 20 '22 16:11 manojbaishya

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.

jdneo avatar Nov 22 '22 03:11 jdneo

@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 avatar Mar 26 '23 10:03 gayanper

@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.

jdneo avatar Mar 27 '23 01:03 jdneo

May this feature please be merged? :)

manojbaishya avatar May 04 '23 07:05 manojbaishya