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

Third-party libraries are not supported #2

Open
holenlv opened this issue Aug 13, 2018 · 12 comments
Open

Third-party libraries are not supported #2

holenlv opened this issue Aug 13, 2018 · 12 comments

Comments

@holenlv
Copy link

holenlv commented Aug 13, 2018

If third-party libraries is installed in $GOPATH/src ,It works well
But it doesn't work if installed in project/vendor

@roxma
Copy link
Member

roxma commented Aug 13, 2018

I cannot reproduce the issue.

If you could reproduce the issue with vim-go, set omnifunc=go#complete#Complete and <c-x><c-o>, it's more likely to be gocode issue.

@jsfaint
Copy link

jsfaint commented Jan 3, 2019

Recently, maybe after Go 1.11 was released.
The behavior of Go completion became very weird.
Some code can be completed with lsp (go-langserve), but can't be completed with ncm2-go.

For example, here are two completion item, the first from ncm2-go, the second from lsp
image

Then input ., there are only lsp result left, no result from ncm2-go
image

@jsfaint
Copy link

jsfaint commented Jan 9, 2019

I changed gocode from https://github.com/mdempsky/gocode to https://github.com/stamblerre/gocode.
The issue above was resolved.

Currently gocode has 3 forks on the table, but they all have some different issues.
The original: https://github.com/nsf/gocode
The active fork: https://github.com/mdempsky/gocode
Go module support: https://github.com/stamblerre/gocode

@jsfaint
Copy link

jsfaint commented Jan 9, 2019

And I also find this issue
mdempsky/gocode#32

This is known issue. gocode make candidates from current package or standard package. So you must enable source importer with -source flag.

If you use vim-go, please try this.

diff --git a/autoload/go/complete.vim b/autoload/go/complete.vim
index 127d57f..279b10c 100644
--- a/autoload/go/complete.vim
+++ b/autoload/go/complete.vim
@@ -9,6 +9,7 @@ function! s:gocodeCommand(cmd, args) abort
   let cmd = [bin_path]
   let cmd = extend(cmd, ['-sock', socket_type])
   let cmd = extend(cmd, ['-f', 'vim'])
+  let cmd = extend(cmd, ['-source'])
   let cmd = extend(cmd, [a:cmd])
   let cmd = extend(cmd, a:args)
 

It looks we need to add parameter -source for gocode

@jsfaint
Copy link

jsfaint commented Jan 12, 2019

I found another solution for this case.
Run go build -i, it will install the third-party library into $GOPATH/pkg, then everything will be OK.

@fcying
Copy link

fcying commented Jan 17, 2019

@jsfaint
I add -source in args, it can complete github.com/sciter-sdk/go-sciter/window, But the completion is too slow.

        args = args = [gocode, '-f', 'json', '-source',                                                                                                    
                       'autocomplete', filepath, '%s' % offset]

and I test deoplete-go, It can complete and fast, I don't know how it is implemented

@jsfaint
Copy link

jsfaint commented Jan 17, 2019

Yes, -source is very slow. You can use go build -i to build the library you use, then the completion will works well.

The -i flag installs the packages that are dependencies of the target.

@fcying
Copy link

fcying commented Jan 17, 2019

@jsfaint after go build -i , it can autocomplete fast. just a little trouble. Every time you import a new package, you have to build it at first.

Or it can be use a cache? This will slow at first complete(with -source).

@jsfaint
Copy link

jsfaint commented Jan 18, 2019

@fcying gocode usage below:

$ gocode -h
Usage: gocode [-s] [-f=<format>] [-in=<path>] [-sock=<type>] [-addr=<addr>]
       <command> [<args>]

Flags:
  -addr string
        address for tcp socket (default "127.0.0.1:37373")
  -builtin
        propose completions for built-in functions and types
  -debug
        enable server-side debug mode
  -f string
        output format (vim | emacs | nice | csv | json) (default "nice")
  -fallback-to-source
        if importing a package fails, fallback to the source importer
  -ignore-case
        do case-insensitive matching
  -in string
        use this file instead of stdin input
  -s    run a server instead of a client
  -sock string
        socket type (unix | tcp | none) (default "unix")
  -source
        use source importer
  -unimported-packages
        propose completions for standard library packages not explicitly importe                                                                               d

Commands:
  autocomplete [<path>] <offset>     main autocompletion command
  exit                               terminate the gocode daemon

gocode will import the binary package ($GOPATH/pkg/$GOOS_$GOARCH/) by default, if no parameter was given.

There are two parameter is related here: -source and -fallback-to-source

  -source
        use source importer

  -fallback-to-source
        if importing a package fails, fallback to the source importer

As you know, -source is very slow, and it doesn't support vendor package.
-fallback-to-source maybe a little fast in general case, but it doesn't support vendor pacakge too.
So the best workaround here is go build -i

I only use deoplete-go long time ago, it is very slow in that time.
I'm not sure what was changed since that

@fcying
Copy link

fcying commented Jan 18, 2019

@jsfaint I test ncm2-vim-lsp + bingo, it work very well

Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'ncm2/ncm2-vim-lsp'
if executable('bingo')
    au User lsp_setup call lsp#register_server({
        \ 'name': 'bingo',
        \ 'cmd': {server_info->['bingo', '-mode', 'stdio']},
        \ 'whitelist': ['go'],
        \ })
endif

@jsfaint
Copy link

jsfaint commented Jan 18, 2019

Yes, lsp is ok, but completion in ncm2-go and lsp server is different case.
All we talk about here is based on gocode

😄 you can also have a look on the Go official lsp server implementation.
https://github.com/golang/tools/tree/master/cmd/gopls

@ttys3
Copy link

ttys3 commented Dec 13, 2020

I changed gocode from https://github.com/mdempsky/gocode to https://github.com/stamblerre/gocode. The issue above was resolved.

Currently gocode has 3 forks on the table, but they all have some different issues.
The original: https://github.com/nsf/gocode
The active fork: https://github.com/mdempsky/gocode
Go module support: https://github.com/stamblerre/gocode

and now, all those forks is under maintance.

https://github.com/mdempsky/gocode:

For a better autocompletion experience with Go, we suggest you use the Go language server, gopls.
If you are looking for a version of gocode that works with Go modules, please see stamblerre/gocode.

https://github.com/stamblerre/gocode:

IMPORTANT: This fork of gocode is currently in maintenance mode. For a better development experience with Go modules, we suggest you use the Go language server, gopls.

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

5 participants