go: use gopls to reformat code and add missing (or remove old) imports
This commit is contained in:
parent
ef5bf904e6
commit
5f9633827f
22
init.el
22
init.el
@ -476,7 +476,7 @@ of the key binding used to execute this command."
|
|||||||
;;; `~/.emacs.d/init.el`. This adds syntax highlighting but without
|
;;; `~/.emacs.d/init.el`. This adds syntax highlighting but without
|
||||||
;;; fontifing names of called functions, autocompletion and info on
|
;;; fontifing names of called functions, autocompletion and info on
|
||||||
;;; called function in mode line, auto formatting of the code on save
|
;;; called function in mode line, auto formatting of the code on save
|
||||||
;;; with adding of missing imports ([goimports]).
|
;;; with adding of missing imports.
|
||||||
|
|
||||||
;;; It is quite long as I define two interactive functions:
|
;;; It is quite long as I define two interactive functions:
|
||||||
|
|
||||||
@ -489,7 +489,6 @@ of the key binding used to execute this command."
|
|||||||
;;; packages.
|
;;; packages.
|
||||||
|
|
||||||
;;; [go-mode]: https://github.com/dominikh/go-mode.el
|
;;; [go-mode]: https://github.com/dominikh/go-mode.el
|
||||||
;;; [goimports]: https://godoc.org/golang.org/x/tools/cmd/goimports
|
|
||||||
|
|
||||||
(defun my-go-electric-brace ()
|
(defun my-go-electric-brace ()
|
||||||
"Insert an opening brace may be with the closing one.
|
"Insert an opening brace may be with the closing one.
|
||||||
@ -536,8 +535,7 @@ inserted between the braces between the braces."
|
|||||||
|
|
||||||
(use-package go-mode
|
(use-package go-mode
|
||||||
:init
|
:init
|
||||||
(setq gofmt-command "goimports" ; use goimports instead of gofmt
|
(setq go-fontify-function-calls nil ; fontifing names of called
|
||||||
go-fontify-function-calls nil ; fontifing names of called
|
|
||||||
; functions is too much for me
|
; functions is too much for me
|
||||||
company-idle-delay nil) ; avoid auto completion popup, use TAB
|
company-idle-delay nil) ; avoid auto completion popup, use TAB
|
||||||
; to show it
|
; to show it
|
||||||
@ -554,8 +552,9 @@ inserted between the braces between the braces."
|
|||||||
(require 'go-guru)
|
(require 'go-guru)
|
||||||
(add-hook 'go-mode-hook #'lsp)
|
(add-hook 'go-mode-hook #'lsp)
|
||||||
(add-hook 'go-mode-hook #'smartparens-mode)
|
(add-hook 'go-mode-hook #'smartparens-mode)
|
||||||
;; run gofmt/goimports when saving the file
|
;; reformat code and add missing (or remove old) imports
|
||||||
(add-hook 'before-save-hook #'gofmt-before-save))
|
(add-hook 'before-save-hook #'lsp-format-buffer)
|
||||||
|
(add-hook 'before-save-hook #'lsp-organize-imports))
|
||||||
|
|
||||||
;; Go/speedbar integration
|
;; Go/speedbar integration
|
||||||
|
|
||||||
@ -591,21 +590,14 @@ inserted between the braces between the braces."
|
|||||||
;;; $ GO111MODULE=on go get golang.org/x/tools/cmd/gopls@latest
|
;;; $ GO111MODULE=on go get golang.org/x/tools/cmd/gopls@latest
|
||||||
;;; ```
|
;;; ```
|
||||||
|
|
||||||
;;; 4. Install [goimports] which can be installed from Debian package
|
;;; 4. Install [guru](https://godoc.org/golang.org/x/tools/cmd/guru)
|
||||||
;;; `golang-go.tools` or with
|
|
||||||
|
|
||||||
;;; ```
|
|
||||||
;;; $ go get -u golang.org/x/tools/cmd/goimports
|
|
||||||
;;; ```
|
|
||||||
|
|
||||||
;;; 5. Install [guru](https://godoc.org/golang.org/x/tools/cmd/guru)
|
|
||||||
;;; with
|
;;; with
|
||||||
|
|
||||||
;;; ```
|
;;; ```
|
||||||
;;; $ go get -u golang.org/x/tools/cmd/guru
|
;;; $ go get -u golang.org/x/tools/cmd/guru
|
||||||
;;; ```
|
;;; ```
|
||||||
|
|
||||||
;;; 6. Add your `$GOPATH/bin` to your `PATH` environment variable (or
|
;;; 5. Add your `$GOPATH/bin` to your `PATH` environment variable (or
|
||||||
;;; copy the `gopls`, `goimports`, and `guru` executables from
|
;;; copy the `gopls`, `goimports`, and `guru` executables from
|
||||||
;;; `$GOPATH/bin` to some directory which is in your `PATH`).
|
;;; `$GOPATH/bin` to some directory which is in your `PATH`).
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user