Hi everyone,
My go version is 1.14.6, and the GO111MODULE is unset. If it is GOPATH mode, gopls works fine, but if in module mode, it doesn't work at all on my macbook, here is what I do:
Create the following layout outside of GOPATH,
~/projects-go
/hello
/foo
foo.go
hello.go
go.mod
hello.go:
package hello
import (
"example.com/hello/foo"
)
// Hello ...
func Hello() string {
foo.Foo()
return "Hello, world."
}
foo.go:
package foo
import "fmt"
func Foo() {
fmt.Println("Foo")
}
go.sum:
module example.com/hello
go 1.14
When I open hello.go in emacs, and hover the mouse to the import line, emacs shows the following message in mini buffer after a few minutes:
I tried to find any debug message why it cannot import the package with following settings, but no luck. I open the page
http://localhost:8080, no useful message, just some memory info, rpc, trace, etc. The file gopls.log was created, but it is empty
(use-package lsp-mode
:ensure t
:init
(setq lsp-gopls-server-args '("-debug" ":8080" "-vv" "-logfile" "/Users/foobar/gopls.log"))
:commands (lsp lsp-deferred)
:hook (go-mode . lsp-deferred)
:config
;; Set up before-save hooks to format buffer and add/delete imports.
;; Make sure you don't have other gofmt/goimports hooks enabled.
(defun lsp-go-install-save-hooks ()
"Comment 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)
)
Thank you very much