From 6316a7855ebc7109391bc76a6178b0c012f6003e Mon Sep 17 00:00:00 2001 From: Andreas Fuchs Date: Wed, 16 Aug 2017 23:40:43 -0700 Subject: [PATCH] Introduce godoc command and arg variables, restructure query * 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). --- emacs-company/company-go.el | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/emacs-company/company-go.el b/emacs-company/company-go.el index 9cb8a03c..a8590cbc 100644 --- a/emacs-company/company-go.el +++ b/emacs-company/company-go.el @@ -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 @@ -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)