Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gocode only works when run manually #389

Closed
ns-cweber opened this issue Sep 26, 2016 · 20 comments
Closed

gocode only works when run manually #389

ns-cweber opened this issue Sep 26, 2016 · 20 comments

Comments

@ns-cweber
Copy link

ns-cweber commented Sep 26, 2016

Hi, I hope this isn't a duplicate; I read through a bunch of the existing issues, tried searching, and generally did my due diligence before reporting. Apologies if I missed something. I'm not getting any completions from the default gocode server. When I close the server and run gocode -s, completions work fine. Without running gocode -s, the log output looks like this:

2016/09/26 11:03:52 Go project path: .
2016/09/26 11:03:52 Got autocompletion request for '/private/tmp/main.go'
2016/09/26 11:03:52 Cursor at: 52
2016/09/26 11:03:52 -------------------------------------------------------
package main

import (
        "fmt"
)

func main() {
        fmt.#Println
}
2016/09/26 11:03:52 -------------------------------------------------------
2016/09/26 11:03:52 Found "fmt" at "/Users/cweber/.gvm/gos/go1.7.1/pkg/darwin_amd64/fmt.a"
2016/09/26 11:03:52 Error parsing input file (inner block):
2016/09/26 11:03:52  4:6: expected selector or type assertion, found ';'
2016/09/26 11:03:52  4:7: expected ';', found 'IDENT' Println
2016/09/26 11:03:52  5:2: expected ';', found 'EOF'
2016/09/26 11:03:52  5:2: expected '}', found 'EOF'

With gocode -s, I see:

2016/09/26 11:09:26 Go project path: .
2016/09/26 11:09:26 Got autocompletion request for '/private/tmp/main.go'
2016/09/26 11:09:26 Cursor at: 52
2016/09/26 11:09:26 -------------------------------------------------------
package main

import (
        "fmt"
)

func main() {
        fmt.#
}
2016/09/26 11:09:26 -------------------------------------------------------
2016/09/26 11:09:26 Found "fmt" at "/Users/cweber/.gvm/gos/go1.7.1/pkg/darwin_amd64/fmt.a"
2016/09/26 11:09:26 Error parsing input file (inner block):
2016/09/26 11:09:26  4:6: expected selector or type assertion, found ';'
2016/09/26 11:09:26 extracted expression tokens: fmt
2016/09/26 11:09:26 Offset: 0
2016/09/26 11:09:26 Number of candidates found: 25
2016/09/26 11:09:26 Candidates are:
2016/09/26 11:09:26   func Errorf(format string, a ...interface{}) error
2016/09/26 11:09:26   func Fprint(w !io!io.Writer, a ...interface{}) (n int, err error)
2016/09/26 11:09:26   func Fprintf(w !io!io.Writer, format string, a ...interface{}) (n int, err error)
2016/09/26 11:09:26   func Fprintln(w !io!io.Writer, a ...interface{}) (n int, err error)
2016/09/26 11:09:26   func Fscan(r !io!io.Reader, a ...interface{}) (n int, err error)
2016/09/26 11:09:26   func Fscanf(r !io!io.Reader, format string, a ...interface{}) (n int, err error)
2016/09/26 11:09:26   func Fscanln(r !io!io.Reader, a ...interface{}) (n int, err error)
2016/09/26 11:09:26   func Print(a ...interface{}) (n int, err error)
2016/09/26 11:09:26   func Printf(format string, a ...interface{}) (n int, err error)
2016/09/26 11:09:26   func Println(a ...interface{}) (n int, err error)
2016/09/26 11:09:26   func Scan(a ...interface{}) (n int, err error)
2016/09/26 11:09:26   func Scanf(format string, a ...interface{}) (n int, err error)
2016/09/26 11:09:26   func Scanln(a ...interface{}) (n int, err error)
2016/09/26 11:09:26   func Sprint(a ...interface{}) string
2016/09/26 11:09:26   func Sprintf(format string, a ...interface{}) string
2016/09/26 11:09:26   func Sprintln(a ...interface{}) string
2016/09/26 11:09:26   func Sscan(str string, a ...interface{}) (n int, err error)
2016/09/26 11:09:26   func Sscanf(str string, format string, a ...interface{}) (n int, err error)
2016/09/26 11:09:26   func Sscanln(str string, a ...interface{}) (n int, err error)
2016/09/26 11:09:26   type Formatter interface
2016/09/26 11:09:26   type GoStringer interface
2016/09/26 11:09:26   type ScanState interface
2016/09/26 11:09:26   type Scanner interface
2016/09/26 11:09:26   type State interface
2016/09/26 11:09:26   type Stringer interface
2016/09/26 11:09:26 =======================================================

Here's the output from nvim --version:

NVIM 0.1.3
Build type: RelWithDebInfo
Compilation: /usr/local/Library/ENV/4.3/clang -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DDISABLE_LOG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -DHAVE_CONFIG_H -I/tmp/neovim-20160707-73611-1gf4v6g/neovim-0.1.3/build/config -I/tmp/neovim-20160707-73611-1gf4v6g/neovim-0.1.3/src -I/tmp/neovim-20160707-73611-1gf4v6g/neovim-0.1.3/deps-build/usr/include -I/tmp/neovim-20160707-73611-1gf4v6g/neovim-0.1.3/deps-build/usr/include -I/tmp/neovim-20160707-73611-1gf4v6g/neovim-0.1.3/deps-build/usr/include/luajit-2.0 -I/tmp/neovim-20160707-73611-1gf4v6g/neovim-0.1.3/deps-build/usr/include -I/tmp/neovim-20160707-73611-1gf4v6g/neovim-0.1.3/deps-build/usr/include -I/tmp/neovim-20160707-73611-1gf4v6g/neovim-0.1.3/deps-build/usr/include -I/tmp/neovim-20160707-73611-1gf4v6g/neovim-0.1.3/deps-build/usr/include -I/usr/local/opt/gettext/include -I/usr/include -I/usr/include -I/tmp/neovim-20160707-73611-1gf4v6g/neovim-0.1.3/build/src/nvim/auto -I/tmp/neovim-20160707-73611-1gf4v6g/neovim-0.1.3/build/include
Compiled by cweber@MBP

Optional features included (+) or not (-): +acl   +iconv    +jemalloc
For differences from Vim, see :help vim-differences

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/0.1.3/share/nvim"

My default shell is zsh (if that might affect anything)?

OSX version 10.11.6

@nsf
Copy link
Owner

nsf commented Sep 26, 2016

Hm, I wonder where do you get the log from if you don't run gocode -s. Are you using gocode's "force-debug-output" option? If so, you'd be the first one who does. Just a curious fact. :)

And what do you mean you don't get any autocompletions? In the log or in nvim?

@ns-cweber
Copy link
Author

ns-cweber commented Sep 26, 2016

Yeah, this is coming from force-debug-output. The behavior was the same before using force-debug-output; I just used that option to get some logging info. By "no autocompletions", I meant in nvim, but I don't see any in the log either.

@nsf
Copy link
Owner

nsf commented Sep 26, 2016

It's just first log message looks weird to me. Is it stripped or something? If you take a look at the code:

https://github.com/nsf/gocode/blob/master/server.go#L185-L209

It should print "Offset:" if it prints "Got autocompletion request". And I see none. Perhaps it hangs? Any signs of 100% cpu usage?

@ns-cweber
Copy link
Author

That's very odd. No sign of 100% cpu; cpu is 0 at idle and 0.9% during completion requests.

@ns-cweber
Copy link
Author

I also tried clearing my cache, in case it was confused between 1.6 and 1.7 artifacts.

@ns-cweber
Copy link
Author

Is it possible that candidates, d := g_daemon.autocomplete.apropos(file, filename, cursor) is somehow mutating g_debug or maybe panic/recovering such that the subsequent block isn't being executed?

@nsf
Copy link
Owner

nsf commented Sep 26, 2016

Panic is possible, but in this case it ends up here: https://github.com/nsf/gocode/blob/master/server.go#L136-L146

And returns one autocompletion result which is PANIC. And of course panic is also printed into the log.

Mutation of g_debug is unlikely:

[nsf @ gocode]$ LANG=C grep -R g_debug *
autocompletefile.go:    if err != nil && *g_debug {
autocompletefile.go:            if err != nil && *g_debug {
cursorcontext.go:       if *g_debug {
declcache.go:   if *g_debug {
declcache.go:   if *g_debug {
declcache.go:           if err != nil && *g_debug {
declcache.go:   if *g_debug {
declcache.go:   if *g_debug {
decl.go:                } else if !*g_debug && strings.HasPrefix(t.Name, "#") {
decl.go:                } else if !*g_debug && strings.HasPrefix(t.Name, "!") {
gocode.go:      g_debug     = flag.Bool("debug", false, "enable server-side debug mode")
server.go:              *g_debug = true
server.go:              if *g_debug && err != nil {
server.go:              if *g_debug && err != nil {
server.go:                      if *g_debug {
server.go:              } else if *g_debug {
server.go:      if *g_debug {
server.go:      if *g_debug {

Only force-debug-output option writes true to it and that's it.

@ns-cweber
Copy link
Author

I threw in some log statements around the aforementioned line. If I don't run gocode -s, they don't display at all. I'm suspecting gocode close isn't actually quitting the server?

@nsf
Copy link
Owner

nsf commented Sep 26, 2016

gocode close sends close command to a server if it can find one. If there is none, it will start one and send the close command to it. When server receives close command it should quit.

@nsf
Copy link
Owner

nsf commented Sep 26, 2016

Is it possible that you have multiple gocode binaries on your machine? What which -a gocode says?

@ns-cweber
Copy link
Author

ns-cweber commented Sep 26, 2016

➜  temp which -a gocode
/Users/cweber/Projects/bin/gocode
/Users/cweber/Projects/bin/gocode

No idea why it's repeated; ls -a ~/Projects/bin/goco* shows only one instance...

@nsf
Copy link
Owner

nsf commented Sep 26, 2016

Have no idea why it shows it twice, maybe you have some duplication in your PATH env var. But that's okay, there is only one location at the end. Should work.

@ns-cweber
Copy link
Author

ns-cweber commented Sep 26, 2016

So it looks like YouCompleteMe contains a gocode executable:

cweber          29563   0.0  0.0 573402464   6800   ??  S    11:45AM   0:00.09 /Users/cweber/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/gocode/gocode -s -sock unix -addr 127.0.0.1:55311

Last updated 7/30:

➜  temp ls -l ~/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/gocode/gocode
-rwxr-xr-x  1 cweber  staff  12000604 Jul 30 19:15 /Users/cweber/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/gocode/gocode

So I'm guessing this is to blame.

@nsf
Copy link
Owner

nsf commented Sep 26, 2016

That's interesting, I would get rid of it, but that's me, have no idea what YouCompleteMe does.

@ns-cweber
Copy link
Author

@nsf Nor I. I only installed it for Python completions, but it was a pain to install and has been more trouble than it's worth. I'll try to disable it and see what happens.

@nsf
Copy link
Owner

nsf commented Sep 26, 2016

Also since it looks like a process, make sure you kill it :)

@ns-cweber
Copy link
Author

After killing off all the ycmd processes, the first relaunched the correct gocode server, and I have my autocompletions back. Thanks very much for the debugging help!

@nsf
Copy link
Owner

nsf commented Sep 26, 2016

you're welcome

@ns-cweber
Copy link
Author

For posterity, it looks like YCM clones the entire gocode repo and builds it at YCM's install time. It appears to completely disregard the gocode repo in your $GOPATH. Navigate to the YCM gocode directory and run git pull origin master && go build to fix.

@wcn3
Copy link

wcn3 commented Oct 2, 2016

You can use a YCM variable to specify the location of gocode to use. You'll want to do this for godef as well.

let g:ycm_gocode_binary_path = "$GOPATH/bin/gocode"
let g:ycm_godef_binary_path = "$GOPATH/bin/godef"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants