DisposaBoy / GoSublime

A Golang plugin collection for SublimeText 3, providing code completion and other IDE-like features.
MIT License
3.42k stars 300 forks source link

Auto gofmt on completion not working with custom GOROOT #523

Closed btracey closed 10 years ago

btracey commented 10 years ago

Gofmt on save no longer works, and I believe this happened when I moved GOROOT away from /usr/local. I saw on a different issue that there can be problems with multiple go installations, so I deleted the old one. I tried reinstalling GoSublime, changing only the "env" variable. Goimports is not working either, so I'm guessing it's something with the save integration. There are no MarGo warnings on startup (which do occur if I have an incorrect GOROOT variable). I'm not sure what else to try. Thanks.

In GoSublime.sublime-settings - GoSublime "env": { "GOROOT": "/Users/brendan/go_1_2/go", "GOPATH": "/Users/brendan/Documents/mygo" }, "fmt_enabled": true,

The entire contents of the user settings are { "fmt_cmd": ["goimports"] }

Go environment variables: brendan:~/Documents/mygo/src$ go env GOARCH="amd64" GOBIN="" GOCHAR="6" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin" GOPATH="/Users/brendan/Documents/mygo" GORACE="" GOROOT="/Users/brendan/go_1_2/go" GOTOOLDIR="/Users/brendan/go_1_2/go/pkg/tool/darwin_amd64" TERM="dumb" CC="clang" GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fno-common" CXX="clang++" CGO_ENABLED="1"

DisposaBoy commented 10 years ago

Are there errors in the Sublime console? ignoring the goimports case for a moment, the fmt will/can only fail if the file has syntax errors in there. That go env output isn't reliable. You can see what the env vars actually are from 9o, super+9 and then type env . To see the settings type settings in 9o

btracey commented 10 years ago

Thanks for your reply. The problem was that there were errors in goimports that was causing fmt to not run. I have included my settings below in case it is a bug that goimports would stop fmt from running.

You may want to add a "troubleshooting" section to the readme which says what you posted above. (Check that GOROOT and GOPATH are correct by looking at 9o, check that there are no errors in the Sublime console, whatever else are the common problems). For those of us who are not skilled at using Sublime, those steps are not obvious.

Thanks for your excellent work on the project.

Console output: GoSublime cannot fmt file. error: `exec: "goimports": executable file not found in $PATH'

env from 9o [ env | done ] Default Settings file: gs.packages://GoSublime/GoSublime.sublime-settings (do not edit this file) User settings file: gs.packages://User/GoSublime.sublime-settings (add/change your settings here) { "Apple_PubSub_Socket_Render": "/tmp/launch-OVuQNQ/Render", "DISPLAY": "/tmp/launch-SUpdeA/org.macosforge.xquartz:0", "GOPATH": "/Users/brendan/Documents/mygo", "GOROOT": "/Users/brendan/go_1_2/go", "GS_GOPATH": "", "HOME": "/Users/brendan", "LOGNAME": "brendan", "PATH": "/Users/brendan/Library/Application Support/Sublime Text 3/Packages/User/GoSublime/osx-x64/r13.12.26-3_go1.2.1/bin:/Users/brendan/go_1_2/go/bin:/Users/brendan/Documents/mygo/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/brendan/bin:/Users/brendan/go/bin:/usr/local/go/bin:/usr/local/opt/go/bin:/usr/local/bin", "PWD": "/Users/brendan/Documents/mygo/src/github.com/btracey/ransuq/synthetic", "SHELL": "/bin/bash", "SSH_AUTH_SOCK": "/tmp/launch-g6WMpm/Listeners", "TMPDIR": "/var/folders/s0/2lsmv0jd7x37kkxmc_q6wyj80000gn/T/", "USER": "brendan", "__CF_USER_TEXT_ENCODING": "0x1F5:0:0", "__CHECKFIX1436934": "1", "_fn": "/Users/brendan/Library/Application Support/Sublime Text 3/Packages/GoSublime/GoSublime.sublime-settings", "_nm": "GoSublime.sublime-settings", "_vfn": "", "_wd": "/Users/brendan/Documents/mygo/src/github.com/btracey/ransuq/synthetic" }

Settings from 9o: Default Settings file: gs.packages://GoSublime/GoSublime.sublime-settings (do not edit this file) User settings file: gs.packages://User/GoSublime.sublime-settings (add/change your settings here) { "9o_aliases": {}, "9o_color_scheme": "default", "9o_instance": "", "9o_settings": {}, "9o_show_end": false, "_debug": false, "autocomplete_builtins": false, "autocomplete_closures": false, "autocomplete_filter_name": "", "autocomplete_snippets": true, "autocomplete_suggest_imports": false, "autocomplete_tests": false, "autoinst": true, "autosave": true, "build_command": [ "^1" ], "calltips": true, "comp_lint_commands": [ { "cmd": [ "go", "install" ] } ], "comp_lint_enabled": false, "complete_builtins": false, "default_snippets": [ { "match": { "global": false, "pkgname": "" }, "snippets": [ { "text": "package ${default_pkgname}", "title": "", "value": "package ${default_pkgname}\n\n$1\n" } ] }, { "match": { "global": true, "pkgname": "^main$" }, "snippets": [ { "text": "func main", "title": "func main {...}", "value": "func main() {\n\t$0\n}\n" } ] }, { "match": { "global": true, "pkgname": "." }, "snippets": [ { "text": "import", "title": "import (...)", "value": "import (\n\t\"$1\"\n)" }, { "text": "func", "title": "func {...}", "value": "func ${1:name}($2)$3 {\n\t$0\n}" }, { "text": "var", "title": "var (...)", "value": "var (\n\t$1\n)" }, { "text": "const", "title": "const (...)", "value": "const (\n\t$1\n)" }, { "text": "init", "title": "func init()", "value": "func init() {\n\t$1\n}" }, { "text": "func http handler", "title": "func(rw, req)", "value": "func ${1:name}(rw http.ResponseWriter, req _http.Request) {\n\t$0\n}" } ] }, { "match": { "global": true, "hastypes": true, "pkgname": "." }, "snippets": [ { "text": "func (${typename})", "title": "func (...) {...}", "value": "func (${1:${typename_abbr}} ${2:*}${typename}) ${3:name}($4)$5 {\n\t$0\n}" } ] }, { "match": { "local": true }, "snippets": [ { "text": "func", "title": "func{...}()", "value": "func($1) {\n\t$0\n}($2)" }, { "text": "var", "title": "var [name] [type]", "value": "var ${1:name} ${2:type}" } ] } ], "env": { "GOPATH": "/Users/brendan/Documents/mygo", "GOROOT": "/Users/brendan/go_1_2/go" }, "fmt_cmd": [ "goimports" ], "fmt_enabled": true, "fmt_tab_indent": true, "fmt_tab_width": 8, "fn_excludeprefixes": [ ".", "" ], "gohtml_extensions": [ ".html.go" ], "gscomplete_enabled": true, "gslint_enabled": true, "gslint_timeout": 100, "installsuffix": "", "ipc_timeout": 1, "lint_enbled": true, "lint_filter": [ "gs.flag.parse", "gs.types" ], "linters": [], "margo_oom": 1000, "on_save": [], "shell": [], "snippets": [], "use_gs_gopath": false, "use_named_imports": false }

DisposaBoy commented 10 years ago

The docs will be improved, when they are updated. What was the goimports issue. I just checked an if the fmd_cmd fails to execute, the failure message is printed to the console so if it wasn't there feel free to re-open this

davmaz commented 8 years ago

I'm having a crazy issue. I have 2 SublimeText3 windows open. One of them correctly executes goimports when saving a file. The other show this in the log:

\ 2016-01-28 16:58:03.882521 **: GoSublime

cannot fmt file. error: `Blocking Call(sh): Timeout'

davmaz commented 8 years ago

NEVERMIND! Sorry. If I have any syntax errors in the file, goimports won't get called. It's strange: to test if goimports is 'working' I just delete one of the imports -- that would give the error. Now it doesn't.