While testing #3547 I noticed that both goto declaration and goto definition showed only the cases of the function in the `.hpp` file (the declarations), and not the cases in the `.cpp` file (the definitions) although both were open and the functions in the `.cpp` file showed in its symbols.
Doing goto on "handle" the line in the `.hpp` shows:
```C++ namespace CLI { class Option_string : public Option { ... public: ... Err::Severity handle(string_view, string_view, size_t, const string&) override; ... }; } ```
Matching line in `.cpp` does not show for goto declaration or definition:
```C++ Err::Severity CLI::Option_string::handle(string_view o, string_view v, size_t, const string&){ ... } ```
I haven't tried or checked but from what I remember it behaves this way: 1. If you invoke it on a use of symbol (not its definition/declaration, in your case it would be some call of `handle()` in the code), it will jump to its definition. 2. If you invoke in on a definition of a symbol (in your case on the line with `handle` function definition in your cpp), it jumps to its declaration in hpp. 3. If you invoke in on a declaration of a symbol (in your case on the line with `handle` function declaration in your hpp), it jumps to its definition in cpp.
The logic is about this - (1) takes you to the definition which is probably what you want, by (2)/(3) you can quickly toggle between definition/declaration.
If there are multiple symbols found, it does the same, it just pops up a list with either definitions or declarations, depending on where you invoked it based on the 3 cases above. So I guess in your example you invoked it on the `handle` ``` Err::Severity CLI::Option_string::handle(string_view o, string_view v, size_t, const string&){ ``` in your cpp file so you got just the declarations.
(Or there's really some bug of course :-)
1.-3. what is "it"? There is goto declaration (ctrl-t), and goto definition (ctrl-shift-t).
My expectation would be if I say "goto definition" that it will show definitions in the popup list, and if I say "goto declaration" it will show declarations. It should not try to be smart, it isn't. If I have a call selected and say I want to see the implementation (the definition) why does it go to the declaration, even when I select goto definition? If I pick the wrong definition from the list and say "goto definition" to select another, why does it only show me declarations, thats daft, it presumes Geany knows better than the user.
So I guess in your example you invoked it on the handle in your cpp file so you got just the declarations.
I invoked both goto declaration and goto definition in both .hpp and .cpp, always got .hpp in the list. I tried to be thorough and try all combinations of "goto declaration" and "goto definition" and `.hpp` and `.cpp` files (I did not try calls since I didn't have that file open).
(Or there's really some bug of course :-)
I suspect there is two things:
- some daft design/implementation of the feature that ignores what the user tells it to do, and - because I never saw the .cpp symbols in the list, no matter where I invoked it or which action I invoked, I suspect there is also a bug.
This can wait until after release when I will try to gist a minimal failing example for thorough analysis.
There is also ctrl+click on the symbol. This is the way what I mostly "it" and works like @techee describes
I invoked both goto declaration and goto definition in both .hpp and .cpp, always got .hpp in the list.
But you invoked it on the line where the symbol was defined already, so it swapped to the other search. If you invoked it on the _call_ of that function, it would behave the way you expected.
This behavior isn't anything new and dates back to https://github.com/geany/geany/commit/c61a189c00fca689f6f047c7d9c108a807aa14...
The current "source of the problem" looks this way:
https://github.com/geany/geany/blob/c46ffb0dcdf50760b362c076922bdc747be24937...
I kind of like how it behaves as when you already are on the definition, you don't really need to get to the definition again but rather to the declaration. And as @kugel-, I also use the Ctrl+click version of this feature.
But you invoked it on __the line__ where the symbol was defined already, so it swapped to the other search. If you invoked it on the call of that function, it would behave the way you expected. [my highlighting]
The behaviour and your discussion is predicated on there being __one__ declaration and __one__ definition, "... the line ...". But its not "the" line it is several lines, for both declaration and definition. This is common in C++ and as @kugel- noted in another issue, its possible even in C when he had several versions of the same file open.
And as @kugel-, I also use the Ctrl+click version of this feature.
The described behaviour is appropriate for ctrl+click where the user is not specifying which they want to see, then the sequence:
``` `call`->`declarations`->`definitions`-| ^__________________| ``` does make some sense. But not for ctrl+t or ctrl+shift+t which specify goto declaration or goto definition.
This behavior isn't anything new and dates back to https://github.com/geany/geany/commit/c61a189c00fca689f6f047c7d9c108a807aa14...
Yeah, I wasn't intending to say it was part of #3547 just that was when I noticed it.
I kind of like how it behaves as when you already are on the definition, you don't really need to get to the definition again but rather to the declaration.
There is that "the" again :-)
If there are several definitions, and I am on "the wrong" one when I type ctrl+shift+t I want the list of definitions so I can select "the right" one, not to have to cycle to the declarations then back to definitions.
Essentially the problem is with ctrl+t and ctrl+shift+t doing the same as ctrl+click does, there is no point in having three actions all doing the same thing. If an action is titled "goto declaration" thats all it should do, even if its on a declaration, and similarly the action titled "goto definition" should do that only, even if its on a definition or a call.
Well, there is - goto definition - goto declaration - ctrl+click
I'm slightly worried that users already got used to "goto definition" keybinding to behave like ctrl+click and if we modify it now, it will break user's expectations. We could introduce - goto definition/declaration keybinding
behaving like ctrl+click but that will probably have to be assigned a different default keybinding so users will have to learn something new again. I'm not really sure how to solve this and if we should do something about it.
there is no point in having three actions all doing the same thing.
But one is mouse-oriented and the other keyboard-oriented. And only two do the same thing: - ctrl+click does the same thing as goto definition (going to definition unless on definition already, then to declaration + the popup stuff for multiple results) - goto declaration (going to declaration unless on declaration already, then to definition + the popup stuff for multiple results)
I'm slightly worried that users already got used to "goto definition" keybinding to behave like ctrl+click and if we modify it now, it will break user's expectations.
Or they will be delighted that it finally provides the declarations list as the name says. Also as the original post said it never seemed to provide the definitions list, so exactly what the users have gotten used to is questionable.
Anyway yes if you want to you could introduce an extra configurable keybinding that does the same as ctrl+click (note subtle change from "we" ;-)
But wait until after release and I get time to make a test file to see if my impressions of missing definitions are right.
Then we can have a bikeshed about which keybindings to use and fix any bugs.
We could introduce the new action and map to ctrl+t, and "go to definition" becomes unbound. If "go to declaration" is essentially the same thing (as of now, until it's fixed) then unbind it too.
If I explicitly use "go to definition" when I'm on a definition, then I probably don't want to go to the declaration but rather see the list of other definitions. Likewise with "go to declaration". This is currently impossible if IIUC?
Also as the original post said it never seemed to provide the definitions list, so exactly what the users have gotten used to is questionable.
Once again, it _does_ provide definitions list. We are only talking about the special case where you are on the definition already and it swaps to the other search.
We could introduce the new action and map to ctrl+t, and "go to definition" becomes unbound. If "go to declaration" is essentially the same thing (as of now, until it's fixed) then unbind it too.
I'm fine with that.
github-comments@lists.geany.org