From 389a5a054864f780f57ac3c1f372dc1b99fc10bd Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Fri, 21 Sep 2018 23:25:45 +0300 Subject: [PATCH] go: install tools with their custom names We're assuming for now to use the same binary name that also matches the import path. But this is not always the case. To add support for an experimental `gocode`, we need to install a second binary. This change will allow us to do it by just adding a line, such as: \ 'gocode-gomod': ['github.com/stamblerre/gocode'], This PR splits `go get` command into specific download and install steps. A follow up PR to add support for gocode-gomod will follow. --- plugin/go.vim | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/plugin/go.vim b/plugin/go.vim index 48173c00fa..2a7be9c95b 100644 --- a/plugin/go.vim +++ b/plugin/go.vim @@ -29,7 +29,7 @@ if endif " these packages are used by vim-go and can be automatically installed if -" needed by the user with GoInstallBinaries +" needed by the user with GoInstallBinaries. let s:packages = { \ 'asmfmt': ['github.com/klauspost/asmfmt/cmd/asmfmt'], \ 'dlv': ['github.com/derekparker/delve/cmd/dlv'], @@ -99,9 +99,9 @@ function! s:GoInstallBinaries(updateBinaries, ...) set noshellslash endif - let l:cmd = ['go', 'get', '-v'] + let l:dl_cmd = ['go', 'get', '-v', '-d'] if get(g:, "go_get_update", 1) != 0 - let l:cmd += ['-u'] + let l:dl_cmd += ['-u'] endif " Filter packages from arguments (if any). @@ -127,16 +127,16 @@ function! s:GoInstallBinaries(updateBinaries, ...) for [binary, pkg] in items(l:packages) let l:importPath = pkg[0] - let l:run_cmd = copy(l:cmd) + let l:run_cmd = copy(l:dl_cmd) if len(l:pkg) > 1 && get(l:pkg[1], l:platform, '') isnot '' let l:run_cmd += get(l:pkg[1], l:platform, '') endif - let binname = "go_" . binary . "_bin" + let bin_setting_name = "go_" . binary . "_bin" let bin = binary - if exists("g:{binname}") - let bin = g:{binname} + if exists("g:{bin_setting_name}") + let bin = g:{bin_setting_name} endif if !executable(bin) || a:updateBinaries == 1 @@ -146,7 +146,15 @@ function! s:GoInstallBinaries(updateBinaries, ...) echo "vim-go: ". binary ." not found. Installing ". importPath . " to folder " . go_bin_path endif + " first download the binary let [l:out, l:err] = go#util#Exec(l:run_cmd + [l:importPath]) + if l:err + echom "Error downloading " . l:importPath . ": " . l:out + endif + + " and then build and install it + let l:build_cmd = ['go', 'build', '-o', go_bin_path . go#util#PathSep() . bin, l:importPath] + let [l:out, l:err] = go#util#Exec(l:build_cmd + [l:importPath]) if l:err echom "Error installing " . l:importPath . ": " . l:out endif @@ -158,6 +166,12 @@ function! s:GoInstallBinaries(updateBinaries, ...) if resetshellslash set shellslash endif + + if a:updateBinaries == 1 + call go#util#EchoInfo('updating finished!') + else + call go#util#EchoInfo('installing finished!') + endif endfunction " CheckBinaries checks if the necessary binaries to install the Go tool