9e9b790fe1e3150b36bb1e01b432f5b38e52b512

Author
Ilia Choly <icholy@accipiterradar.com>
Committer
Ilia Choly <icholy@accipiterradar.com>
Date

Message

golang: improve go doc completion

Diff

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