Merge pull request #642 from pseyfert/go-relative-paths

[golang] unify package completion for build and run
This commit is contained in:
nicoulaj 2019-09-20 21:24:51 +02:00 committed by GitHub
commit ca24e66278
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)