Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode goto implementation, goto definition, goto type definition, difference

I noticed VSCode has the following

  • goto implemementation
  • goto definition
  • goto type definition

I'm a bit confused as to how these work, sometimes they even open up a peek definition. Can someone please provide a practical example on the usages of this. I found the following Difference between Goto Definition and Goto Implementation in Visual Studio but its lacking goto type definition.

like image 318
tmp dev Avatar asked Nov 19 '18 21:11

tmp dev


1 Answers

Well, go to type definition does exactly what it says.

VS Code documentation provides us all that info:

Go to Type Definition

Some languages also support jumping to the type definition of a symbol by running the Go to Type Definition command from either the editor context menu or the Command Palette. This will take you to the definition of the type of a symbol. The command editor.action.goToTypeDefinition is not bound to a keyboard shortcut by default but you can add your own custom keybinding.


Regarding your questions:

sometimes they even open up a peek definition

It shows peek definition popup window when it found more than one candidate, and leave to you choose where to jump.

I'm a bit confused as to how these work

These terms have meaning for some languages, such as C#, and full support of VS Code. In other languages, such as Ruby, despite having Interfaces, VS Code seems have no support for Go To Implementation for example. Then you have JavaScript, which does not have Interfaces, in this case Go To Implementation routes to Go To Definition.

Can someone please provide a practical example on the usages of this.

You already have Go To Implementation and Go To Definition, here it goes Go To Type Definition (since it's been a while I haven't coded this type of language, I may be wrong in some detail):

1: class Animal
2: end
3:
4: Animal dog = new Animal();

In line 4:

  • Go To Type Definition on symbol "dog" -> l1
  • Go To Definition on symbol "dog" -> l4
  • Go TO Definition on symbol "Animal" -> l1
like image 147
Andre Figueiredo Avatar answered Oct 19 '22 22:10

Andre Figueiredo