Skip to content

Latest commit

 

History

History
114 lines (99 loc) · 2.87 KB

go.org

File metadata and controls

114 lines (99 loc) · 2.87 KB

Go

Overview

Go Mod

Should work with go mod projects.

Language Server

Most of the heavy lifting should be lsp and gopls

Role of older tools

This is based on how spacemacs go layer was structured, however key elements are changing for go mod support. Hence this is going to be in flux.

Go Mode and hooks

(use-package go-mode
  :ensure t
  :bind (
         ;; If you want to switch existing go-mode bindings to use lsp-mode/gopls instead
         ;; uncomment the following lines
         ;; ("C-c C-j" . lsp-find-definition)
         ;; ("C-c C-d" . lsp-describe-thing-at-point)
         )
  :config
  ; Use goimports instead of go-fmt
  (setq gofmt-command "goimports")
  (add-hook 'go-mode-hook 'company-mode)
  ;; Call Gofmt before saving
  (add-hook 'before-save-hook 'gofmt-before-save)
  (add-hook 'go-mode-hook 'setup-go-mode-compile)
  (add-hook 'go-mode-hook #'smartparens-mode)
  (add-hook 'go-mode-hook 'yas-minor-mode)
  (add-hook 'go-mode-hook 'flycheck-mode)
  
  (add-hook 'go-mode-hook '(lambda ()
           (local-set-key (kbd "C-c C-r") 'go-remove-unused-imports)
           (local-set-key (kbd "C-c b") 'go-run)))
  (add-hook 'go-mode-hook '(lambda ()
			     (local-set-key (kbd "C-c C-g") 'go-goto-imports)))
  (add-hook 'go-mode-hook (lambda ()
			    (set (make-local-variable 'company-backends) '(company-go))
			    (company-mode)))

  :hook ((go-mode . lsp-deferred)
         (before-save . lsp-organize-imports)))

Testing

(use-package gotest
  :ensure t
  :config
  (add-hook 'go-mode-hook '(lambda ()
			     (local-set-key (kbd "C-c a") 'go-test-current-project)
                 (local-set-key (kbd "C-c m") 'go-test-current-file)
                 (local-set-key (kbd "C-c ,") 'go-test-current-test)
           ))

)

Go Completion

(use-package company-go
  :ensure t
  :after go-mode
  :config
  (setq tab-width 4)

  :bind (:map go-mode-map
  ; Godef jump key binding
  ("M-." . godef-jump)))

(use-package go-eldoc
  :ensure t
  :config
  (add-hook 'go-mode-hook 'go-eldoc-setup))

(use-package go-guru
  :ensure t)

(defun setup-go-mode-compile ()
  ; Customize compile command to run go build
  (if (not (string-match "go" compile-command))
      (set (make-local-variable 'compile-command)
           "go build -v && go test -v && go vet")))

Syntax & Linting Check

Golangci

(use-package flycheck-golangci-lint
    :ensure t
    :config 
    (add-hook 'flycheck-mode-hook #'flycheck-golangci-lint-setup))

go snippets

(use-package go-snippets
  :ensure t)

babel support

(use-package ob-go
  :ensure t)

Provide this so that it may be required

(provide 'go)