ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Godef

by buaazp ST2/ST3

Plugin of sublime to use godef to go to definitions accurately.

Labels go

Details

  • 2018.05.21.05.41.10
  • github.​com
  • github.​com
  • 2 months ago
  • 1 minute ago
  • 4 years ago

Installs

  • Total 7K
  • Win 2K
  • OS X 3K
  • Linux 1K
Jul 16 Jul 15 Jul 14 Jul 13 Jul 12 Jul 11 Jul 10 Jul 9 Jul 8 Jul 7 Jul 6 Jul 5 Jul 4 Jul 3 Jul 2 Jul 1 Jun 30 Jun 29 Jun 28 Jun 27 Jun 26 Jun 25 Jun 24 Jun 23 Jun 22 Jun 21 Jun 20 Jun 19 Jun 18 Jun 17 Jun 16 Jun 15 Jun 14 Jun 13 Jun 12 Jun 11 Jun 10 Jun 9 Jun 8 Jun 7 Jun 6 Jun 5 Jun 4 Jun 3 Jun 2 Jun 1
Windows 4 3 1 1 1 1 4 3 3 0 1 4 0 3 3 1 1 1 3 1 2 2 1 1 3 2 2 3 1 0 1 1 3 3 2 1 1 0 1 1 5 4 1 4 0 3
OS X 2 0 2 2 2 1 3 3 2 3 4 1 0 4 4 4 2 6 9 1 4 1 5 1 4 4 5 3 3 0 3 2 1 2 4 1 0 0 0 0 2 1 1 2 0 3
Linux 1 0 0 0 1 0 0 1 0 0 1 1 2 0 1 2 0 0 0 0 2 0 1 1 0 2 2 0 3 1 0 1 1 0 0 2 0 1 2 0 4 0 2 1 0 1

Readme

Source
raw.​githubusercontent.​com

Godef

This Sublime Text 2/3 golang plugin adds a godef command which uses godef or guru to find the definition under the cursor.

Compatible with GoSublime

You can use this plugin working with GoSublime because GoSublime is not support godef/guru.

This plugin support two different modes to find the definition of symbles:

godef offers faster speed. But cannot find correct definition if the package name is not matched with import path: rogpeppe/godef#40

guru tool offers improved definition lookups which are compatible with Go 1.5+ vendoring.

We use godef to find definition first, if it fails, try guru again.

Installation

The plugin assumes godef/guru is present at $GOPATH/bin/. You need install them first:

go get -v github.com/rogpeppe/godef
go get -v golang.org/x/tools/cmd/guru

Sublime Package Control

If you are using Sublime Package Control you can simply install Sublime Godef by searching for Godef in the package listing.

Manual Install

Git clone this repository and place the entire Godef directory into your Packages directory.

OSX:

# Install the plugin
git clone git@github.com:buaazp/Godef.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/Godef

Linux:

# Install the plugin
git clone git@github.com:buaazp/Godef.git ~/.config/sublime-text-3/Packages/Godef

Windows:

Now windows is been supported. Thanks for @decker502 and @mattn's work. Please use the Sublime Package Control to install this plugin.

Settings

Configuring GOPATH and GOROOT

In most cases, you needn't set anything after installing. But if your Godef don't work you need to add gopath and goroot into the setting file before using this plugin. Here's an example Godef.sublime-settings:

{
    "goroot": "/Users/zippo/Go",
    "gopath": "/Users/zippo/gopath"
}

// or if you use windows
{
    "goroot": "C:\\Go",
    "gopath": "C:\\gopath"
}

NOTE: The value of gopath/goroot should be absolute path. Multiple path like env GOPATH are supported but relative path are not:

GOOD:
"gopath": "/opt/golang:/Users/zippo/develop/GO"

BAD:
"gopath": "~/develop/GO"
"gopath": "$HOME/develop/GO"

This plugin will determine GOPATH/GOROOT from either:

  1. The gopath/goroot value from Godef.sublime-settings
  2. The GOPATH/GOROOT environment variable

NOTE 2: In case your plugin can't resolve internals, add the installed library path to your gopath (notice the last part):

"gopath": "/opt/golang:/Users/zippo/develop/GO:/usr/lib/go"

Key Bindings

The default key of Godef is gd, which is also the default key of godef plugin for vim. Don't be afraid. This key binding will NOT modify your codes. Just press it.

Or you can click left button while pressing super/ctrl+alt. You CAN of course change it by yourself. Here's an example key binding:

{ "keys": ["super+h"], "command": "godef" }

You can also add these two key-binding into your keymap file to jump between the postions. Using j/k is because I use vim mode. Change them by yourself:

{ "keys": ["super+j"], "command": "jump_forward"},
{ "keys": ["super+k"], "command": "jump_back"},

These two command only available in ST3.

Enjoy it!

Godef doesn't work

There are so many reasons lead to godef fails. If that happens, do these:

  1. upgrade your plugin to the latest version.
  2. press ctrl + ~ to open the sublime console, then press godef shortcut key again.
  3. logs in the console will show you the reason why godef is not work.
  4. follow the logs and adjust your settings.
  5. check if your GOPATH/GOROOT is right in settings.
  6. open an issue and paste the logs in it.

License

Godef is under BSD license which is in the license file.