It always takes me an hour to get gocode to work and usually it's random. It also tends to break at random as well.
Where does gocode look for $GOPATH?
Here are some of the things I've tried.. in my emacs:
in my .zshrc:
Is it using the one in .zshrc, or the one in .emacs, or neither?
I use http://emacsformacosx.com/, so I'm not sure where all the paths are coming from, it's extremely frustrating.
If I run this go env in my zsh terminal I get:
Is gocode suppose to run from the zsh terminal, or is the emacs plugin suppose to launch it for you? Are the paths different if you launch it your self?
Is there an easy way to debug what's happening under the covers instead of me hitting tab and nothing happening?
GOPATH is a just an env var. Unfortunatelly I'm not familiar at all with how MacOSX does things. I can only tell how things work on linux more or less.
On linux environment variables of all the parent processes are inherited to child processes by default, so if a process starts another process it gets its env vars. Using that concept it's possible to set variables in many places: logic shell init scripts (such as /etc/profile), ~/.xinitrc for graphical environment, interactive shell init scripts (such as ~/.zshrc or ~/.bashrc), etc.
Same goes for editors, if you start an editor from bash/zsh, it uses environment variables defined for that shell session. If you start an editor from graphical environment, it will use whatever environment variables are defined on the process responsible for it.
As for GOPATH specifically, I set it in
For further info you can read this debian's article, it describes everything nicely: https://wiki.debian.org/EnvironmentVariables
And here answers to your direct questions:
Normally gocode should be started by the plugin itself.
Gocode client passes all necessary environment variables on a per-request basis, so it doesn't matter under which environment gocode daemon was started.
You can run gocode in a so-called "debug mode" manually, it prints a lot of info on a per-request basis, you can do it that way in a separate terminal window:
Just google for how to set environment vars for programs in MacOSX, I'm sure you'll find your answer.
I hope it helps.
The way I fixed this was by installing https://github.com/purcell/exec-path-from-shell and removing any set paths from my .emacs file. The plugin makes sure to use the correct paths (the paths I set in .zshrc) even when launching from spotlight (which was the actual issue, it was inheriting the wrong paths when launching the .app)
I installed that from MELPA and everything seems to work again. Perhaps a recommendation in the README.md might help other people? I'm not sure if this is a common problem.. but I know a lot of people on OSX use http://emacsformacosx.com/ and would run into this exact issue if they launched from spotlight.
Also feel free to close this issue.
@nsf If you wouldn't mind, could you also add this under that suggestion section..
Add this to your .emacs if you use exec-path-from-shell:
People might forget to add (exec-path-from-shell-copy-env "GOPATH") which copies $GOPATH from your .bashrc, or .zshrc
Thanks so much, gocode -s -debug definitely nailed where the issue was coming from.
…heck I think it has to do with the PATH being incorrectly set for Emacs when it is started on MacOS X from the Launchbar. I therefore applied a workaround using the pkg "exec-path-from-shell" References: http://codewinds.com/blog/2015-04-02-emacs-flycheck-eslint-jsx.html nsf/gocode#261