gocode icon indicating copy to clipboard operation
gocode copied to clipboard

gocode.exe not working on Windows 10

Open shadyyx opened this issue 8 years ago • 20 comments

Hi.

I am developing in go under Ubuntu but at home I wanted to give it a try on my home Windows machine. It seems everything is working properly except gocode.exe - running any of gocode.exe set, gocode.exe set autobild, ``gocode.exe set autobild true` nor the autocompletion for go work (no output at all for commands in console nor in console running as administrator). I tried running them in cmd.exe as well as in PowerShell (and PowerShell Administrator ISE) - no luck getting any output nor autocompletion (in Atom) to work.

Windows 10, 64 bit, Go 1.7 (after running go version in cmd got this output go version go1.7 windows/amd64).

One weird thing I have just now experienced:

  • I navigated to c:\gowork\github.com\nsf\gocode
  • I ran go build and go install
  • then after running gocode set I finally got some output
  • then I cd c:\gowork\ and gocode set is again not working... WTF?!

shadyyx avatar Sep 04 '16 13:09 shadyyx

Is C:\gowork\bin in your PATH environment variable?

nsf avatar Sep 04 '16 15:09 nsf

Of course it is. Running PATH in cmd returns me my PATH with c:\gowork\bin included.

shadyyx avatar Sep 05 '16 05:09 shadyyx

I don't know here, hard to tell what's going on.

nsf avatar Sep 17 '16 16:09 nsf

@nsf Same issue for me, Win 10 64 bit, Go 1.7.1. I can get auto completion to work occasionally but the performance is unreliable. No log with any gocode commands and have everything correct in my path.

SonarBeserk avatar Sep 24 '16 20:09 SonarBeserk

I'll try it on windows 10 tomorrow.

nsf avatar Sep 24 '16 20:09 nsf

Installed Go 1.7.1 on my windows 10 machine (official Go installer), it added GOROOT env var and modified PATH env var.

Installed Git 2.1.0 (official installer), asked it to expose itself on PATH.

Added GOPATH env var pointing to C:\waytogo.

go get github.com/nsf/gocode
go get github.com/nsf/godit

Tried editing files in godit, autocompletion works perfectly, haven't noticed any lags.

Could you guys try editing stuff in godit? It's a simple emacs-like text editor written by me, it works on windows just fine. Just open some random Go file in it (godit file.go), make sure it's saved on disk (otherwise gocode won't be triggered), and use Ctrl-x Ctrl-a for autocompletion. Ctrl-x Ctrl-c for exit.

If it works well in godit, then text editors are to blame. Godit can be seen as a reference gocode integration.

nsf avatar Sep 25 '16 12:09 nsf

Oh, just wanted to add. My windows 10 has automatic updates disabled, hence its state may not match yours. So, there is a chance that some windows 10 update breaks things, but it seems unlikely.

nsf avatar Sep 25 '16 12:09 nsf

I will try goedit later today if I have time. @shadyyx Removing a factor hopefully, don't have avast slowing down your gocode do you?

SonarBeserk avatar Sep 26 '16 12:09 SonarBeserk

It works fine here on Windows 10 (using it with VSCode) but the performance is atrocious (a few seconds for code completion). Running gocode in debug mode I noticed that all packages are rebuilt every single time a request comes in o_O This is something I noticed with go build if you don't use -i. @nsf any clues on what might be happening?

mattetti avatar Jan 04 '17 22:01 mattetti

Gocode's "autobuild" feature is experimental and have never been tested properly. Maybe for some reason it fails on windows. Unless vscode forces it on, I recommend disabling it.

nsf avatar Jan 04 '17 22:01 nsf

@nsf VSCode doesn't do anything special, it starts the process and exposes it on a TCP socket, then spawns a new process to ask for auto completion of the file at a specific cursor position.

How can I try to disable that feature to see if it helps?

mattetti avatar Jan 04 '17 22:01 mattetti

Well, in this case autobuild should be disabled by default. You need to find the gocode binary and exec it via cmd.exe or something. gocode set will print the gocode config. There make sure autobuild is set to false. If it is, then it's not gocode who's building stuff. Also keep in mind that third party plugins may invoke third party tools and who knows maybe it's not gocode's fault.

nsf avatar Jan 04 '17 22:01 nsf

gocode.exe set
propose-builtins true
lib-path ""
custom-pkg-prefix ""
custom-vendor-dir ""
autobuild true
force-debug-output ""
package-lookup-mode "go"
close-timeout 1800
unimported-packages false

Autobuild is set to true o_O This is how I started gocode: gocode.exe -s -sock tcp -addr 127.0.0.1:37373 VSCode spawns a process and send a command similar to gocode.exe -f=json autocomplete "c:\Users\Matt\Go\src\github.com\pkg\my_file.go" c4706

mattetti avatar Jan 04 '17 22:01 mattetti

Vscode plugin might invoke "set" command and set it to true. Find a way to force it to false. Plugin should be open source. gocode set autobuild false will set it to false, I don't remember where gocode's config is on windows. Somewhere in there: https://github.com/nsf/gocode/blob/master/os_windows.go#L40-L48

nsf avatar Jan 04 '17 22:01 nsf

I did find out that the VSCode Go extension does have a flag to autobuild:

let gocode = getBinPath('gocode');
			let autobuild = vscode.workspace.getConfiguration('go')['gocodeAutoBuild'];
			cp.execFile(gocode, ['set', 'propose-builtins', 'true'], {}, (err, stdout, stderr) => {
				cp.execFile(gocode, ['set', 'autobuild', autobuild], {}, (err, stdout, stderr) => {
					resolve();
				});
			});

I'll turn that off this way (in the config) and confirm that it fast again. Funny enough this feature works well on Mac but I'll investigate that separately.

mattetti avatar Jan 04 '17 22:01 mattetti

I think the feature invokes the go tool. So if you have some unconventional setup or something it might fail. Also I believe go tool uses modification timestamps to rebuild out of date things. Not sure how well it would work on windows. On linux and mac it's solid because timestamps were used by "make" for ages.

nsf avatar Jan 04 '17 22:01 nsf

I can confirm that when turning off this feature it is fast again. The VSCode Go extension have that feature turned on by default, probably because most extension developers are on unix systems. I'll look at what gocode/go tool does to determine if the packages should be rebuilt. I've only recently started developing on Windows from time to time and I did notice that go build recompiles everything if I don't use the -i flag. So there might be a simple workaround.

Thanks again for gocode, it's a very convenient tool I rely on daily :)

mattetti avatar Jan 04 '17 22:01 mattetti

go build should not be used most of the time. Gocode's autobuild feature runs go install. go build is useless because it's a blank build, it does nothing. go install builds and saves binaries.

Code for reference: https://github.com/nsf/gocode/blob/master/declcache.go#L189-L252

It's a very simple feature.

nsf avatar Jan 04 '17 22:01 nsf

perfect, I'll investigate and see what's causing the issue under Windows.

mattetti avatar Jan 04 '17 22:01 mattetti

After further investigation... I have no idea what was wrong. I removed the executable, added some debug statements, rebuilt it and copied it (for some reason go install wasn't moving the file properly). After that, autobuild worked as expected on Windows 10, VSCode, autobuild on, Go 1.8. I can only assume something was wrong with my system and my coworkers.

mattetti avatar Jan 10 '17 07:01 mattetti