[golang] unify package completion for build and run

* let both `go build` and `go run` suggest local files and dirs with
   `go build ./something`
 * let both suggest package identifiers
   `go build github.com/username/reponame`
 * automatically prefix relative paths with './'
   `go build file<TAB>` → `go build ./file.go`
This commit is contained in:
Paul Seyfert 2019-07-18 23:07:32 +02:00
parent b512d57b6d
commit e73235f0df
1 changed files with 12 additions and 2 deletions

View File

@ -117,8 +117,18 @@ case $state in
gopaths=("${(s/:/)$(go env GOPATH)}")
gopaths+=("$(go env GOROOT)")
for p in $gopaths; do
_path_files -W "$p/src" -/
_path_files $@ -W "$p/src" -/
done
# no special treatment for
# - relative paths starting with ..
# - absolute path starting with /
# - variables, substitutions, subshells
if [[ $words[$CURRENT] = ..* || $words[$CURRENT] = \$* || $words[$CURRENT] = /* ]]; then
_path_files $@ -/ -g '*.go'
else
# go build accepts paths relative to the cwd but they must start with './', so prefix them
_path_files $@ -P './' -/ -g '*.go'
fi
}
case $words[1] in
@ -266,7 +276,7 @@ case $state in
_arguments \
${build_flags[@]} \
'-exec[invoke the binary using xprog]:xporg' \
'*:file:_files -g "*.go(-.)"'
'*:importpaths:__go_packages'
;;
test)