gopls 无法补全

GNU Emacs 27.1
Mac OS X 11.2.1

Config

(use-package lsp-mode
  :hook (python-mode . lsp)
  :hook (go-mode . lsp)
  :commands lsp)


(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))
(add-hook go-mode-hook #'lsp-go-install-save-hooks)
which gopls

/Users/matianhe/go/bin/gopls

lsp-log

Command "gopls" is present on the path.
Command "gopls" is present on the path.
Found the following clients for /Users/matianhe/gomuniao/main.go: (server-id gopls, priority 0)
The following clients were selected based on priority: (server-id gopls, priority 0)
2021/02/25 10:31:15 go env for /Users/matianhe/gomuniao
(root /Users/matianhe/gomuniao)
(go version go version go1.15.8 darwin/amd64)
(valid build configuration = true)
(build flags: [])
GOINSECURE=
GONOPROXY=
GOPRIVATE=
GOROOT=/usr/local/Cellar/go/1.15.8/libexec
GOFLAGS=
GONOSUMDB=
GOSUMDB=sum.golang.org
GO111MODULE=
GOPATH=/Users/matianhe/go
GOCACHE=/Users/matianhe/Library/Caches/go-build
GOMODCACHE=/Users/matianhe/go/pkg/mod
GOPROXY=https://proxy.golang.org,direct
GOMOD=/Users/matianhe/gomuniao/go.mod


2021/02/25 10:31:16 go/packages.Load
	snapshot=0
	directory=/Users/matianhe/gomuniao
	query=[builtin matianhe.com/gomuniao/v1/...]
	packages=7

Creating watch for /Users/matianhe/gomuniao
Creating watch for /Users/matianhe/gomuniao/controller
Creating watch for /Users/matianhe/gomuniao/database
Creating watch for /Users/matianhe/gomuniao/model
Creating watch for /Users/matianhe/gomuniao/router
Creating watch for /Users/matianhe/gomuniao/utils

没有补全功能, 保存也没有自动格式化.
image

不清楚lsp-mode怎么用,格式化的话可以使用go-mode


(leaf go-mode
  :straight t
  :hook (before-save-hook . gofmt-before-save)
  :pre-setq
  (gofmt-command . "goimports")
  :config
  (with-eval-after-load 'exec-path-from-shell
    (exec-path-from-shell-copy-envs '("GOPATH"))))

我怀疑你的main.go没加第一行的package main或package name

加了的 package main

GO111MODULE 应该需要打开吧

请问这个最终咋解决的呢?是因为什么呢?

好像是因为emacs不能获取mac 的环境变量 找不到gopls的可执行文件, 装了一个这个包

;; 执行终端命令 (straight-use-package 'exec-path-from-shell) (when (memq window-system '(mac ns x)) (exec-path-from-shell-initialize))