fix(golang): complete go module tools (#13786)

This commit is contained in:
Rayan Salhab
2026-06-01 12:06:46 +03:00
committed by GitHub
parent b86a99da17
commit 70ad5e3df8

View File

@@ -15,6 +15,52 @@ __go_identifiers() {
compadd $(godoc -templates "$tmpl_path" ${words[-2]} 2> /dev/null) compadd $(godoc -templates "$tmpl_path" ${words[-2]} 2> /dev/null)
} }
__go_tool_commands() {
local -a tools tool_commands
local -A command_seen short_count
local tool command
tools=("${(@f)$(go tool 2>/dev/null)}")
# Go 1.24+ lists module tools by package path, but also accepts unique
# default binary names for those tools.
for tool in "${tools[@]}"; do
[[ -n $tool ]] || continue
(( command_seen[$tool]++ ))
if [[ $tool == */* ]]; then
command=${tool:t}
if [[ $command == v[0-9]* && ${command#v} != *[^0-9]* ]] && (( ${command#v} > 1 )); then
command=${${tool%/$command}:t}
fi
(( short_count[$command]++ ))
fi
done
for tool in "${tools[@]}"; do
[[ -n $tool ]] || continue
tool_commands+=("$tool")
if [[ $tool == */* ]]; then
command=${tool:t}
if [[ $command == v[0-9]* && ${command#v} != *[^0-9]* ]] && (( ${command#v} > 1 )); then
command=${${tool%/$command}:t}
fi
if (( short_count[$command] == 1 && ! command_seen[$command] )); then
tool_commands+=("$command")
fi
fi
done
_values "go tool" "${tool_commands[@]}"
}
_go() { _go() {
typeset -a commands build_flags typeset -a commands build_flags
commands+=( commands+=(
@@ -208,7 +254,7 @@ _go() {
;; ;;
tool) tool)
if (( CURRENT == 3 )); then if (( CURRENT == 3 )); then
_values "go tool" $(go tool) __go_tool_commands
return return
fi fi
case ${words[3]} in case ${words[3]} in