├── .gitignore ├── .no-sublime-package ├── Default (Linux).sublime-keymap ├── Default (Linux).sublime-mousemap ├── Default (OSX).sublime-keymap ├── Default (OSX).sublime-mousemap ├── Default (Windows).sublime-keymap ├── Default (Windows).sublime-mousemap ├── Godef.py ├── Godef.sublime-settings ├── LICENSE ├── Main.sublime-menu ├── README.md ├── messages.json └── messages └── install.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /.no-sublime-package: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/buaazp/Godef/a5ac2919ce4198f60748ca9624374e6315154ae2/.no-sublime-package -------------------------------------------------------------------------------- /Default (Linux).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { "keys": ["g","d"], "command": "godef" }, 3 | { "keys": ["g","h"], "command": "godef_prev" } 4 | ] 5 | -------------------------------------------------------------------------------- /Default (Linux).sublime-mousemap: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "button": "button1", 4 | "modifiers": ["ctrl", "alt"], 5 | "press_command": "drag_select", 6 | "command": "godef" 7 | } 8 | ] 9 | -------------------------------------------------------------------------------- /Default (OSX).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { "keys": ["g","d"], "command": "godef" }, 3 | { "keys": ["g","h"], "command": "godef_prev" } 4 | ] 5 | -------------------------------------------------------------------------------- /Default (OSX).sublime-mousemap: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "button": "button1", 4 | "modifiers": ["super", "alt"], 5 | "press_command": "drag_select", 6 | "command": "godef" 7 | } 8 | ] 9 | -------------------------------------------------------------------------------- /Default (Windows).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { "keys": ["g","d"], "command": "godef" }, 3 | { "keys": ["g","h"], "command": "godef_prev" } 4 | ] 5 | -------------------------------------------------------------------------------- /Default (Windows).sublime-mousemap: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "button": "button1", 4 | "modifiers": ["ctrl", "alt"], 5 | "press_command": "drag_select", 6 | "command": "godef" 7 | } 8 | ] 9 | -------------------------------------------------------------------------------- /Godef.py: -------------------------------------------------------------------------------- 1 | import sublime 2 | import sublime_plugin 3 | import subprocess 4 | import os 5 | import platform 6 | import sys 7 | import json 8 | from collections import deque 9 | 10 | 11 | def real_path(go_path): 12 | if go_path is None: 13 | return None 14 | return os.path.expanduser(os.path.expandvars(go_path)) 15 | 16 | 17 | class GodefCommand(sublime_plugin.WindowCommand): 18 | """ 19 | Godef command class 20 | use godef to find definition first, 21 | if not found, use guru to find again. 22 | """ 23 | 24 | def __init__(self, window): 25 | self.systype = platform.system() 26 | self.gopath = None 27 | self.goroot = None 28 | self.cmdpaths = [] 29 | self.env = None 30 | self.gosublime = {} 31 | self.read_gosublime(window) 32 | 33 | default_setting = sublime.load_settings("Preferences.sublime-settings") 34 | default_setting.set("default_line_ending", "unix") 35 | gopath = self._gopath() 36 | goroot = self._goroot() 37 | self.load(gopath, goroot, self.systype) 38 | self.gopath = gopath 39 | self.goroot = goroot 40 | if sys.version_info[0] == 2: 41 | super(GodefCommand, self).__init__(window) 42 | else: 43 | super().__init__(window) 44 | 45 | def load(self, gopath, goroot, systype): 46 | print("===============[Godef]Load Begin==============") 47 | # print("[Godef]DEBUG: system type: %s" % self.systype) 48 | if not gopath: 49 | print("[Godef]ERROR: no GOPATH defined") 50 | print("===============[Godef] Load End===============") 51 | return False 52 | 53 | if not goroot: 54 | print("[Godef]WARN: no GOROOT defined") 55 | 56 | cmdpaths = [] 57 | for cmd in ['godef', 'guru']: 58 | found = False 59 | if systype == "Windows": 60 | binary = cmd + ".exe" 61 | else: 62 | binary = cmd 63 | gopaths = gopath.split(os.pathsep) 64 | for go_path in gopaths: 65 | cmdpath = os.path.join(go_path, "bin", binary) 66 | if not os.path.isfile(cmdpath): 67 | print('[Godef]WARN: "%s" cmd not found at %s' % (cmd, go_path)) 68 | continue 69 | else: 70 | found = True 71 | break 72 | if not found: 73 | print('[Godef]WARN: "%s" cmd is not available.' % cmd) 74 | continue 75 | print('[Godef]INFO: found "%s" at %s' % (cmd, cmdpath)) 76 | cmdpaths.append({'mode': cmd, 'path': cmdpath}) 77 | 78 | if len(cmdpaths) == 0: 79 | print('[Godef]ERROR: godef/guru are not available.\n\ 80 | Make sure your gopath in settings is right.\n\ 81 | Use "go get -u github.com/rogpeppe/godef"\n\ 82 | and "go get -u golang.org/x/tools/cmd/guru"\n\ 83 | to install them.') 84 | print("===============[Godef] Load End===============") 85 | return False 86 | 87 | # a weird bug on windows. sometimes unicode strings end up in the 88 | # environment and subprocess.call does not like this, encode them 89 | # to latin1 and continue. 90 | env = os.environ.copy() 91 | if systype == "Windows": 92 | if sys.version_info[0] == 2: 93 | if gopath and isinstance(gopath, unicode): 94 | gopath = gopath.encode('iso-8859-1') 95 | if goroot and isinstance(goroot, unicode): 96 | goroot = goroot.encode('iso-8859-1') 97 | env["GOPATH"] = gopath 98 | if goroot: 99 | env["GOROOT"] = goroot 100 | 101 | self.cmdpaths = cmdpaths 102 | self.env = env 103 | print("===============[Godef] Load End===============") 104 | return True 105 | 106 | def run(self): 107 | default_setting = sublime.load_settings("Preferences.sublime-settings") 108 | default_setting.set("default_line_ending", "unix") 109 | settings = sublime.load_settings("Godef.sublime-settings") 110 | gopath = real_path(settings.get("gopath", os.getenv('GOPATH'))) 111 | goroot = real_path(settings.get("goroot", os.getenv('GOROOT'))) 112 | 113 | if self.gopath != gopath or self.goroot != goroot: 114 | print('[Godef]INFO: settings change, reload conf') 115 | self.gopath = gopath 116 | self.goroot = goroot 117 | self.cmdpaths = [] 118 | self.env = None 119 | if len(self.cmdpaths) != 2 and not self.load(gopath, goroot, self.systype): 120 | return 121 | 122 | print("=================[Godef]Begin=================") 123 | if len(self.cmdpaths) == 1: 124 | if self.cmdpaths[0]['mode'] != 'godef': 125 | print('[Godef]WARN: missing cmd "godef"') 126 | else: 127 | print('[Godef]WARN: missing cmd "guru"') 128 | if not self.goroot: 129 | print("[Godef]WARN: no GOROOT defined in settings") 130 | 131 | view = self.window.active_view() 132 | filename = view.file_name() 133 | select = view.sel()[0] 134 | select_begin = select.begin() 135 | select_before = sublime.Region(0, select_begin) 136 | string_before = view.substr(select_before) 137 | offset = len(string_before.encode('utf-8')) 138 | if view.line_endings() == 'Windows': 139 | offset += string_before.count('\n') 140 | 141 | print("[Godef]INFO: select_begin: %s offset: %s" % (select_begin, offset)) 142 | 143 | reset = False 144 | output = None 145 | succ = None 146 | for d in self.cmdpaths: 147 | if 'godef' == d['mode']: 148 | args = [d['path'], "-f", filename, "-o", str(offset)] 149 | else: 150 | args = [d['path'], "-json", 'definition', filename + ":#" + str(offset)] 151 | print("[Godef]INFO: spawning: %s" % " ".join(args)) 152 | 153 | startupinfo = None 154 | if os.name == 'nt': 155 | startupinfo = subprocess.STARTUPINFO() 156 | startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW 157 | stderr = None 158 | try: 159 | p = subprocess.Popen(args, stdout=subprocess.PIPE, 160 | stderr=subprocess.PIPE, env=self.env, 161 | startupinfo=startupinfo) 162 | output, stderr = p.communicate() 163 | except Exception as e: 164 | print("[Godef]EXPT: %s fail: %s" % (d['mode'], e)) 165 | print('[Godef]WARN: %s binary not existed, need reload conf' % d['mode']) 166 | reset = True 167 | continue 168 | if stderr: 169 | err = stderr.decode("utf-8").rstrip() 170 | print("[Godef]ERROR: %s fail: %s" % (d['mode'], err)) 171 | output = None 172 | continue 173 | elif len(output) < 3: 174 | position = output.decode("utf-8").rstrip() 175 | print("[Godef]ERROR: %s illegal output: %s" % (d['mode'], output)) 176 | continue 177 | else: 178 | succ = d 179 | break 180 | 181 | if reset: self.cmdpaths = [] 182 | 183 | if not output: 184 | print("[Godef]ERROR: all cmds failed") 185 | print("=================[Godef] End =================") 186 | return 187 | 188 | position = output.decode("utf-8").rstrip() 189 | print("[Godef]INFO: %s output:\n%s" % (succ['mode'], position)) 190 | if succ['mode'] == 'guru': 191 | definition = json.loads(position) 192 | if 'objpos' not in definition: 193 | print("[Godef]ERROR: guru result josn unmarshal err") 194 | else: 195 | position = definition['objpos'] 196 | print("[Godef]INFO: opening definition at %s" % position) 197 | self.window.open_file(position, sublime.ENCODED_POSITION) 198 | # record prev postion 199 | startrow, startcol = view.rowcol(select_begin) 200 | GodefPrevCommand.append(filename, startrow, startcol) 201 | print("=================[Godef] End =================") 202 | 203 | def read_gosublime(self, window): 204 | """ 205 | reads environment variables from gosublime. 206 | """ 207 | view = window.active_view() 208 | if view is not None: 209 | settings = view.settings() 210 | gosublime = settings.get("GoSublime", None) 211 | if gosublime and gosublime.get("env", None): 212 | env = gosublime.get("env") 213 | print("[Godef]INFO: found gosublime environment: {env}".format(env=env)) 214 | self.gosublime["gopath"] = env.get("GOPATH", "") 215 | self.gosublime["goroot"] = env.get("GOROOT", "") 216 | 217 | def _gopath(self): 218 | settings = sublime.load_settings("Godef.sublime-settings") 219 | gopath = real_path(settings.get("gopath", os.getenv('GOPATH'))) 220 | if gopath is None: 221 | return self.gosublime.get("gopath", "") 222 | return gopath 223 | 224 | def _goroot(self): 225 | settings = sublime.load_settings("Godef.sublime-settings") 226 | goroot = real_path(settings.get("goroot", os.getenv('GOROOT'))) 227 | if goroot is None: 228 | return self.gosublime.get("goroot", "") 229 | return goroot 230 | 231 | 232 | # GodefPrev Commands 233 | # code based on https://github.com/SublimeText/CTags/blob/development/ctagsplugin.py 234 | class GodefPrevCommand(sublime_plugin.WindowCommand): 235 | """ 236 | Provide ``godef_back`` command. 237 | 238 | Command "godef jump back" to the previous code point before a godef was navigated. 239 | 240 | This is functionality supported natively by ST3 but not by ST2. It is 241 | therefore included for legacy purposes. 242 | """ 243 | buf = deque(maxlen=100) # virtually a "ring buffer" 244 | 245 | def run(self): 246 | if not self.buf: 247 | print("[GodefPrev]ERROR: GodefPrev buffer empty") 248 | return 249 | 250 | filename, startrow, startcol = self.buf.pop() 251 | path = "{0}:{1}:{2}".format(filename, startrow +1, startcol + 1) 252 | self.window.open_file(path, sublime.ENCODED_POSITION) 253 | print("[GodefPrev]INFO: jump prev definition at %s" % path) 254 | 255 | @classmethod 256 | def append(cls, filename, startrow, startcol): 257 | """Append a code point to the list""" 258 | if filename: 259 | cls.buf.append((filename, startrow, startcol)) 260 | -------------------------------------------------------------------------------- /Godef.sublime-settings: -------------------------------------------------------------------------------- 1 | { 2 | // Copy this file to Settings - User 3 | // Set your real GOPATH in user's Godef.sublime-settings 4 | // For example: 5 | 6 | // "goroot": "/usr/local/opt/go/libexec", 7 | // "gopath": "/Users/zippo/develop/go", 8 | 9 | // Or if you use windows 10 | // "goroot": "C:\\Go", 11 | // "gopath": "C:\\gopath", 12 | } 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2015, 招牌疯子 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of Godef nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -------------------------------------------------------------------------------- /Main.sublime-menu: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "Preferences", 4 | "mnemonic": "n", 5 | "id": "preferences", 6 | "children": 7 | [ 8 | { 9 | "caption": "Package Settings", 10 | "mnemonic": "P", 11 | "id": "package-settings", 12 | "children": 13 | [ 14 | { 15 | "caption": "Godef", 16 | "children": 17 | [ 18 | { 19 | "command": "open_file", "args": 20 | { 21 | "file": "${packages}/Godef/Godef.sublime-settings" 22 | }, 23 | "caption": "Settings – Default" 24 | }, 25 | { 26 | "command": "open_file", "args": 27 | { 28 | "file": "${packages}/User/Godef.sublime-settings" 29 | }, 30 | "caption": "Settings – User" 31 | }, 32 | { "caption": "-" }, 33 | { 34 | "command": "open_file", 35 | "platform": "OSX", 36 | "args": { 37 | "file": "${packages}/Godef/Default (OSX).sublime-keymap" 38 | }, 39 | "caption": "Key Bindings – Default" 40 | }, 41 | { 42 | "command": "open_file", 43 | "platform": "Linux", 44 | "args": { 45 | "file": "${packages}/Godef/Default (Linux).sublime-keymap" 46 | }, 47 | "caption": "Key Bindings – Default" 48 | }, 49 | { 50 | "command": "open_file", 51 | "platform": "Windows", 52 | "args": { 53 | "file": "${packages}/Godef/Default (Windows).sublime-keymap" 54 | }, 55 | "caption": "Key Bindings – Default" 56 | }, 57 | { 58 | "command": "open_file", 59 | "platform": "OSX", 60 | "args": { 61 | "file": "${packages}/User/Default (OSX).sublime-keymap" 62 | }, 63 | "caption": "Key Bindings – User" 64 | }, 65 | { 66 | "command": "open_file", 67 | "platform": "Linux", 68 | "args": { 69 | "file": "${packages}/User/Default (Linux).sublime-keymap" 70 | }, 71 | "caption": "Key Bindings – User" 72 | }, 73 | { 74 | "command": "open_file", 75 | "platform": "Windows", 76 | "args": { 77 | "file": "${packages}/User/Default (Windows).sublime-keymap" 78 | }, 79 | "caption": "Key Bindings – User" 80 | }, 81 | { "caption": "-" }, 82 | { 83 | "command": "open_file", 84 | "platform": "OSX", 85 | "args": { 86 | "file": "${packages}/Godef/Default (OSX).sublime-mousemap" 87 | }, 88 | "caption": "Mouse Bindings – Default" 89 | }, 90 | { 91 | "command": "open_file", 92 | "platform": "Linux", 93 | "args": { 94 | "file": "${packages}/Godef/Default (Linux).sublime-mousemap" 95 | }, 96 | "caption": "Mouse Bindings – Default" 97 | }, 98 | { 99 | "command": "open_file", 100 | "platform": "Windows", 101 | "args": { 102 | "file": "${packages}/Godef/Default (Windows).sublime-mousemap" 103 | }, 104 | "caption": "Mouse Bindings – Default" 105 | }, 106 | { 107 | "command": "open_file", 108 | "platform": "OSX", 109 | "args": { 110 | "file": "${packages}/User/Default (OSX).sublime-mousemap" 111 | }, 112 | "caption": "Mouse Bindings – User" 113 | }, 114 | { 115 | "command": "open_file", 116 | "platform": "Linux", 117 | "args": { 118 | "file": "${packages}/User/Default (Linux).sublime-mousemap" 119 | }, 120 | "caption": "Mouse Bindings – User" 121 | }, 122 | { 123 | "command": "open_file", 124 | "platform": "Windows", 125 | "args": { 126 | "file": "${packages}/User/Default (Windows).sublime-mousemap" 127 | }, 128 | "caption": "Mouse Bindings – User" 129 | }, 130 | { "caption": "-" }, 131 | { 132 | "caption": "Read Me", 133 | "command": "open_file", 134 | "args": { 135 | "file": "${packages}/Godef/messages/install.txt" 136 | } 137 | } 138 | ] 139 | } 140 | ] 141 | } 142 | ] 143 | } 144 | ] 145 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Godef 2 | 3 | This Sublime Text 2/3 [golang](http://golang.org/) plugin adds a `godef` command which uses [godef](http://godoc.org/github.com/rogpeppe/godef) or [guru](http://godoc.org/golang.org/x/tools/cmd/guru) to find the definition under the cursor. 4 | 5 | #### Compatible with GoSublime 6 | 7 | You can use this plugin working with [GoSublime](https://github.com/DisposaBoy/GoSublime) because GoSublime is not support `godef/guru`. 8 | 9 | > This plugin support two different modes to find the definition of symbles: 10 | > 11 | > `godef` offers faster speed. But cannot find correct definition if the package name is not matched with import path: [rogpeppe/godef#40](https://github.com/rogpeppe/godef/issues/40) 12 | > 13 | > `guru` tool offers improved definition lookups which are compatible with Go 1.5+ vendoring. 14 | > 15 | > We use `godef` to find definition first, if it fails, try `guru` again. 16 | 17 | ## Installation 18 | 19 | The plugin assumes `godef/guru` is present at `$GOPATH/bin/`. You need install them first: 20 | 21 | ``` 22 | go get -v github.com/rogpeppe/godef 23 | go get -v golang.org/x/tools/cmd/guru 24 | ``` 25 | 26 | #### Sublime Package Control 27 | 28 | If you are using [Sublime Package Control](http://wbond.net/sublime_packages/package_control) you can simply install Sublime Godef by searching for `Godef` in the package listing. 29 | 30 | #### Manual Install 31 | 32 | Git clone this repository and place the entire `Godef` directory into your `Packages` directory. 33 | 34 | OSX: 35 | 36 | ``` 37 | # Install the plugin 38 | git clone git@github.com:buaazp/Godef.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/Godef 39 | ``` 40 | 41 | Linux: 42 | 43 | ``` 44 | # Install the plugin 45 | git clone git@github.com:buaazp/Godef.git ~/.config/sublime-text-3/Packages/Godef 46 | ``` 47 | 48 | Windows: 49 | 50 | Now windows is been supported. Thanks for [@decker502](https://github.com/decker502) and [@mattn](https://github.com/mattn)'s work. Please use the Sublime Package Control to install this plugin. 51 | 52 | ## Settings 53 | 54 | ### Configuring `GOPATH` and `GOROOT` 55 | 56 | 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`: 57 | 58 | ``` 59 | { 60 | "goroot": "/Users/zippo/Go", 61 | "gopath": "/Users/zippo/gopath" 62 | } 63 | 64 | // or if you use windows 65 | { 66 | "goroot": "C:\\Go", 67 | "gopath": "C:\\gopath" 68 | } 69 | ``` 70 | 71 | NOTE: The value of `gopath/goroot` should be absolute path. Multiple path like env `GOPATH` are supported but relative path are not: 72 | 73 | ``` 74 | GOOD: 75 | "gopath": "/opt/golang:/Users/zippo/develop/GO" 76 | 77 | BAD: 78 | "gopath": "~/develop/GO" 79 | "gopath": "$HOME/develop/GO" 80 | ``` 81 | 82 | This plugin will determine `GOPATH/GOROOT` from either: 83 | 84 | 1. The `gopath/goroot` value from `Godef.sublime-settings` 85 | 2. The `GOPATH/GOROOT` environment variable 86 | 87 | NOTE 2: In case your plugin can't resolve internals, add the installed library path to your gopath (notice the last part): 88 | 89 | ``` 90 | "gopath": "/opt/golang:/Users/zippo/develop/GO:/usr/lib/go" 91 | ``` 92 | 93 | ### Key Bindings 94 | 95 | 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. 96 | 97 | 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: 98 | 99 | ``` 100 | { "keys": ["super+h"], "command": "godef" } 101 | ``` 102 | 103 | 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: 104 | 105 | ``` 106 | { "keys": ["super+j"], "command": "jump_forward"}, 107 | { "keys": ["super+k"], "command": "jump_back"}, 108 | ``` 109 | These two command only available in ST3. 110 | 111 | Enjoy it! 112 | 113 | ## Godef doesn't work 114 | 115 | There are so many reasons lead to `godef` fails. If that happens, do these: 116 | 117 | 1. upgrade your plugin to the latest version. 118 | 2. press `ctrl + ~` to open the sublime console, then press godef shortcut key again. 119 | 3. logs in the console will show you the reason why `godef` is not work. 120 | 4. follow the logs and adjust your settings. 121 | 5. check if your `GOPATH/GOROOT` is right in settings. 122 | 6. open an issue and paste the logs in it. 123 | 124 | ## License 125 | 126 | Godef is under BSD license which is in the license file. 127 | 128 | 129 | -------------------------------------------------------------------------------- /messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "install": "messages/install.txt" 3 | } 4 | -------------------------------------------------------------------------------- /messages/install.txt: -------------------------------------------------------------------------------- 1 | _____ _____ _____ _____ _____ 2 | / ___| / _ \ | _ \ | ____| | ___| 3 | | | | | | | | | | | | |__ | |__ 4 | | | _ | | | | | | | | | __| | __| 5 | | |_| | | |_| | | |_| | | |___ | | 6 | \_____/ \_____/ |_____/ |_____| |_| 7 | 8 | Godef Plugin for Sublime Text 2/3 9 | https://github.com/buaazp/Godef 10 | 11 | ******************************************************************************** 12 | IMPORTANT: WE USE GURU IF GODEF FAILED, YOU NEED TO INSTALL THEM FIRST: 13 | 14 | go get -v github.com/rogpeppe/godef 15 | go get -v golang.org/x/tools/cmd/guru 16 | 17 | WINDOWS NOW IS SUPPORTED! 18 | 19 | THE DEFAULT KEYMAP OF GODEF HAS CHANGED TO gd BECAUSE SUPER+D IS MORE 20 | USEFUL FOR EXPANDING SELECTION!!! 21 | ******************************************************************************** 22 | 23 | There are so many reasons lead to GODEF fails. If that happens, do these: 24 | 25 | 1. upgrade your plugin to the latest version. 26 | 2. press `ctrl + ~` to open the console, then press godef shortcut key again. 27 | 3. logs in the console will show you the reason why `godef` is not work. 28 | 4. follow the logs and adjust your settings. 29 | 5. check if your `GOPATH/GOROOT` is right in settings. 30 | 6. open an issue and paste the logs in it. 31 | 32 | ******************************************************************************** 33 | 34 | The plugin assumes godef is present at $GOPATH/bin/godef. 35 | You need install godef first: 36 | 37 | go get -v github.com/rogpeppe/godef 38 | 39 | And then add gopath to the setting file before using this plugin. 40 | Here's an example Godef.sublime-settings: 41 | 42 | { 43 | "goroot": "/Users/zippo/Go", 44 | "gopath": "/Users/zippo/gopath" 45 | } 46 | 47 | // or if you use windows 48 | { 49 | "goroot": "C:\\Go", 50 | "gopath": "C:\\gopath" 51 | } 52 | 53 | NOTE: The value of gopath should be a absolute path. Multiple path like env 54 | GOPATH are supported: 55 | 56 | GOOD: 57 | "gopath": "/opt/golang:/Users/zippo/develop/GO" 58 | 59 | But relative path are not: 60 | 61 | BAD: 62 | "gopath": "~/develop/GO" 63 | "gopath": "$HOME/develop/GO" 64 | 65 | ******************************************************************************** 66 | 67 | The default key of Godef is gd, which is also the default key of godef plugin 68 | for vim. 69 | Or you can click left button while pressing super/ctrl+alt. 70 | You CAN of course change it by yourself. Here's an example key binding: 71 | 72 | { 73 | { "keys": ["super+h"], "command": "godef" } 74 | } 75 | 76 | You can also add these two key-binding into your keymap file to jump between the 77 | postions. Using j/k is because I use vim mode. Change them by yourself: 78 | 79 | { 80 | { "keys": ["super+j"], "command": "jump_forward"}, 81 | { "keys": ["super+k"], "command": "jump_back"}, 82 | } 83 | 84 | These two command only available in ST3. 85 | 86 | ******************************************************************************** 87 | --------------------------------------------------------------------------------