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

Go to definition of Constructor

Open cgringmuth opened this issue 5 years ago • 4 comments

Hi, I was not able to find any documentation about this. Is it possible to jump to the constructor of a class? I tried several ways, F12 and Ctrl+Click on variable, on Classname (before variable), on parenthesis, inside of parenthesis. Nothing worked.

Everything else works quite well. I was just wondering if there is an option to jump to correct constructor of the class. Current workaround: Jump to definition of class and search for (correct if it has overloads) constructor.

cgringmuth avatar Oct 16 '20 11:10 cgringmuth

Go to definition on "foo" in "Foo * f = new foo(0);" should go to the foo constructor. We can use this issue to track adding some Go to Constuctor command for other cases where the constructor isn't explicitly invoked like a method.

sean-mcmanus avatar Oct 16 '20 18:10 sean-mcmanus

Go to definition on "foo" in "Foo * f = new foo(0);" should go to the foo constructor. We can use this issue to track adding some Go to Constuctor command for other cases where the constructor isn't explicitly invoked like a method.

Yes, this case works as you mentioned because the constructor is explicitly called. However for Foo f(0); it does not work. It could work, as cpp-tools already knows which function it can jump to. Hitting ctrl+shift+space in the parenthesis shows all possible declarations. It even selects the correct overload if list of variables are provided. image So, I don't see a reason Go to Definition to constructor is not working in this case. I would like to introduce this myself. However I don't have a clue where to start. So, I probably would need ages to implement it. But for experienced people it is probably easy to fix, as all the necessary information is already available.

Besides, hitting F12 on the variable definition does nothing in this case. In some cases it shows all references to the symbol which is a bit wired because then F12 has multiple meanings then. shift+F12 is the shortcut for showing all references.

cgringmuth avatar Oct 17 '20 11:10 cgringmuth

The code is in our closed source cpptools/cpptools-srv. I've filed a feature request on VS at https://developercommunity.visualstudio.com/idea/1226131/enable-cc-intellisense-go-to-definition-on-class-i.html -- there might be a shared implementation we could leverage. It's not a trivial thing to add. The ctrl+shift+space is invoking signature help.

sean-mcmanus avatar Oct 19 '20 21:10 sean-mcmanus

This feature request has received enough votes to be added to our backlog.

github-actions[bot] avatar Aug 07 '22 12:08 github-actions[bot]