Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

IntelliJ IDEA Setup for Go

Glyn Normington edited this page Sep 23, 2015 · 28 revisions

To get decent support for Go in IntelliJ IDEA (on Mac OS X):

  1. Download IntelliJ IDEA 14.1 or later.
  2. Start IntelliJ.
  3. Install the latest alpha of the IntelliJ Go Plugin by following the instructions to add the alpha repository to IntelliJ and install version 0.9.300 or later of the plugin. After adding the repository, the plugin may not be visible in which case navigate to Preferences->Plugins->Browse repositories, select the alpha repository from the drop-down, and then install the plugin.
  4. To enable support for Linux-specific source code, edit /Applications/IntelliJ IDEA 14.1 CE.app/Contents/Info.plist (or equivalent for your version of IntelliJ) and add the following to the VMOptions setting:
    -Dgo.target.os=linux.
  5. To ensure optimal performance, edit /Applications/IntelliJ IDEA 14.1 CE.app/Contents/bin/idea.vmoptions (or equivalent for your version of IntelliJ) and change the maximum heap and permgen sizes as follows: Xmx2048m and XX:MaxPermSize=768m.
  6. Restart IntelliJ.
  7. It is recommended that you set the keymap to "Mac OS X 10.5+" (search for "Keymap" in Preferences).

goimports

  1. Install the IntelliJ File Watchers plugin.
  2. Configure a file watcher to run goimports whenever a file is saved:
    • Add a file watcher by navigating to Preferences->File Watchers and hit +.
    • Provide name Goimports, set the File Type to Go, add the full path of goimports as the Program, and set the Arguments to -w $FileDir$.
    • Click Apply and Ok.

ginkgo support

If you use ginkgo for testing, it's worth adding an "external tool" to be able to run ginkgo in IntelliJ:

  1. Under preferences, search for "External Tools".
  2. Add an external tool with name Ginkgo Watch, uncheck the Synchronize files after execution box, specify program ginkgo, parameters watch -race $FileDir$, and working directory $FileDir$.
  3. Optionally, check the Show console when standard out changes and/or Show console when standard error changes boxes, which will show the console pane whenever Ginkgo Watch runs.
  4. Click "Ok" and then "Apply".

When it is started the Ginkgo Watch tool will run ginkgo against a package once and thereafter continually monitor the package files and re-run its tests if anything changes.

To start Ginkgo Watch for a package: right-click on the package directory (or any of its files) in the Project hierarchy and select Externals Tools->Ginkgo Watch from the pop-up menu.

To stop Ginkgo Watch, click on the red "stop" box in its console pane. If you terminate IntelliJ before doing this, it will warn you that Ginkgo Watch is running before you can exit.

Key Features

Here are the key features for Go programmers. The keymap is assumed to be "Mac OS X 10.5+" (see above).

  • Runs goimports automatically each time a file is saved. (Note that, by default, IntelliJ saves files when it loses focus.)
  • cmd+b: Go to the definition of the identifier under the cursor.
  • cmd+[: go back
  • cmd+]: go forward
  • alt+F7: find usages of the identifier under the cursor.
  • cmd+shift+f: search all the files in the project. (You can also search a directory by right clicking on the direction from the project view and choosing "Find in Path...".)
  • shift+F6: rename the identifier under the cursor. (Press escape unless you want to overtype the whole identifier.)
  • cmd+7: View the structure of the current file which displays types, methods, and so forth. There is a button to sort the contents alphabetically which is useful for large files.
  • cmd+1: View the project files.
  • cmd+/: comment the current line (or the current selection).
  • cmd+d: duplicate the current line.
  • alt+shift+<cursor up>: move the current line up.
  • alt+shift+<cursor down>: move the current line down.
  • Live templates. E.g. type meth in a Go file and then choose the live template by hitting tab to insert a method. Other live templates can be found under preferences.

Clone this wiki locally