techee / geany-lsp

LSP plugin for the Geany editor
GNU General Public License v2.0
11 stars 1 forks source link

Add Goto type declaration capability #14

Open elextr opened 9 months ago

elextr commented 9 months ago

This is a follow on from this.

Geany has goto declaration and goto definition but Vscode also has goto type definition as per this LSP message.

Use case:

In code Foo* something(); auto p = something(); p->foo the foo is red wriggly underlined and the hover says "No member named 'foo' in 'Foo'".

As discussed in the link above goto on foo will do nothing, its not visible here, lets see whats p (hovers) oh, its a Foo*, tries goto definition gets auto p bah!!! and same for goto declaration, but in Vscode goto type definition lands on class Foo where its obvious the member is goo not foo, woo hoo ;-P

In this simple example it would be possible to goto definition of p then goto definition of something() to find Foo which can goto declaration and get to class Foo. But thats a number of steps and it is only a simple sequence, it could easily get longer and the sequence would be blocked if something() return type was inferred or was a template parameter, then there would not be a Foo written down to follow.

techee commented 9 months ago

Done. I also implemented "go to implementations" (e.g. classes implementing a superclass/interface). There are keybindings for this, menu items under the LSP menu, and also entries in the context menu.

Ready for testing :-).

elextr commented 9 months ago

Thanks, will test.

elextr commented 9 months ago

Ok, goto type seems to work from limited testing. Find implementation seems to do nothing. I notice Vscode does not have that (at least for C++), maybe its something for other languages.

elextr commented 9 months ago

Hmmmm, ok "find implementation" provides a list of declarations of overrides of virtual functions, but the "implementation" is the definition, not the declaration.

What I found is Vscode "hides" this as part of "goto declaration" and "goto definition" so it knows which you want, and if there is only one answer it goes to it directly, else it provides an inset list as described here

techee commented 9 months ago

Hmmmm, ok "find implementation" provides a list of declarations of overrides of virtual functions, but the "implementation" is the definition, not the declaration.

Yes, it's those methods implementing an interface.

What I found is Vscode "hides" this as part of "goto declaration" and "goto definition" so it knows which you want, and if there is only one answer it goes to it directly, else it provides an inset list as described https://github.com/techee/geany-lsp/issues/21#issue-1989722527

Well, there is "Go to Implementations" in vscode which does just this. I decided to feed the results into the message window because in this case (and also in the case of references), there are typically more results and the whole thing behaves more like "find" than "goto". And then I found it a little strange that for one item it goes somewhere directly so in this case I display this single item instead of going to it immediately.

elextr commented 9 months ago

Yes, it's those methods implementing an interface.

My complaint is that clang is giving me the declarations of those implementations, not the definitions which actually do the implementing and I can't choose which I want to see. The Vscode Menu->Go->Go to implementations does not do anything here. Edit: with the cursor in the same position as generated the inset of #21