Skip to content

Commit 7729b36

Browse files
committed
Integrate godoc lookup into company-go
Using the package information the 4th field in CSV output, call `godoc` on the symbol being completed. This activates the automatic documentation functionality for go in company.
1 parent c47efd1 commit 7729b36

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

emacs-company/company-go.el

+15-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ symbol is preceded by a \".\", ignoring `company-minimum-prefix-length'."
9090
(defun company-go--get-candidates (strings)
9191
(mapcar (lambda (str)
9292
(let ((candidate (split-string str ",,")))
93-
(propertize (nth 1 candidate) 'meta (company-go--format-meta candidate)))) strings))
93+
(propertize (nth 1 candidate)
94+
'meta (company-go--format-meta candidate)
95+
'package (nth 3 candidate))))
96+
strings))
9497

9598
(defun company-go--candidates ()
9699
(let ((candidates (company-go--get-candidates (split-string (company-go--invoke-autocomplete) "\n" t))))
@@ -207,6 +210,15 @@ triggers a completion immediately."
207210
(buffer-string))
208211
str))
209212

213+
(defun company-go--godoc-as-buffer (arg)
214+
"Return Go documentation for QUERY as a buffer."
215+
(let ((package (get-text-property 0 'package arg)))
216+
(unless (or (string= arg "") (string= package ""))
217+
(let* ((query (format "%s.%s" package arg))
218+
(buf (godoc--get-buffer query)))
219+
(call-process-shell-command (concat godoc-command " " query) nil buf nil)
220+
buf))))
221+
210222
;;;###autoload
211223
(defun company-go (command &optional arg &rest ignored)
212224
(interactive (list 'interactive))
@@ -223,6 +235,8 @@ triggers a completion immediately."
223235
(when company-go-show-annotation
224236
(company-go--extract-annotation (get-text-property 0 'meta arg))))
225237
(location (company-go--location arg))
238+
(doc-buffer
239+
(company-go--godoc-as-buffer arg))
226240
(sorted t)
227241
(post-completion
228242
(when (and company-go-insert-arguments

0 commit comments

Comments
 (0)