From 90ff2c3d6aab2e0cb25f863281a14f3e58c59684 Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Wed, 6 Jun 2018 01:08:04 +0300 Subject: [PATCH 1/3] gocode: switch to https://github.com/mdempsky/gocode nsf/gocode is not working well with Go 1.10. I just encountered it myself again. The author of original gocode also states and recommends the mdempsky/gocode fork over nsf/gocode: https://github.com/nsf/gocode#an-autocompletion-daemon-for-the-go-programming-language We actually [moved once](https://github.com/fatih/vim-go/pull/1814), but because we didn't removed the obsolote settings, we weren't prepared for issues that were [reported](https://github.com/fatih/vim-go/issues/1817), and hence [reverted it back](https://github.com/fatih/vim-go/pull/1823) This PR also removes all settings. The reason is that the new gocode doesn't support settings anymore. The author decided not the support it. * For `autobuild`, this was removed because the author believe it's not worth tackling it inside `gocode`: https://github.com/mdempsky/gocode/issues/13 * For `propose builtins`, this is actually still supported but disabled in the source code, we need to add it back again in the future: https://github.com/mdempsky/gocode/commit/787cfae70965d528523902b4c12e85692e17336b * For `unimported packages`: this was just removed and I couldn't find upcoming plans for it Going forward this package seems to be more stable and is a better bet. Most important, as I stated nfs/gocode is not 1.10 compatible and the author has no intentions to fix it. --- autoload/go/complete.vim | 24 ------------------------ autoload/go/config.vim | 12 ------------ doc/vim-go.txt | 22 ---------------------- plugin/go.vim | 2 +- 4 files changed, 1 insertion(+), 59 deletions(-) diff --git a/autoload/go/complete.vim b/autoload/go/complete.vim index 9460b46204..e00ee226b7 100644 --- a/autoload/go/complete.vim +++ b/autoload/go/complete.vim @@ -43,31 +43,7 @@ function! s:sync_gocode(cmd, args, input) abort return l:result endfunction -let s:optionsEnabled = 0 -function! s:gocodeEnableOptions() abort - if s:optionsEnabled - return - endif - - let l:bin_path = go#path#CheckBinPath("gocode") - if empty(l:bin_path) - return - endif - - let s:optionsEnabled = 1 - - call go#util#Exec(['gocode', 'set', 'propose-builtins', s:toBool(go#config#GocodeProposeBuiltins())]) - call go#util#Exec(['gocode', 'set', 'autobuild', s:toBool(go#config#GocodeAutobuild())]) - call go#util#Exec(['gocode', 'set', 'unimported-packages', s:toBool(go#config#GocodeUnimportedPackages())]) -endfunction - -function! s:toBool(val) abort - if a:val | return 'true' | else | return 'false' | endif -endfunction - function! s:gocodeAutocomplete() abort - call s:gocodeEnableOptions() - " use the offset as is, because the cursor position is the position for " which autocomplete candidates are needed. return s:sync_gocode('autocomplete', diff --git a/autoload/go/config.vim b/autoload/go/config.vim index 140e41c5c0..d1a6bbea6a 100644 --- a/autoload/go/config.vim +++ b/autoload/go/config.vim @@ -135,23 +135,11 @@ function! go#config#SetGuruScope(scope) abort endif endfunction -function! go#config#GocodeUnimportedPackages() abort - return get(g:, 'go_gocode_unimported_packages', 0) -endfunction - let s:sock_type = (has('win32') || has('win64')) ? 'tcp' : 'unix' function! go#config#GocodeSocketType() abort return get(g:, 'go_gocode_socket_type', s:sock_type) endfunction -function! go#config#GocodeProposeBuiltins() abort - return get(g:, 'go_gocode_propose_builtins', 1) -endfunction - -function! go#config#GocodeAutobuild() abort - return get(g:, 'go_gocode_autobuild', 1) -endfunction - function! go#config#EchoCommandInfo() abort return get(g:, 'go_echo_command_info', 1) endfunction diff --git a/doc/vim-go.txt b/doc/vim-go.txt index 638a2765d2..a1c7b66dbf 100644 --- a/doc/vim-go.txt +++ b/doc/vim-go.txt @@ -1575,28 +1575,6 @@ same. \ '? go#util#pascalcase(expand(""))' . \ ': go#util#camelcase(expand(""))' < - *'g:go_gocode_autobuild'* - -Specifies whether `gocode` should automatically build out-of-date packages -when their source fields are modified, in order to obtain the freshest -autocomplete results for them. By default it is enabled. -> - let g:go_gocode_autobuild = 1 -< - *'g:go_gocode_propose_builtins'* - -Specifies whether `gocode` should add built-in types, functions and constants -to an autocompletion proposals. By default it is enabled. -> - let g:go_gocode_propose_builtins = 1 -< - *'g:go_gocode_unimported_packages'* - -Specifies whether `gocode` should include suggestions from unimported -packages. By default it is disabled. -> - let g:go_gocode_unimported_packages = 0 -< *'g:go_gocode_socket_type'* diff --git a/plugin/go.vim b/plugin/go.vim index 95bf7fd524..01e19b7d93 100644 --- a/plugin/go.vim +++ b/plugin/go.vim @@ -35,7 +35,7 @@ let s:packages = { \ 'dlv': ['github.com/derekparker/delve/cmd/dlv'], \ 'errcheck': ['github.com/kisielk/errcheck'], \ 'fillstruct': ['github.com/davidrjenni/reftools/cmd/fillstruct'], - \ 'gocode': ['github.com/nsf/gocode', {'windows': ['-ldflags', '-H=windowsgui']}], + \ 'gocode': ['github.com/mdempsky/gocode', {'windows': ['-ldflags', '-H=windowsgui']}], \ 'godef': ['github.com/rogpeppe/godef'], \ 'gogetdoc': ['github.com/zmb3/gogetdoc'], \ 'goimports': ['golang.org/x/tools/cmd/goimports'], From a981711b3ad4a9f07487b802ff85c2d31b578d34 Mon Sep 17 00:00:00 2001 From: Billie Cleek Date: Sun, 26 Aug 2018 10:03:02 -0700 Subject: [PATCH 2/3] restore support for proposing builtins --- autoload/go/complete.vim | 5 +++++ autoload/go/config.vim | 4 ++++ doc/vim-go.txt | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/autoload/go/complete.vim b/autoload/go/complete.vim index e00ee226b7..be5c40e960 100644 --- a/autoload/go/complete.vim +++ b/autoload/go/complete.vim @@ -9,6 +9,11 @@ function! s:gocodeCommand(cmd, args) abort let cmd = [bin_path] let cmd = extend(cmd, ['-sock', socket_type]) let cmd = extend(cmd, ['-f', 'vim']) + + if go#config#GocodeProposeBuiltins() + let cmd = extend(cmd, ['-builtin']) + endif + let cmd = extend(cmd, [a:cmd]) let cmd = extend(cmd, a:args) diff --git a/autoload/go/config.vim b/autoload/go/config.vim index d1a6bbea6a..e136d41b30 100644 --- a/autoload/go/config.vim +++ b/autoload/go/config.vim @@ -140,6 +140,10 @@ function! go#config#GocodeSocketType() abort return get(g:, 'go_gocode_socket_type', s:sock_type) endfunction +function! go#config#GocodeProposeBuiltins() abort + return get(g:, 'go_gocode_propose_builtins', 1) +endfunction + function! go#config#EchoCommandInfo() abort return get(g:, 'go_echo_command_info', 1) endfunction diff --git a/doc/vim-go.txt b/doc/vim-go.txt index a1c7b66dbf..5a3ba40ffd 100644 --- a/doc/vim-go.txt +++ b/doc/vim-go.txt @@ -1575,7 +1575,13 @@ same. \ '? go#util#pascalcase(expand(""))' . \ ': go#util#camelcase(expand(""))' < + *'g:go_gocode_propose_builtins'* +Specifies whether `gocode` should add built-in types, functions and constants +to an autocompletion proposals. By default it is enabled. +> + let g:go_gocode_propose_builtins = 1 +< *'g:go_gocode_socket_type'* Specifies whether `gocode` should use a different socket type. By default From 6be5309dfec4750803ed9c4c24a40e74aa8bbcb1 Mon Sep 17 00:00:00 2001 From: Billie Cleek Date: Sun, 26 Aug 2018 10:19:10 -0700 Subject: [PATCH 3/3] add option to propose from source --- autoload/go/complete.vim | 4 ++++ autoload/go/config.vim | 4 ++++ doc/vim-go.txt | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/autoload/go/complete.vim b/autoload/go/complete.vim index be5c40e960..a5992c63ad 100644 --- a/autoload/go/complete.vim +++ b/autoload/go/complete.vim @@ -14,6 +14,10 @@ function! s:gocodeCommand(cmd, args) abort let cmd = extend(cmd, ['-builtin']) endif + if go#config#GocodeProposeSource() + let cmd = extend(cmd, ['-source']) + endif + let cmd = extend(cmd, [a:cmd]) let cmd = extend(cmd, a:args) diff --git a/autoload/go/config.vim b/autoload/go/config.vim index e136d41b30..8e72b1a83a 100644 --- a/autoload/go/config.vim +++ b/autoload/go/config.vim @@ -144,6 +144,10 @@ function! go#config#GocodeProposeBuiltins() abort return get(g:, 'go_gocode_propose_builtins', 1) endfunction +function! go#config#GocodeProposeSource() abort + return get(g:, 'go_gocode_propose_source', 0) +endfunction + function! go#config#EchoCommandInfo() abort return get(g:, 'go_echo_command_info', 1) endfunction diff --git a/doc/vim-go.txt b/doc/vim-go.txt index 5a3ba40ffd..33015f40bb 100644 --- a/doc/vim-go.txt +++ b/doc/vim-go.txt @@ -1581,6 +1581,14 @@ Specifies whether `gocode` should add built-in types, functions and constants to an autocompletion proposals. By default it is enabled. > let g:go_gocode_propose_builtins = 1 +< + *'g:go_gocode_propose_source'* + +Specifies whether `gocode` should use source files instead of binary packages +for autocompletion proposals. By default it is disabled because it is +currently much slower. +> + let g:go_gocode_propose_source = 0 < *'g:go_gocode_socket_type'*