2015-04-19 03:40:24 +00:00
|
|
|
(setq go-packages
|
2015-10-26 13:57:33 +00:00
|
|
|
'(
|
|
|
|
company
|
2016-05-30 02:39:21 +00:00
|
|
|
(company-go :toggle (configuration-layer/package-usedp 'company))
|
2015-10-26 13:57:33 +00:00
|
|
|
flycheck
|
2016-05-30 02:39:21 +00:00
|
|
|
(flycheck-gometalinter :toggle (and go-use-gometalinter
|
|
|
|
(configuration-layer/package-usedp
|
|
|
|
'flycheck)))
|
2016-04-05 04:08:34 +00:00
|
|
|
ggtags
|
|
|
|
helm-gtags
|
2015-10-26 13:57:33 +00:00
|
|
|
go-eldoc
|
2016-01-18 03:06:04 +00:00
|
|
|
go-mode
|
2016-03-27 16:22:14 +00:00
|
|
|
(go-oracle :location site)
|
2016-01-18 03:06:04 +00:00
|
|
|
(go-rename :location local)
|
2015-10-26 13:57:33 +00:00
|
|
|
))
|
2015-01-09 06:08:07 +00:00
|
|
|
|
2016-05-30 02:39:21 +00:00
|
|
|
|
|
|
|
(defun go/post-init-company ()
|
|
|
|
(spacemacs|add-company-hook go-mode))
|
|
|
|
|
|
|
|
(defun go/init-company-go ()
|
|
|
|
(use-package company-go
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(setq company-go-show-annotation t)
|
|
|
|
(push 'company-go company-backends-go-mode))))
|
|
|
|
|
2015-04-11 02:23:16 +00:00
|
|
|
(defun go/post-init-flycheck ()
|
2016-04-30 02:58:23 +00:00
|
|
|
(spacemacs/add-flycheck-hook 'go-mode))
|
2015-01-10 04:09:16 +00:00
|
|
|
|
2015-01-09 06:08:07 +00:00
|
|
|
(defun go/init-go-mode()
|
2016-01-13 01:19:07 +00:00
|
|
|
(when (memq window-system '(mac ns x))
|
|
|
|
(dolist (var '("GOPATH" "GO15VENDOREXPERIMENT"))
|
|
|
|
(unless (getenv var)
|
|
|
|
(exec-path-from-shell-copy-env var))))
|
2015-06-06 17:28:54 +00:00
|
|
|
|
2015-01-09 06:08:07 +00:00
|
|
|
(use-package go-mode
|
|
|
|
:defer t
|
2016-04-05 02:36:51 +00:00
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(defun spacemacs//go-set-tab-width ()
|
|
|
|
"Set the tab width."
|
|
|
|
(setq-local tab-width go-tab-width))
|
2016-09-05 02:29:41 +00:00
|
|
|
(add-hook 'go-mode-hook 'spacemacs//go-set-tab-width))
|
2015-01-19 08:01:00 +00:00
|
|
|
:config
|
2015-04-04 04:34:03 +00:00
|
|
|
(progn
|
2015-01-19 08:01:00 +00:00
|
|
|
(add-hook 'before-save-hook 'gofmt-before-save)
|
2015-04-04 04:34:03 +00:00
|
|
|
|
2015-10-26 13:57:33 +00:00
|
|
|
(defun spacemacs/go-run-tests (args)
|
|
|
|
(interactive)
|
|
|
|
(save-selected-window
|
|
|
|
(async-shell-command (concat "go test " args))))
|
|
|
|
|
2015-04-04 04:34:03 +00:00
|
|
|
(defun spacemacs/go-run-package-tests ()
|
|
|
|
(interactive)
|
2015-10-26 13:57:33 +00:00
|
|
|
(spacemacs/go-run-tests ""))
|
|
|
|
|
|
|
|
(defun spacemacs/go-run-package-tests-nested ()
|
|
|
|
(interactive)
|
|
|
|
(spacemacs/go-run-tests "./..."))
|
|
|
|
|
|
|
|
(defun spacemacs/go-run-test-current-function ()
|
|
|
|
(interactive)
|
|
|
|
(if (string-match "_test\\.go" buffer-file-name)
|
|
|
|
(let ((test-method (if go-use-gocheck-for-testing
|
|
|
|
"-check.f"
|
|
|
|
"-run")))
|
|
|
|
(save-excursion
|
2016-04-13 13:40:27 +00:00
|
|
|
(re-search-backward "^func[ ]+\\(([[:alnum:]]*?[ ]?[*]?[[:alnum:]]+)[ ]+\\)?\\(Test[[:alnum:]_]+\\)(.*)")
|
2015-10-26 13:57:33 +00:00
|
|
|
(spacemacs/go-run-tests (concat test-method "='" (match-string-no-properties 2) "'"))))
|
|
|
|
(message "Must be in a _test.go file to run go-run-test-current-function")))
|
|
|
|
|
|
|
|
(defun spacemacs/go-run-test-current-suite ()
|
|
|
|
(interactive)
|
|
|
|
(if (string-match "_test\.go" buffer-file-name)
|
|
|
|
(if go-use-gocheck-for-testing
|
|
|
|
(save-excursion
|
2016-04-13 13:40:27 +00:00
|
|
|
(re-search-backward "^func[ ]+\\(([[:alnum:]]*?[ ]?[*]?\\([[:alnum:]]+\\))[ ]+\\)?Test[[:alnum:]_]+(.*)")
|
2016-01-21 20:23:25 +00:00
|
|
|
(spacemacs/go-run-tests (concat "-check.f='" (match-string-no-properties 2) "'")))
|
2015-10-26 13:57:33 +00:00
|
|
|
(message "Gocheck is needed to test the current suite"))
|
|
|
|
(message "Must be in a _test.go file to run go-test-current-suite")))
|
2015-04-04 04:34:03 +00:00
|
|
|
|
2015-10-22 19:22:26 +00:00
|
|
|
(defun spacemacs/go-run-main ()
|
|
|
|
(interactive)
|
|
|
|
(shell-command
|
|
|
|
(format "go run %s"
|
|
|
|
(shell-quote-argument (buffer-file-name)))))
|
|
|
|
|
2015-11-27 20:35:24 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'go-mode "me" "playground")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'go-mode "mg" "goto")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'go-mode "mh" "help")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'go-mode "mi" "imports")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'go-mode "mt" "test")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'go-mode "mx" "execute")
|
2015-11-18 00:38:05 +00:00
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'go-mode
|
|
|
|
"hh" 'godoc-at-point
|
|
|
|
"ig" 'go-goto-imports
|
|
|
|
"ia" 'go-import-add
|
|
|
|
"ir" 'go-remove-unused-imports
|
|
|
|
"eb" 'go-play-buffer
|
|
|
|
"er" 'go-play-region
|
|
|
|
"ed" 'go-download-play
|
|
|
|
"xx" 'spacemacs/go-run-main
|
|
|
|
"ga" 'ff-find-other-file
|
2016-03-04 13:10:05 +00:00
|
|
|
"gc" 'go-coverage
|
2015-11-18 00:38:05 +00:00
|
|
|
"tt" 'spacemacs/go-run-test-current-function
|
|
|
|
"ts" 'spacemacs/go-run-test-current-suite
|
|
|
|
"tp" 'spacemacs/go-run-package-tests
|
|
|
|
"tP" 'spacemacs/go-run-package-tests-nested))))
|
2015-01-12 04:22:23 +00:00
|
|
|
|
|
|
|
(defun go/init-go-eldoc()
|
2015-10-26 13:57:33 +00:00
|
|
|
(add-hook 'go-mode-hook 'go-eldoc-setup))
|
2015-01-19 08:01:00 +00:00
|
|
|
|
2016-01-18 03:06:04 +00:00
|
|
|
(defun go/init-go-oracle()
|
|
|
|
(let ((go-path (getenv "GOPATH")))
|
|
|
|
(if (not go-path)
|
|
|
|
(spacemacs-buffer/warning
|
|
|
|
"GOPATH variable not found, go-oracle configuration skipped.")
|
|
|
|
(when (load-gopath-file
|
|
|
|
go-path "/src/golang.org/x/tools/cmd/oracle/oracle.el")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'go-mode "mr" "rename")
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'go-mode
|
|
|
|
"ro" 'go-oracle-set-scope
|
|
|
|
"r<" 'go-oracle-callers
|
|
|
|
"r>" 'go-oracle-callees
|
|
|
|
"rc" 'go-oracle-peers
|
|
|
|
"rd" 'go-oracle-definition
|
|
|
|
"rf" 'go-oracle-freevars
|
|
|
|
"rg" 'go-oracle-callgraph
|
|
|
|
"ri" 'go-oracle-implements
|
|
|
|
"rp" 'go-oracle-pointsto
|
|
|
|
"rr" 'go-oracle-referrers
|
|
|
|
"rs" 'go-oracle-callstack
|
|
|
|
"rt" 'go-oracle-describe)))))
|
|
|
|
|
|
|
|
(defun go/init-go-rename()
|
|
|
|
(use-package go-rename
|
|
|
|
:init
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'go-mode "rn" 'go-rename)))
|
2016-04-11 14:08:56 +00:00
|
|
|
|
|
|
|
(defun go/init-flycheck-gometalinter()
|
|
|
|
(use-package flycheck-gometalinter
|
2016-04-30 02:58:23 +00:00
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(add-hook 'go-mode-hook 'spacemacs//go-enable-gometalinter t)))
|
2016-04-05 04:08:34 +00:00
|
|
|
|
|
|
|
(defun go/post-init-ggtags ()
|
2016-08-15 19:24:44 +00:00
|
|
|
(add-hook 'go-mode-local-vars-hook #'spacemacs/ggtags-mode-enable))
|
2016-04-05 04:08:34 +00:00
|
|
|
|
|
|
|
(defun go/post-init-helm-gtags ()
|
|
|
|
(spacemacs/helm-gtags-define-keys-for-mode 'go-mode))
|