Skip to content

Commit

Permalink
Introduce godoc command and arg variables, restructure query
Browse files Browse the repository at this point in the history
* Add the -u flag (customizably) to the `go doc` command line: This
  ensures that un-exported/private names get matched & have their docs
  displayed, too.

* Add a company-go customization option for the `go doc` command line.

* Make sure that if company-go gets no package, it looks in the
  current directory. This can more reliably show documentation for the
  current package's names (including internals).
  • Loading branch information
antifuchs committed Aug 17, 2017
1 parent 8aef1e9 commit 6316a78
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions emacs-company/company-go.el
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ symbol is preceded by a \".\", ignoring `company-minimum-prefix-length'."
:group 'company-go
:type '(repeat string))

(defcustom company-go-godoc-command "go doc"
"The command to invoke `go doc' with."
:group 'company-go
:type 'string)

(defcustom company-go-godoc-args "-u"
"Arguments to pass to `go doc'."
:group 'company-go
:type 'string)

(defun company-go--invoke-autocomplete ()
(let ((code-buffer (current-buffer))
(gocode-args (append company-go-gocode-args
Expand Down Expand Up @@ -212,12 +222,19 @@ triggers a completion immediately."

(defun company-go--godoc-as-buffer (arg)
"Return Go documentation for QUERY as a buffer."
(let ((package (get-text-property 0 'package arg)))
(unless (or (string= arg "") (string= package ""))
(let* ((query (format "%s.%s" package arg))
(buf (godoc--get-buffer query)))
(call-process-shell-command (concat godoc-command " " query) nil buf nil)
buf))))
(unless (string= arg "")
(let* ((package (get-text-property 0 'package arg))
(query (if (string= package "")
arg
(format "%s.%s" package arg)))
(buf (godoc--get-buffer query))
(exit-code (call-process-shell-command
(concat company-go-godoc-command " " company-go-godoc-args " " query)
nil buf nil)))
(if (zerop exit-code)
buf
(kill-buffer buf)
nil))))

;;;###autoload
(defun company-go (command &optional arg &rest ignored)
Expand Down

0 comments on commit 6316a78

Please sign in to comment.