I started recently with golang development with vscode. I use the example code
accompanying a book as a starting point. This comes in chapters and I did some work with code from chapters 2 and 3. When I examine this source code in vscode and I hover over certain data types it gives me the definitions and allows me to select "type definitions" and it then opens the actual file that contains the type definition. Furthermore it leaves the files I have touched upon open as tabs in the editing pane.
However with chapter 4 code opened vscode behaves totally different. All hovering is gone and the editing pane only shows the current file and no history at all.
Why this difference in behaviour accross projects all with the same vscode installation?
Don’t understand this at all
Thanks Peter
2
Answers
Hi I found out the cause for difference in behaviour. I forgot to do a mod init (and tidy) in the chapter04 structure with the source code. After having done that (and solving a lot of package imports etc.) I get back the symbol definitions when I hover over the variables
All is well again.
I assume, you don’t have
go.mod
file on the chapter 4 code base. If that is the case than what you need to do is to rungo mod init {{your_package_name}}
and followed bygo mod tidy
.You can also refer to this documentation to learn more about modules in go.
https://go.dev/doc/tutorial/create-module
Hope it helps!