From 4b55f149e657db8de3b055be575639fbc151cf75 Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Mon, 29 Jul 2024 14:28:17 +0900 Subject: [PATCH 01/21] Update help and work subcommand completions --- src/_golang | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/_golang b/src/_golang index 47819c9..ec88f91 100644 --- a/src/_golang +++ b/src/_golang @@ -377,6 +377,7 @@ case $state in '-go[sets the expected Go language version]:goversion' '*-replace=[add a replacement of the given module path and version]:replace' '*-dropreplace=[drop a replacement of the given module path and version]:dropreplace' + '-toolchain=[set the Go toolchain to use]:name' '-json[prints the final go.mod/work file in JSON format]' '-print[prints the final go.mod/work in its text format]' ) @@ -1051,12 +1052,13 @@ case $state in '*:importpaths:__go_packages' ;; - work) + (work) local -a work_commands=( 'edit:edit go.work from tools or scripts' 'init:initialize workspace file' 'sync:sync workspace build list to modules' 'use:add modules to workspace file' + 'vendor:make vendored copy of dependencies' ) _arguments \ @@ -1064,9 +1066,9 @@ case $state in '*:: :->args' case $state in - args) + (args) case $words[1] in - edit) + (edit) _arguments \ ${edit_flags[@]} \ '*-use[add use directive from the go.work set of module directories]' \ @@ -1074,25 +1076,29 @@ case $state in ':go.work:_path_files -g "go.work"' ;; - init) + (init) _arguments \ '*:directory: _path_files -/' ;; - sync) - ;; - - use) + (use) _arguments \ '-r[searches recursively for modules in the argumentdirectories]' \ '*:directory: _path_files -/' ;; + + (vendor) + _arguments \ + '-v[print the names of vendored modules and packages to standard error]' \ + '-e[attempt to proceed despite errors encountered while loading packages]' \ + '-o[create the vendor directory at the given path instead of vendor]:outdir:_path_files -/' + ;; esac ;; esac ;; - help) + (help) local -a topics=( 'buildconstraint:build constraints' 'buildmode:build modes' @@ -1102,11 +1108,9 @@ case $state in 'filetype:file types' 'go.mod:the go.mod file' 'gopath:GOPATH environment variable' - 'gopath-get:legacy GOPATH go get' 'goproxy:module proxy protocol' 'importpath:import path syntax' 'modules:modules, module versions, and more' - 'module-get:module-aware go get' 'module-auth:module authentication using go.sum' 'packages:package lists and patterns' 'private:configuration for downloading non-public code' From 177fadadbaf10bee331235b6a9e94a7d8c9361ed Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Mon, 29 Jul 2024 17:46:12 +0900 Subject: [PATCH 02/21] Update 'go vet' completion --- src/_golang | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/_golang b/src/_golang index ec88f91..41075f2 100644 --- a/src/_golang +++ b/src/_golang @@ -1037,17 +1037,18 @@ case $state in esac ;; - version) + (version) _arguments \ '-m[print each executable embedded module version information]' \ '-v[report unrecognized files]' \ '*:files:_files' ;; - vet) + (vet) _arguments \ '-n[print commands that would be executed]' \ '-x[prints commands as they are executed]' \ + '-vettool[set a different analysis tool with alternative or additional checks]:prog:_files' \ ${build_flags[@]} \ '*:importpaths:__go_packages' ;; From 91fce8803693d67c7f7faff93cc71bc473d821f4 Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Mon, 29 Jul 2024 17:57:17 +0900 Subject: [PATCH 03/21] Update 'go tool asm' completion --- src/_golang | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/_golang b/src/_golang index 41075f2..6e742f1 100644 --- a/src/_golang +++ b/src/_golang @@ -727,9 +727,8 @@ case $state in fi ;; - tool) - local -a tools - tools=($(go tool)) + (tool) + local -a tools=($(go tool)) _arguments \ '-n[print command that would be executed]' \ @@ -737,22 +736,29 @@ case $state in '*:: :->args' case $state in - args) + (args) case $words[1] in - addr2line) + (addr2line) _files ;; - asm) + (asm) _arguments \ - '-D[predefined symbol with optional simple value]:value' \ - '-I[include directory]:value' \ + '*-D[predefined symbol with optional simple value]:value' \ + '*-I[include directory]:value' \ '-S[print assembly and machine code]' \ + '(- *)-V[print assembler version and exit]' \ '-debug[dump instructions as they are parsed]' \ '-dynlink[support references to Go symbols]' \ - '-o[output file]:string' \ + '-e[no limit on number of errors reported]' \ + '-gensymabis[write symbol ABI information to output file. Do not assemble]' \ + '-o[output file]:string:_files' \ + '-p[set expected package import to pkgpath]:pkgpath' \ '-shared[generate code that can be linked into a shared lib]' \ - '-trimpath[remove prefix from recorded source file paths]:string' + '-spectre[enable spectre mitigations in list]:list:(all ret)' \ + '-trimpath[remove prefix from recorded source file paths]:string' \ + '-v[print debug output]' \ + '*:file:_files' ;; callgraph) From b4c970619b8adf0ed853d22186e3039f395c24c6 Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Mon, 29 Jul 2024 17:59:51 +0900 Subject: [PATCH 04/21] Add 'go tool buildid' completion --- src/_golang | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/_golang b/src/_golang index 6e742f1..75b6ec1 100644 --- a/src/_golang +++ b/src/_golang @@ -761,25 +761,13 @@ case $state in '*:file:_files' ;; - callgraph) - local -a algos=( - 'static:static calls only' - 'cha:Class Hierarchy Analysis' - 'rta:Rapid Type Analysis' - 'pta:inclusion-based Points-To Analysis' - ) - local -a graphs=( - 'digraph:output in digraph format' - 'graphviz:output in AT&T GraphViz (.dot) format' - ) - + (buildid) _arguments \ - '-algo=[call-graph construction algorithm]:algos:{ _describe "algos" algos }' \ - "-test[include the package's tests in the analysis]" \ - '-format=[format in which each call graph edge is displayed]:graphs:{ _describe "graphs" graphs }' + '-w[rewrite the build ID found in the file]' \ + '*:file:_files' ;; - cgo) + (cgo) _arguments \ '-debug-define[print relevant #defines]' \ '-debug-gcc[print gcc invocations]' \ From 5a4bbc1ad87816374bae33213d26338d31c8781d Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Mon, 29 Jul 2024 18:10:37 +0900 Subject: [PATCH 05/21] Update 'go tool cgo' completion --- src/_golang | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/_golang b/src/_golang index 75b6ec1..137899e 100644 --- a/src/_golang +++ b/src/_golang @@ -769,21 +769,25 @@ case $state in (cgo) _arguments \ + '(- *)-V[print cgo version and exit]' \ '-debug-define[print relevant #defines]' \ '-debug-gcc[print gcc invocations]' \ '-dynimport[if non-empty, print dynamic import data]:string' \ '-dynlinker[record dynamic linker information]' \ - '-dynout[write -dynimport output to file]:file' \ + '-dynout[write -dynimport output to file]:file:_files' \ '-dynpackage[set Go package for -dynimport output]:string' \ '-exportheader[where to write export header]:string' \ - '-gccgo[generate files for use with gccgo]' \ - '-gccgopkgpath[-fgo-pkgpath option used with gccgo]:string' \ - '-gccgoprefix[-fgo-prefix option used with gccgo]:string' \ - '-godefs[write Go definitions for C file to stdout]' \ + '-importpath[the import path for the Go package]:package' \ '-import_runtime_cgo[import runtime/cgo in generated code]' \ '-import_syscall[import syscall in generated code]' \ - '-importpath[import path of package being built]:path' \ - '-objdir[object directory]:dir' + '-gccgo[generate files for use with gccgo]' \ + '-gccgoprefix[-fgo-prefix option used with gccgo]:string' \ + '-gccgopkgpath[-fgo-pkgpath option used with gccgo]:string:_path_files -/' \ + '-gccgo_define_cgoincomplete[define cgo.Incomplete locally rather than importing it from "runtime/cgo" package]' \ + '-godefs[write Go definitions for C file to stdout]' \ + '-objdir[object directory]:dir:_path_files -/' \ + '-srcdir[source directory]:dir:_path_files -/' \ + '*:file:_files' ;; compile) From 057d9a994062bbaea8e10a33dca6047f95da5603 Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Mon, 29 Jul 2024 18:36:59 +0900 Subject: [PATCH 06/21] Update 'go fix' completion --- src/_golang | 83 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 36 deletions(-) diff --git a/src/_golang b/src/_golang index 137899e..347576e 100644 --- a/src/_golang +++ b/src/_golang @@ -320,6 +320,40 @@ __go_envvarvals() { esac } +__go_packages() { + local -a gopaths=("${(s/:/)$(go env GOPATH)}") + gopaths+=("$(go env GOROOT)") + for p in $gopaths; do + _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 +} + +__go_fix_names() { + local -a fix_names=( + 'buildtag[remove +build comments from modules using Go 1.18 or later]' + 'cftype[fixes initialzers and casts of C.*Ref and JNI types]' + 'context[Change imports of golang.org/x/net/context to context]' + 'egl[fixes initializers of EGLDisplay]' + 'eglconf[fixes initializers of EGLConfig]' + 'gotypes[change imports of oglang.org/x/tools/go{exact,types} to go/{constant,types}]' + "jni[fixes initializers of JNI's jobject and subtypes]" + 'netipv6zone[adapt element key to IPAddr, UPDAddr, TCPAddr composite literals]' + 'printerconfig[add element keys to Config composite literals]' + ) + + _values -s ',' 'fix name' $fix_names +} + if [[ "$service" = -value-* ]]; then variable=${${service%,-default-}#-value-,} # some special variables are not read from the environment @@ -382,26 +416,6 @@ case $state in '-print[prints the final go.mod/work in its text format]' ) - __go_packages() { - local gopaths - declare -a gopaths - gopaths=("${(s/:/)$(go env GOPATH)}") - gopaths+=("$(go env GOROOT)") - for p in $gopaths; do - _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 build) _arguments \ @@ -409,7 +423,7 @@ case $state in ${build_flags[@]} \ ${mod_flags[@]} \ '*:importpaths:__go_packages' - ;; + ;; clean) _arguments \ @@ -422,7 +436,7 @@ case $state in ${build_flags[@]} \ ${mod_flags[@]} \ '*:importpaths:__go_packages' - ;; + ;; doc) _arguments \ @@ -432,7 +446,7 @@ case $state in '-short[one-line representation for each symbol]' \ '-src[show the full source code for the symbol]' \ '-u[show docs for unexported and exported symbols and methods]' - ;; + ;; env) local -a goenvvars=( @@ -495,7 +509,7 @@ case $state in ) local -a exclude_from_w=(GOENV) - __list_env_vars() { + __go_list_env_vars() { # the parameter expansion strops off everything after the first [ _values -s ' ' -w 'environment variable' ${goenvvars[@]%%\[*} } @@ -507,13 +521,17 @@ case $state in '-json[print the environment in JSON format]' \ '-u[unset environment variables]' \ '-w[change the default setting of environment variables]' \ - '*:[show environment variable]: __list_env_vars' || _values \ + '*:[show environment variable]: __go_list_env_vars' || _values \ -s ' ' -S "=" -w 'environment variable' ${^goenvvars:#GOENV*}": __go_envvarvals" ;; - fix) + (fix) _arguments \ '-C[change to directory before running the command]: :_files -/' \ + '-diff[display diffs instead of rewriting files]' \ + '-force[force these fixes to run even if the code looks updated]:fix_names:__go_fix_names' \ + '-go[go language version for files]:version' \ + '-r[restrict the rewrites to this comma-separated list]:fix_names:__go_fix_names' \ '*:importpaths:__go_packages' ;; @@ -860,12 +878,12 @@ case $state in '*:file:_files -g "*.go(-.)"' ;; - doc) + (doc) _arguments \ '-c[respect case when matching symbols]' \ '-cmd[treat a command (package main) like a regular package]' \ - '-u[show docs for unexported and exported symbols and methods]' \ - ;; + '-u[show docs for unexported and exported symbols and methods]' + ;; fix) _arguments \ @@ -1023,13 +1041,6 @@ case $state in '-v[verbose]' \ '*:files:_files' ;; - - yacc) - _arguments \ - '-o[output]:output' \ - '-v[parsetable]:parsetable' \ - '*:files:_files' - ;; esac ;; esac From f475c1322f8f0e0b48cde56a42d93debe78f4fa9 Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Mon, 29 Jul 2024 18:47:46 +0900 Subject: [PATCH 07/21] Improve 'go help' completion --- src/_golang | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/_golang b/src/_golang index 347576e..e3541d4 100644 --- a/src/_golang +++ b/src/_golang @@ -415,6 +415,17 @@ case $state in '-json[prints the final go.mod/work file in JSON format]' '-print[prints the final go.mod/work in its text format]' ) + local -a mod_commands=( + 'download:download modules to local cache' + 'edit:edit go.mod from tools or scripts' + 'graph:print module requirement graph' + 'init:initialize new module in current directory' + 'tidy:add missing and remove unused modules' + 'vendor:make vendored copy of dependencies' + 'verify:verify dependencies have expected content' + 'why:explain why packages or modules are needed' + 'help:get more information about a command' + ) case $words[1] in build) @@ -593,27 +604,15 @@ case $state in _arguments ${list_args[@]} ;; - mod) - local -a mod_commands=( - 'download:download modules to local cache' - 'edit:edit go.mod from tools or scripts' - 'graph:print module requirement graph' - 'init:initialize new module in current directory' - 'tidy:add missing and remove unused modules' - 'vendor:make vendored copy of dependencies' - 'verify:verify dependencies have expected content' - 'why:explain why packages or modules are needed' - 'help:get more information about a command' - ) - + (mod) _arguments \ "1: :{_describe 'command' mod_commands}" \ '*:: :->args' case $state in - args) + (args) case $words[1] in - download) + (download) _arguments \ '-json[print a sequence of JSON objects to standard output]' \ '-x[print the commands download executes]' @@ -662,12 +661,12 @@ case $state in esac ;; - run) + (run) _arguments \ ${build_flags[@]} \ '-exec[invoke the binary using xprog]:xporg' \ '*:importpaths:__go_packages' - ;; + ;; test) if [[ $words[$CURRENT] = -test.* ]]; then @@ -1129,7 +1128,14 @@ case $state in 'vcs:controlling version control with GOVCS' ) - _arguments "1: :{_describe 'command' commands -- topics}" + case "$words[2]" in + (mod) + _arguments "2: :{_describe 'command' mod_commands}" + ;; + (*) + _arguments "1: :{_describe 'command' commands -- topics}" + ;; + esac ;; esac ;; From 937cd0fcea26579b6a421bf7002074c2ae38c8a2 Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Tue, 30 Jul 2024 11:56:50 +0900 Subject: [PATCH 08/21] Complete package name in 'go doc' --- src/_golang | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/_golang b/src/_golang index e3541d4..1f001ea 100644 --- a/src/_golang +++ b/src/_golang @@ -449,14 +449,15 @@ case $state in '*:importpaths:__go_packages' ;; - doc) + (doc) _arguments \ '-all[show all the documentation for the package]' \ '-c[respect case when matching symbols]' \ '-cmd[treat a command (package main) like a regular package]' \ '-short[one-line representation for each symbol]' \ '-src[show the full source code for the symbol]' \ - '-u[show docs for unexported and exported symbols and methods]' + '-u[show docs for unexported and exported symbols and methods]' \ + '*:importpaths:__go_packages' ;; env) From 61c84a203c2259f3293c2bb82c38b25023490f74 Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Tue, 30 Jul 2024 12:15:24 +0900 Subject: [PATCH 09/21] Update 'go env' environment list --- src/_golang | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/_golang b/src/_golang index 1f001ea..8fea9f1 100644 --- a/src/_golang +++ b/src/_golang @@ -428,7 +428,7 @@ case $state in ) case $words[1] in - build) + (build) _arguments \ '-o[force build to write to named output file or directory]:file or directory:_files' \ ${build_flags[@]} \ @@ -436,7 +436,7 @@ case $state in '*:importpaths:__go_packages' ;; - clean) + (clean) _arguments \ '-i[remove corresponding installed archive or binary]' \ '-r[apply clean recursively on all dependencies]' \ @@ -460,12 +460,15 @@ case $state in '*:importpaths:__go_packages' ;; - env) + (env) local -a goenvvars=( - "GOARCH[architecture, or processor, for which to compile code.]:architecture" + # General-purpose environment variables + "GO111MODULE[controls whether the go command runs in module-aware mode]:value" "GCCGO[gccgo command to run.]:gccgo command" + "GOARCH[architecture, or processor, for which to compile code.]:architecture" "GOBIN[directory where 'go install' installs to]:go install target dir" "GOCACHE[directory to store cached information]:go build cache dir" + "GOMODCACHE[module cache directory]:path" "GODEBUG[enable runtime debug facilities]:runtime debug settings" "GOENV[location of the go environment configuration file]:configuration file" "GOFLAGS[default go command line flags]:space separated default command line flags" @@ -473,13 +476,16 @@ case $state in "GOOS[target operating system]:operating system" "GOPATH[path to resolve import statements]:import path" "GOPROXY[URL of go module proxy]:proxy url" - "GOROOT[root of the go tree]:go root directory" - "GOTMPDIR[directory for temporary sources, packages, and binaries]:tmp directory" "GOPRIVATE[modules that should always be fetched directly]:comma separated glob patterns" "GONOPROXY[modules that should always be fetched directly]:comma separated glob patterns" "GONOSUMDB[modules that should not be compared against the checksum db]:comma separated glob patterns" - "GOMODCACHE[module cache directory]:path" + "GOROOT[root of the go tree]:go root directory" "GOSUMDB[checksum database]:name(+publickey( url))" + "GOTOOLCHAIN[control which Go tool chain is used]:toolchain" + "GOTMPDIR[directory for temporary sources, packages, and binaries]:tmp directory" + "GOVCS[lists version control commands that may be used with matching servers]:commands" + "GOWORK[use the given go.work file as a workspace file]:workspace_file" + # Environment variables for use with cgo "AR[command for manipulating library archives (for gccgo)]:archive manipulation program" "CC[command to compile C code]:C compiler" "CGO_ENABLED[enable/disable cgo]:boolean" @@ -501,6 +507,7 @@ case $state in "CXX[command to compile C++]:C++ compiler" "FC[command to compile Fortran]:Fortran compiler" "PKG_CONFIG[Path to pkg-config tool.]:path to pkg-config" + # Architecture-specific environment variables "GOARM[arm architecture]:arm architecture" "GO386[x86 instruction set]:x86 instruction set" "GOAMD64[amd64 instruction set]:amd64 instruction set" @@ -508,16 +515,22 @@ case $state in "GOMIPS64[mips64 instruction set]:mips64 instruction set" "GOPPC64[powerpc64 instruction set]:powerpc64 instruction set" "GOWASM[web assembly features]:comma separated web assembly features" + # Environment variable for use with code coverage + "GOCOVERDIR[directory into which to write code coverage data files]" + # Special-purpose environment variables "GCCGOTOOLDIR[directory of gccgo tools]:gccgo tool directory" + "GOEXPERIMENT[comma-separated list of toolchain experiments to enable or disable]" "GOROOT_FINAL[root of the go tree]:go root" "GO_EXTLINK_ENABLED[enable external linking mode]:boolean" "GIT_ALLOW_PROTOCOL[schemes allowed to fetch]:colon separated git schemes" + # Additional information "GOEXE[suffix for executables]:executable suffix" "GOGCCFLAGS[arguments supplied to CC]:space separated arguments to CC" "GOHOSTARCH[architecture of the toolchain binaries]:host os architecture" "GOHOSTOS[operating system of the toolchain binaries]:host os" "GOMOD[absolute path the the main go.mod]:abs path to main go.mod" "GOTOOLDIR[installation directory of go tools]:tool installation directory" + "GOVERSION[The version of the installed Go tree]" ) local -a exclude_from_w=(GOENV) From aac56495ba3cea700ce0fcc9a5c06f334b5cb84e Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Tue, 30 Jul 2024 12:17:57 +0900 Subject: [PATCH 10/21] Update 'go fmt' completion --- src/_golang | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/_golang b/src/_golang index 8fea9f1..32d64eb 100644 --- a/src/_golang +++ b/src/_golang @@ -560,11 +560,12 @@ case $state in '*:importpaths:__go_packages' ;; - fmt) + (fmt) _arguments \ '-C[change to directory before running the command]: :_files -/' \ '-n[prints commands that would be executed]' \ '-x[prints commands as they are executed]' \ + '-mod=[sets which download mode to use]:mode:(readonly vendor)' \ '*:importpaths:__go_packages' ;; From 78c0ab5f9519b247daae80a3e47699315ba570b7 Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Tue, 30 Jul 2024 12:19:18 +0900 Subject: [PATCH 11/21] Update 'go generate' completion --- src/_golang | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/_golang b/src/_golang index 32d64eb..8496f34 100644 --- a/src/_golang +++ b/src/_golang @@ -563,19 +563,20 @@ case $state in (fmt) _arguments \ '-C[change to directory before running the command]: :_files -/' \ - '-n[prints commands that would be executed]' \ - '-x[prints commands as they are executed]' \ - '-mod=[sets which download mode to use]:mode:(readonly vendor)' \ + '-n[print commands that would be executed]' \ + '-x[print commands as they are executed]' \ + '-mod=[set which download mode to use]:mode:(readonly vendor)' \ '*:importpaths:__go_packages' ;; - generate) + (generate) _arguments \ '-C[change to directory before running the command]: :_files -/' \ '-run=[specifies a regular expression to select directives]:regex' \ '-x[print the commands]' \ '-n[print the commands but do not run them]' \ '-v[print the names of packages as they are compiled]' \ + ${build_flags[@]} \ "*:args:{ _alternative ':importpaths:__go_packages' _files }" ;; From 89d7a5ec24f770a45c76f9dfd7ddfd5dca829954 Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Tue, 30 Jul 2024 12:26:31 +0900 Subject: [PATCH 12/21] Update 'go list' completion --- src/_golang | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/_golang b/src/_golang index 8496f34..8735a7e 100644 --- a/src/_golang +++ b/src/_golang @@ -580,7 +580,7 @@ case $state in "*:args:{ _alternative ':importpaths:__go_packages' _files }" ;; - get) + (get) # no mod_flags for get _arguments \ '-d[instructs get to stop after downloading the packages]' \ @@ -593,18 +593,21 @@ case $state in '*:importpaths:__go_packages' ;; - install) + (install) _arguments ${build_flags[@]} \ '*:importpaths:__go_packages' ;; - list) + (list) local -a list_args=( '-e[changes the handling of erroneous packages]' '-f[specifies an alternate format for the list]:format' '-json[causes package data to be printed in JSON format]' '-compiled[set CompiledGoFiles to the Go source files presented to the compiler]' '-deps[iterate over named packages and their dependencies]' + '-export[set the Export for the given package]:package' + '-find[identify the named packages but not resolve their dependencies]:package' + '-test[report not only the named packages but also their test binaries]' '-m[list modules instead of packages]' ${build_flags[@]} ${mod_flags[@]} @@ -613,8 +616,8 @@ case $state in # -u and -versions are only available if -m is present on the commandline if (($words[(I)-m])); then list_args+=( - '-u[adds information about available upgrades]' - '-versions[list all known versions of modules]' + '-u[adds information about available upgrades]' + '-versions[list all known versions of modules]' ) fi _arguments ${list_args[@]} From 13b8ba55e26085049944e71e0265c8f5757b87e5 Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Tue, 30 Jul 2024 12:36:24 +0900 Subject: [PATCH 13/21] Update 'go tool compile' completion --- src/_golang | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/_golang b/src/_golang index 8735a7e..bf73f23 100644 --- a/src/_golang +++ b/src/_golang @@ -826,7 +826,7 @@ case $state in '*:file:_files' ;; - compile) + (compile) _arguments \ '-%[debug non-static initializers]' \ '-+[compiling runtime]' \ @@ -834,35 +834,47 @@ case $state in '-B[disable bounds checking]' \ '-D[set relative path for local imports]:path' \ '-E[debug symbol export]' \ - '-I[add directory to import search path]:directory' \ + '*-I[add directory to import search path]:directory' \ '-K[debug missing line numbers]' \ '-L[use full (long) path in error messages]' \ '-M[debug move generation]' \ '-N[disable optimizations]' \ '-P[debug peephole optimizer]' \ '-R[debug register optimizer]' \ - '-S[print assembly listing]' \ - '-V[print compiler version]' \ + '*-S[print assembly listing]' \ + '(- *)-V[print compiler version and exit]' \ '-W[debug parse tree after type checking]' \ '-asmhdr[write assembly header to file]:file' \ + '-asan[insert calls to C/C++ address sanitizer]' \ '-buildid[record id as the build id in the export metadata]:id' \ + '-blockprofile[write block profile for the compilation to file]:file:_files' \ + '-c[concurrency during compilation]:concurrency' \ '-complete[compiling complete package (no C or assembly)]' \ - '-cpuprofile[write cpu profile to file]:file' \ + '-cpuprofile[write cpu profile to file]:file:_files' \ '-d[print debug information about items in list]:list' \ + '-dwarf[generate DWARF symbols]' \ + '-dwarflocationlists[add location lists to DWARF in optimized mode]' \ + '-gendwarfinl[generate DWARF inline info records]:num' \ '-dynlink[support references to Go symbols]' \ '-e[no limit on number of errors reported]' \ '-f[debug stack frames]' \ '-g[debug code generation]' \ + '-goversion[specify required go tool version of the runtime]:version' \ '-h[halt on error]' \ '-i[debug line number stack]' \ + '-importcfg[read import configuration from file]:config:_files' \ '-installsuffix[set pkg directory suffix]:suffix' \ '-j[debug runtime-initialized variables]' \ '-l[disable inlining]' \ + '-lang[set language version to compile]:version' \ '-largemodel[generate code that assumes a large memory model]' \ + '-linjobj[write linker-specific object to file and compiler-specific object to usual output file]:file:_files' \ '-live[debug liveness analysis]' \ '-m[print optimization decisions]' \ '-memprofile[write memory profile to file]:file' \ '-memprofilerate[set runtime.MemProfileRate to rate]:rate' \ + '-msan[insert calls to C/C++ memory sanitizer]' \ + '-mutexprofile[write mutex profile for the compilation to file]:file:_files' \ '-nolocalimports[reject local (relative) imports]' \ '-o[write output to file]:file' \ '-p[set expected package import path]:path' \ @@ -871,6 +883,8 @@ case $state in '-race[enable race detector]' \ '-s[warn about composite literals that can be simplified]' \ '-shared[generate code that can be linked into a shared library]' \ + '-spectre[enable spectre mitigations in list]:type:(all index ret)' \ + '-traceprofile[write an execution trace to file]:file:_files' \ '-trimpath[remove prefix from recorded source file paths]:prefix' \ '-u[reject unsafe code]' \ '-v[increase debug verbosity]' \ From 238d3b0749a8f1f589711681e5f73e857ff611a1 Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Tue, 30 Jul 2024 12:38:41 +0900 Subject: [PATCH 14/21] Update 'go tool fix' completion --- src/_golang | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/_golang b/src/_golang index bf73f23..eaa383c 100644 --- a/src/_golang +++ b/src/_golang @@ -917,11 +917,12 @@ case $state in '-u[show docs for unexported and exported symbols and methods]' ;; - fix) + (fix) _arguments \ + '(* -)-help[show help message]' \ '-diff[display diffs instead of rewriting files]' \ - '-force[force fixes to run even if the code looks updated]:string' \ - '-r[restrict the rewrites]:string' \ + '-force[force fixes to run even if the code looks updated]:string:__go_fix_names' \ + '-r[restrict the rewrites]:string:__go_fix_names' \ '*:files:_files' ;; From a8dacc93aacaa4849c436521f76d2a04c8be4a9d Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Tue, 30 Jul 2024 12:43:19 +0900 Subject: [PATCH 15/21] Update 'go tool pack' completion --- src/_golang | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/_golang b/src/_golang index eaa383c..b6207b8 100644 --- a/src/_golang +++ b/src/_golang @@ -970,14 +970,25 @@ case $state in '*:files:_files' ;; - objdump) + (objdump) _arguments \ '-s[only dump symbols matching this regexp]:regexp' \ '*:files:_files' ;; - pack) - _arguments '1:ops:(c p r t x)' '::verbose:(v)' ':files:_files' + (pack) + local -a pack_ops=( + 'c:append files to a new archive' + 'p:print files from the archive' + 'r:append files to the archive' + 't:list files from the archive' + 'x:extract files from the archive' + ) + + _arguments \ + '1:ops:{_describe "ops" pack_ops}' \ + '::verbose:(v)' \ + ':files:_files' ;; pprof) From da937c9124f096426cd1589e07a917e9f2c550f7 Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Tue, 30 Jul 2024 12:51:36 +0900 Subject: [PATCH 16/21] Update 'go tool vet' completion --- src/_golang | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/_golang b/src/_golang index b6207b8..87e7d54 100644 --- a/src/_golang +++ b/src/_golang @@ -1055,34 +1055,48 @@ case $state in '*:files:_files' ;; - vet) + (vet) _arguments \ - '-all[check everything]' \ + '(- *)-V[print version and exit]'\ + '-appends[enable appends analysis]' \ '-asmdecl[check assembly against Go declarations]' \ '-assign[check for useless assignments]' \ '-atomic[check for common mistaken usages of the sync/atomic]' \ - '-bool[check for mistakes involving boolean operators]' \ - '-buildtags[check that +build tags are valid]' \ + '-bools[enable bools analysis]' \ + '-buildtag[check that +build tags are valid]' \ + '-cgocall[enable cgocall analysis]' \ '-composites[check that composite literals used field-keyed elements]' \ '-compositewhitelist[use composite white list]' \ '-copylocks[check that locks are not passed by value]' \ + '-defers[enable defers analysis]' \ + '-directive[enable directive analysis]' \ + '-errorsas[enable errorsas analysis]' \ + '-flags[print analysis flags in JSON]' \ + '-framepointer[enable framepointer analysis]' \ + '-httpresponse[enable httpresponse analysis]' \ + '-ifaceassert[enable ifaceassert analysis]' \ + '-json[emit JSON output]' \ + '-loopclosure[enable loopclosure analysis]' \ + '-lostcancel[enable lostcancel analysis]' \ '-methods[check that canonically named methods are canonically defined]' \ '-nilfunc[check for comparisons between functions and nil]' \ '-printf[check printf-like invocations]' \ '-printfuncs[print function names to check]:string' \ '-rangeloops[check that range loop variables are used correctly]' \ - '-shadow[check for shadowed variables]' \ - '-shadowstrict[whether to be strict about shadowing]' \ - '-shift[check for useless shifts]' \ + '-shift[enable shift analysis]' \ + '-sigchanyzer[enable sigchanyzer analysis]' \ + '-slog[enable slog analysis]' \ + '-stdmethods[enable stdmethods analysis]' \ + '-stringintconv[enable stringintconv analysis]' \ '-structtags[check that struct field tags have canonical format]' \ - '-tags[list of build tags to apply when parsing]:list' \ - '-test[for testing only: sets -all and -shadow]' \ + '-tests[enable tests analysis]' \ + '-timeformat[enable time format analysis]' \ + '-unmarshal[enable unmarshal analysis]' \ '-unreachable[check for unreachable code]' \ '-unsafeptr[check for misuse of unsafe.Pointer]' \ '-unusedfuncs[list of functions whose results must be used]:string' \ '-unusedresult[check for unused result of calls to functions in -unusedfuncs]' \ '-unusedstringmethods[list of methods whose results must be used]:string' \ - '-v[verbose]' \ '*:files:_files' ;; esac From 580b096df456239258e3222bd7bd62e1eeeeec79 Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Tue, 30 Jul 2024 12:58:19 +0900 Subject: [PATCH 17/21] Update 'go tool trace' completion --- src/_golang | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/_golang b/src/_golang index 87e7d54..c4a4d2a 100644 --- a/src/_golang +++ b/src/_golang @@ -1049,9 +1049,18 @@ case $state in '*:files:_files' ;; - trace) + (trace) + local -a trace_types=( + "net:network blocking profile" + "sync:synchronization blocking profile" + "syscall:syscall blocking profile" + "scheduler:latency profile" + ) + _arguments \ + '-pprof=[profile type]:type:{_describe "type" trace_types}' \ '-http=[HTTP service address]:addr' \ + '-d=[print debug info such as parsed events]:level:((1\:"high-level" 2\:"low-level"))' \ '*:files:_files' ;; From 9380071ffb1122fdd5feb80fa0f88a2025677716 Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Wed, 31 Jul 2024 12:06:03 +0900 Subject: [PATCH 18/21] Update 'go mod' completion --- src/_golang | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/_golang b/src/_golang index c4a4d2a..a5bf4ff 100644 --- a/src/_golang +++ b/src/_golang @@ -634,10 +634,10 @@ case $state in (download) _arguments \ '-json[print a sequence of JSON objects to standard output]' \ - '-x[print the commands download executes]' + '-x[print the commands download executes]' \ + '-reuse[file containing the JSON output of a previous "go mod download -json" invocation]:json:_files -g "*.json"' ;; - - edit) + (edit) _arguments \ ${edit_flags[@]} \ "-module[change the module's path]" \ @@ -645,31 +645,31 @@ case $state in '*-dropexclude=[drop an exclusion for the given module path and version]:dropexclude' \ ':go.mod:_path_files -g "go.mod"' ;; - graph) + (graph) _arguments \ - '-go[report the module graph as loaded by the given Go version]:goversion' + '-go[report the module graph as loaded by the given Go version]:goversion' \ + '-x[print the commands graph executes]' ;; - init) + (init) # Use go packages as module name suggestion _arguments \ '*:module:__go_packages' ;; - tidy) + (tidy) _arguments \ '-v[print information about removed modules to standard error]' \ '-e[attempt to proceed despite errors encountered while loading packages]' \ + '-x[print the commands download executes]' \ '-go[update the go directive in the go.mod file to the given version]:goversion' \ - '-compat[preserves additional checksums needed for the indicated Go version]' + '-compat[preserves additional checksums needed for the indicated Go version]:version' ;; - vendor) + (vendor) _arguments \ '-v[print the names of vendored modules and packages to standard error]' \ '-e[attempt to proceed despite errors encountered while loading packages]' \ '-o[create the vendor directory at the given path instead of "vendor"]:directory:_path_files -/' ;; - verify) - ;; - why) + (why) _arguments \ '-m[treats the arguments as a list of modules]' \ '-vendor[exclude tests of dependencies]' \ From ef50c3a7b9d3c6f5f369ed749a2d0d113d98050e Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Wed, 31 Jul 2024 12:10:22 +0900 Subject: [PATCH 19/21] Update 'go test' completion --- src/_golang | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/_golang b/src/_golang index a5bf4ff..b2e2445 100644 --- a/src/_golang +++ b/src/_golang @@ -687,7 +687,7 @@ case $state in '*:importpaths:__go_packages' ;; - test) + (test) if [[ $words[$CURRENT] = -test.* ]]; then _arguments \ '-test.bench[run only benchmarks matching regexp]:regexp' \ @@ -746,11 +746,13 @@ case $state in '-memprofile[write a memory profile to file]:mem' \ '-memprofilerate[enable more precise memory profiles]:n' \ '-mutexprofile[write a mutex contention profile to the specified file]:file:_files' \ - '-outputdir[place output files from profiling in output dir]:dir' \ + '-mutexprofilefraction[sample 1 in n stack traces of goroutines holding a contended mutex]:n' \ + '-outputdir[place output files from profiling in output dir]:dir:_path_files -/' \ '-parallel[allow parallel execution of test functions]:n' \ '-run[run tests and examples matching the regular expression]:regexp' \ '-short[tell long-running tests to shorten their run time]' \ '-shuffle[randomize the execution order of tests and benchmarks]:type:(off on)' \ + '-skip[run only tests that do not match the regular expression]:pattern' \ '-test.-[specify options for test running]:test running options:' \ '-timeout[timeout long running tests]:t' \ '-trace[write an execution trace to the specified file]:trace' \ @@ -761,7 +763,7 @@ case $state in '-o[compile test binary to named file]:file:_files' \ '*:importpaths:__go_packages' fi - ;; + ;; (tool) local -a tools=($(go tool)) From f036321bc45713a69d78c080b1e431602945ff2e Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Wed, 31 Jul 2024 12:10:56 +0900 Subject: [PATCH 20/21] Update version --- src/_golang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_golang b/src/_golang index b2e2445..6bbfdf6 100644 --- a/src/_golang +++ b/src/_golang @@ -30,7 +30,7 @@ # Description # ----------- # -# Completion script for go 1.21 (https://go.dev/). +# Completion script for go 1.22.5 (https://go.dev/). # # ------------------------------------------------------------------------------ # Authors From 22222832d8a889c295843a3ea91c1605cd78be99 Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Wed, 31 Jul 2024 16:42:02 +0900 Subject: [PATCH 21/21] Update environment variable completion And don't use global variables --- src/_golang | 113 +++++++++++++++++++--------------------------------- 1 file changed, 41 insertions(+), 72 deletions(-) diff --git a/src/_golang b/src/_golang index 6bbfdf6..41d7e0b 100644 --- a/src/_golang +++ b/src/_golang @@ -207,114 +207,84 @@ __go_envvarvals() { # decide which variable to go to. if $1 is not set, then __go_envvarvals is # called from the `go env` completion and the current word (with all after # the first '=' removed) is the current variable. - local variable - variable=${1-${words[$CURRENT]%%=*}} - case $variable in + local env_variable=${1-${words[$CURRENT]%%=*}} + case $env_variable in + (GO111MODULE) + _values "module mode" off on auto + ;; # commands - AR) - ;& - CC) - ;& - CXX) - ;& - FC) - ;& - GCCGO) + (AR|CC|CXX|FC|GCCGO) _command_names -e ;; - # directories (using fallthrough) - GOBIN) - ;& - GOCACHE) - ;& - GOTMPDIR) - ;& - GOTOOLDIR) - ;& - GOROOT) - ;& - GOROOT_FINAL) - ;& - GCCGOTOOLDIR) - ;& - GOPATH) - ;& - GOMODCACHE) + # directories + (GOBIN|GOCACHE|GOTMPDIR|GOTOOLDIR|GOROOT|GOROOT_FINAL|GCCGOTOOLDIR|GOPATH|GOMODCACHE|GOCOVERDIR) _files -/ ;; - # regular files (using fallthrough) - GOMOD) - ;& - PKG_CONFIG) - ;& - GOENV) + # regular files + (GOMOD|PKG_CONFIG|GOENV) _files ;; # special - GOHOSTOS) - ;& - GOOS) + (GOHOSTOS|GOOS) # from https://golang.org/doc/install/source#environment - _values 'operating system' aix android darwin dragonfly freebsd illumos ios js linux netbsd openbsd plan9 solaris windows wasip1 + local -a supported_os=( + aix android darwin dragonfly freebsd illumos ios js linux netbsd openbsd plan9 solaris wasip1 windows + ) + _values 'operating system' $supported_os ;; - GOHOSTARCH) - ;& - GOARCH) - _values 'architecture' amd64 386 arm64 arm ppc64 ppc64le mips mipsle mips64 mips64le riscv64 s390x wasm + (GOHOSTARCH|GOARCH) + local -a supported_arch=( + amd64 386 arm arm64 ppc64le ppc64 mips64le mips64 mipsle mips s390x riscv64 wasm + ) + _values 'architecture' $supported_arch ;; - CGO_ENABLED) + (CGO_ENABLED) _values 'enable/disable cgo' 0 1 ;; - GO_EXTLINK_ENABLED) + (GO_EXTLINK_ENABLED) _values 'enable/disable external linkage' 0 1 ;; - GOARM) + (GOARM) _values 'target arm architecture' 5 6 7 ;; - GO386) - _values 'x86 floating point instruction set' 387 sse2 + (GO386) + _values 'x86 floating point instruction set' sse2 softfloat ;; - GOAMD64) + (GOAMD64) _values 'amd64 instruction set' v1 v2 v3 v4 ;; - GOMIPS*) + (GOMIPS*) _values 'mips floating point instructions' hardfloat softfloat ;; - GOPPC64) + (GOPPC64) _values 'powerpc64 instruction set' power8 power9 power10 ;; - GOWASM) + (GOWASM) _values 'web assembly features' -s ',' satconv signext ;; - GOPROXY) + (GOPROXY) _urls ;; - GOEXE) + (GOEXE) _message "suffix for executables" ;; - CGO_*FLAGS_*ALLOW) + (CGO_*FLAGS_*ALLOW) _message "regexp" ;; - CGO_*FLAGS) + (CGO_*FLAGS) _dispatch $service -value-,${variable#CGO_},-default- ;; - GODEBUG) + (GODEBUG) __go_runtimedebug ;; - GOFLAGS) + (GOFLAGS) # not implemented, sorry ;; - GOINSECURE) - ;& - GOPRIVATE) - ;& - GONOPROXY) - ;& - GONOSUMDB) + (GOINSECURE|GOPRIVATE|GONOPROXY|GONOSUMDB) # comma separated glob patterns (in the syntax of Go's path.Match) _message "comma separated glob pattern" ;; - GOSUMDB) + (GOSUMDB) _message "e.g. sum.golang.org+ https://sum.golang.org" ;; esac @@ -355,14 +325,13 @@ __go_fix_names() { } if [[ "$service" = -value-* ]]; then - variable=${${service%,-default-}#-value-,} + local env_variable=${${service%,-default-}#-value-,} # some special variables are not read from the environment - local -a blacklist - blacklist=('GOEXE' 'GOGCCFLAGS' 'GOHOSTARCH' 'GOHOSTOS' 'GOMOD' 'GOTOOLDIR') - if (($blacklist[(I)$variable])); then + local -a blacklist=('GOEXE' 'GOGCCFLAGS' 'GOHOSTARCH' 'GOHOSTOS' 'GOMOD' 'GOTOOLDIR') + if (($blacklist[(I)$env_variable])); then return fi - __go_envvarvals $variable + __go_envvarvals $env_variable return fi