Skip to content

Latest commit

 

History

History
64 lines (42 loc) · 2.55 KB

1-editors-and-plugins.md

File metadata and controls

64 lines (42 loc) · 2.55 KB

Editors and plugins

Go has a very rich ecosystem and it is supported directly or via plugins on many editors. You can find a list of them on the Go wiki.

I have personally used:

For this workshop we will use Visual Studio Code (aka VSCode), so please install it now if you haven't yet and install the corresponding Go plugin. You can find instructions on how to do so here.

Once you install the Go plugin on VSCode it will install a bunch of tools, do not worry too much about them yet. By the end of this chapter you'll know what they all do and how they can help you write better code.

Go's philosophy for source code tools

Rather than having each editor reimplement the basic tools that all gophers use with their code, the Go community has produced small tools for each specific use case that are very simple to call from any editor.

This means that no matter what editor you use, you might be calling the same code to navigate from a function to its definition.

Those tools are mainly divided into three categories of tools:

  • those that modify your code, adding formatting or even modifying your code statements,
  • those that analyze your code and show warnings, and
  • those that help you navigating an existing code base.

Code completion

Code completion allows you to write code faster and avoid spelling mistakes. Many gophers love it, and it is provided for most editors with gocode.

You do not need to install it, as vscode-go will install it for you. Calling it directly is rare, instead your editor will call it.

Exercise: code completion

Open hello/main.go with VSCode, you should see this content:

package main

import "fmt"

func main() {
	fmt.Println("hello, gocode")
}

Move your cursor below the fmt.Println line and type fmt., you should see a list of all the identifiers defined in the fmt package.

Autocomplete in action via gocode

Congratulations

You have a now an editor running with a working Go plugin. Let's explore how all the tools that we just installed will make writing code much easier in the next section.