Go autocomplete

Go autocomplete

gocode

弃用

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
go get github.com/nsf/gocode
# change .zshrc or .bashrc
gocode
gocode set propose-builtins true
# install goimports
go install golang.org/x/tools/cmd/goimports@latest
# install godoc
go get golang.org/x/tools/cmd/godoc
# install godef
go get github.com/rogpeppe/godef

了解gopls

了解lsp

了解lsp-ui

gopls+lsp-mode

install gopls

go get golang.org/x/tools/gopls@latest

install lisp-mode

配置部分

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(use-package go-mode
  :ensure t
  :mode (("\\.go\\'" . go-mode))
  ;;:hook ((before-save . gofmt-before-save))
  :config
  ;;(setq gofmt-command "goimports")
  (add-hook 'go-mode-hook '(lambda()
                             (set (make-local-variable 'company-backends)'(company-go))
                             (company-mode)))

  (add-hook 'go-mode-hook #'lsp-go-install-save-hooks)
  (add-hook 'go-mode-hook 'lsp-deferred)
  (add-hook 'go-mode-hook #'yas-minor-mode)
  (use-package lsp-mode
    :ensure t
    :config
    (defun lsp-go-install-save-hooks ()
      (add-hook 'before-save-hook #'lsp-format-buffer t t)
      (add-hook 'before-save-hook #'lsp-organize-imports t t))
    )
  ;; Set up before-save hooks to format buffer and add/delete imports.
  (use-package company-go
    :ensure t
    )
  (use-package go-eldoc
    :ensure t
    :hook (go-mode . go-eldoc-setup)
    )
  (use-package go-guru
    :ensure t
    :hook (go-mode . go-guru-hl-identifier-mode)
    )
  (use-package go-rename
    :ensure t)
  )
(provide 'init-go)

然后打开新go文件看是否提示导入project