2dc980c8c03fe31eccda6c646c4866956cfee3ac

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #4331 from icholy/master

golang: improve go doc completion

Diff

  1diff --git a/plugins/golang/golang.plugin.zsh b/plugins/golang/golang.plugin.zsh
  2index 900fc630dbe3c346ea014588ad854d3f97c80864..1ce3cea58e861e6540509143d1e3f1913056177e 100644
  3--- a/plugins/golang/golang.plugin.zsh
  4+++ b/plugins/golang/golang.plugin.zsh
  5@@ -54,23 +54,42 @@ __go_tool_complete() {
  6     '-installsuffix[suffix to add to package directory]:suffix'
  7     '-tags[list of build tags to consider satisfied]:tags'
  8   )
  9-  __go_list() {
 10-      local expl importpaths
 11-      declare -a importpaths
 12-      importpaths=($(go list ${words[$CURRENT]}... 2>/dev/null))
 13-      _wanted importpaths expl 'import paths' compadd "$@" - "${importpaths[@]}"
 14+  __go_packages() {
 15+      local gopaths
 16+      declare -a gopaths
 17+      gopaths=("${(s/:/)$(go env GOPATH)}")
 18+      gopaths+=("$(go env GOROOT)")
 19+      for p in $gopaths; do
 20+        _path_files -W "$p/src" -/
 21+      done
 22+  }
 23+  __go_identifiers() {
 24+      compadd $(godoc -templates $ZSH/plugins/golang/templates ${words[-2]} 2> /dev/null)
 25   }
 26   case ${words[2]} in
 27-  clean|doc)
 28-      _arguments -s -w : '*:importpaths:__go_list'
 29+  doc)
 30+    _arguments -s -w \
 31+      "-c[symbol matching honors case (paths not affected)]" \
 32+      "-cmd[show symbols with package docs even if package is a command]" \
 33+      "-u[show unexported symbols as well as exported]" \
 34+      "2:importpaths:__go_packages" \
 35+      ":next identifiers:__go_identifiers"
 36+      ;;
 37+  clean)
 38+    _arguments -s -w \
 39+      "-i[remove the corresponding installed archive or binary (what 'go install' would create)]" \
 40+      "-n[print the remove commands it would execute, but not run them]" \
 41+      "-r[apply recursively to all the dependencies of the packages named by the import paths]" \
 42+      "-x[print remove commands as it executes them]" \
 43+      "*:importpaths:__go_packages"
 44       ;;
 45   fix|fmt|list|vet)
 46-      _alternative ':importpaths:__go_list' ':files:_path_files -g "*.go"'
 47+      _alternative ':importpaths:__go_packages' ':files:_path_files -g "*.go"'
 48       ;;
 49   install)
 50       _arguments -s -w : ${build_flags[@]} \
 51         "-v[show package names]" \
 52-        '*:importpaths:__go_list'
 53+        '*:importpaths:__go_packages'
 54       ;;
 55   get)
 56       _arguments -s -w : \
 57@@ -81,7 +100,7 @@ __go_tool_complete() {
 58         ${build_flags[@]} \
 59         "-v[show package names]" \
 60         "-o[output file]:file:_files" \
 61-        "*:args:{ _alternative ':importpaths:__go_list' ':files:_path_files -g \"*.go\"' }"
 62+        "*:args:{ _alternative ':importpaths:__go_packages' ':files:_path_files -g \"*.go\"' }"
 63       ;;
 64   test)
 65       _arguments -s -w : \
 66@@ -103,7 +122,7 @@ __go_tool_complete() {
 67         "-cpuprofile[write CPU profile to file]:file:_files" \
 68         "-memprofile[write heap profile to file]:file:_files" \
 69         "-memprofilerate[set heap profiling rate]:number" \
 70-        "*:args:{ _alternative ':importpaths:__go_list' ':files:_path_files -g \"*.go\"' }"
 71+        "*:args:{ _alternative ':importpaths:__go_packages' ':files:_path_files -g \"*.go\"' }"
 72       ;;
 73   help)
 74       _values "${commands[@]}" \
 75diff --git a/plugins/golang/templates/package.txt b/plugins/golang/templates/package.txt
 76new file mode 100644
 77index 0000000000000000000000000000000000000000..2b75cce35d43b2cf93883d9c278a104b1bde71b0
 78--- /dev/null
 79+++ b/plugins/golang/templates/package.txt
 80@@ -0,0 +1,29 @@
 81+{{with .PDoc}}{{/*
 82+
 83+Constants 
 84+---------------------------------------
 85+
 86+*/}}{{with .Consts}}{{range .}}{{range .Names}}{{.}} {{end}}{{end}}{{end}}{{/*
 87+
 88+Variables
 89+---------------------------------------
 90+
 91+*/}}{{with .Vars}}{{range .}}{{range .Names}}{{.}} {{end}}{{end}}{{end}}{{/*
 92+
 93+Functions
 94+---------------------------------------
 95+
 96+*/}}{{with .Funcs}}{{range .}}{{ .Name }} {{end}}{{end}}{{/*
 97+
 98+Types
 99+---------------------------------------
100+
101+*/}}{{with .Types}}{{range .}}{{ $TypeName := .Name }}{{ $TypeName }} {{/*
102+
103+*/}}{{range .Methods}}{{ $TypeName }}.{{.Name}} {{end}}{{/*
104+
105+*/}}{{range .Funcs}}{{.Name}} {{end}}{{/*
106+
107+*/}}{{range .Consts}}{{range .Names}}{{.}} {{end}}{{end}}{{/*
108+
109+*/}}{{range .Vars}}{{range .Names}}{{.}} {{end}}{{end}}{{end}}{{end}}{{end}}
110diff --git a/plugins/golang/templates/search.txt b/plugins/golang/templates/search.txt
111new file mode 100644
112index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
113--- /dev/null
114+++ b/plugins/golang/templates/search.txt