Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: not working inside of $GOPATH #33018

Closed
arthurkiller opened this issue Jul 10, 2019 · 28 comments
Closed

x/tools/gopls: not working inside of $GOPATH #33018

arthurkiller opened this issue Jul 10, 2019 · 28 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls.
Milestone

Comments

@arthurkiller
Copy link

arthurkiller commented Jul 10, 2019

gopls did not recognize the correct path of import file. and gopls can not go to definenation in side the goroot.

  • I am working inside the GOPATH
  • GOMODULE111 is set as default (auto)
  • at go 1.12.7 on OSX
  • did not set GOROOT manually

I install go use the official install package from golang.org for osx.

Problems:

can not recognize fields

  • vim + ale + gopls
  • opened my project

image

can not go to define inside go root code

  • I opened my project in GOPATH
  • locate at `os.Open()
  • go to definitions
  • locate at an internal function
  • go to definitions, failed.

What version of Go are you using (go version)?

$ go version
go version go1.12.7 darwin/amd64

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
arthur@ArthursMacBookPro:~$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/arthur/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/arthur/golang"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/nh/71f5qs9n3dz3v02z77nc86640000gn/T/go-build495324181=/tmp/go-build -gno-record-gcc-switches -fno-common"

env Output

env

Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.o82G0O0EfW/Render
COLORFGBG=7;0
COLORTERM=truecolor
CPPFLAGS=-I/usr/local/opt/llvm/include
ETCDCTL_API=3
GOPATH=/Users/arthur/golang
HOME=/Users/arthur
ITERM_PROFILE=Default
ITERM_SESSION_ID=w0t2p0:FD5B131C-E44F-45FE-9940-4E36328743AE
LANG=en_US.UTF-8
LC_CTYPE=UTF-8
LDFLAGS=-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib
LOGNAME=arthur
PATH=/usr/local/opt/libressl/bin:/usr/local/opt/llvm/bin:/usr/local/opt/curl/bin:/usr/local/sbin:/usr/local/nginx/sbin:/Users/arthur/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/go/bin:/Applications/Wireshark.app/Contents/MacOS
PWD=/Users/arthur
SHELL=/usr/local/bin/fish
SHLVL=1
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.E9l9HnN7sF/Listeners
TERM=xterm-256color
TERM_PROGRAM=iTerm.app
TERM_PROGRAM_VERSION=3.2.9
TERM_SESSION_ID=w0t2p0:FD5B131C-E44F-45FE-9940-4E36328743AE
TMPDIR=/var/folders/nh/71f5qs9n3dz3v02z77nc86640000gn/T/
USER=arthur
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
__CF_USER_TEXT_ENCODING=0x0:25:52
fish_user_paths=/usr/local/opt/libressl/bin /usr/local/opt/llvm/bin /usr/local/opt/curl/bin /usr/local/sbin

What did you do?

  • tried latest gopls
  • tried stable tag of gopls
  • set GOMODULE111=off when build gopls and use gopls
@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Jul 10, 2019
@arthurkiller
Copy link
Author

#32173 @stamblerre here

@odeke-em odeke-em changed the title [Bug] gopls did not work with mixed of GOPATH and GoModule. x/tools/cmd/gopls: gopls did not work with mixed of GOPATH and GoModule. Jul 10, 2019
@gopherbot gopherbot added this to the Unreleased milestone Jul 10, 2019
@arthurkiller
Copy link
Author

@stamblerre ping

@stamblerre
Copy link
Contributor

Can you share a full gopls log?

@arthurkiller
Copy link
Author

suer @stamblerre FYI

gopls version

arthur@ArthursMacBookPro:~$ gopls version
version v0.1.3-cmd.gopls, built in $GOPATH mode

go version

go version go1.12.7 darwin/amd64

env

Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.o82G0O0EfW/Render
COLORFGBG=7;0
COLORTERM=truecolor
CPPFLAGS=-I/usr/local/opt/llvm/include -I/usr/local/opt/llvm/include
ETCDCTL_API=3
GOPATH=/Users/arthur/golang
GOROOT=/usr/local/go
HOME=/Users/arthur
ITERM_PROFILE=Default
ITERM_SESSION_ID=w0t0p0:5D36CBEA-2D63-42EC-B078-FE41A5708C41
LANG=en_US.UTF-8
LC_CTYPE=UTF-8
LDFLAGS=-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib -L/usr/local/opt/llvm/lib
LOGNAME=arthur
PATH=/usr/local/opt/libressl/bin:/usr/local/opt/llvm/bin:/usr/local/opt/curl/bin:/usr/local/sbin:/usr/local/opt/llvm/bin /usr/local/opt/libressl/bin /usr/local/opt/curl/bin /usr/local/sbin:/usr/local/nginx/sbin:/Users/arthur/.cargo/bin:/Users/arthur/golang/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/go/bin:/Applications/Wireshark.app/Contents/MacOS:/Users/arthur/.cargo/bin:/usr/local/nginx/sbin:/Users/arthur/golang/bin
PWD=/Users/arthur
SHELL=/usr/local/bin/fish
SHLVL=2
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.E9l9HnN7sF/Listeners
TERM=screen-256color
TERM_PROGRAM=iTerm.app
TERM_PROGRAM_VERSION=3.2.9
TERM_SESSION_ID=w0t0p0:5D36CBEA-2D63-42EC-B078-FE41A5708C41
TMPDIR=/var/folders/nh/71f5qs9n3dz3v02z77nc86640000gn/T/
TMUX=/tmp//tmux-501/default,7520,16
TMUX_PANE=%119
TMUX_VERSION_MAJOR=2
TMUX_VERSION_MINOR=9
USER=arthur
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
__CF_USER_TEXT_ENCODING=0x0:25:52
fish_user_paths=/usr/local/opt/libressl/bin /usr/local/opt/llvm/bin /usr/local/opt/curl/bin /usr/local/sbin /usr/local/opt/llvm/bin /usr/local/opt/libressl/bin /usr/local/opt/curl/bin /usr/local/sbin

go env

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/arthur/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/arthur/golang"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/nh/71f5qs9n3dz3v02z77nc86640000gn/T/go-build069429814=/tmp/go-build -gno-record-gcc-switches -fno-common"

gopls log

[Trace - 11:44:30 AM] Sending request 'initialize - (1)'.
Params: {"initializationOptions":{},"rootUri":"file:///Users/arthur/golang/src/icode.baidu.com/baidu/personal-code/goclaw","capabilities":{"workspace":{"workspaceFolders":false,"configuration":false,"symbol":{"dynamicRegistration":false},"applyEdit":false,"didChangeConfiguration":{"dynamicRegistration":false}},"textDocument":{"documentSymbol":{"dynamicRegistration":false,"hierarchicalDocumentSymbolSupport":false},"references":{"dynamicRegistration":false},"publishDiagnostics":{"relatedInformation":true},"rename":{"dynamicRegistration":false},"completion":{"completionItem":{"snippetSupport":false,"commitCharactersSupport":false,"preselectSupport":false,"deprecatedSupport":false,"documentationFormat":["plaintext"]},"contextSupport":false,"dynamicRegistration":false},"synchronization":{"didSave":true,"willSaveWaitUntil":false,"willSave":false,"dynamicRegistration":false},"codeAction":{"dynamicRegistration":false},"typeDefinition":{"dynamicRegistration":false},"hover":{"dynamicRegistration":false,"contentFormat":["plaintext"]},"definition":{"dynamicRegistration":false,"linkSupport":false}}},"rootPath":"/Users/arthur/golang/src/icode.baidu.com/baidu/personal-code/goclaw","processId":31871}


[Trace - 11:44:30 AM] Received response 'initialize - (1)' in 54ms.
Params: {"capabilities":{"textDocumentSync":{"openClose":true,"change":2,"save":{}},"hoverProvider":true,"completionProvider":{"triggerCharacters":["."]},"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"codeActionProvider":true,"documentFormattingProvider":true,"renameProvider":true,"documentLinkProvider":{},"typeDefinitionProvider":true,"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":"workspace/didChangeWorkspaceFolders"}}},"custom":null}


[Trace - 11:44:30 AM] Sending notification 'initialized'.
Params: {}


[Trace - 11:44:31 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"Build info\n----------\nversion v0.1.3-cmd.gopls, built in $GOPATH mode\n\nGo info\n-------\ngo version go1.12.7 darwin/amd64\n\nGOARCH=\"amd64\"\nGOBIN=\"\"\nGOCACHE=\"/Users/arthur/Library/Caches/go-build\"\nGOEXE=\"\"\nGOFLAGS=\"\"\nGOHOSTARCH=\"amd64\"\nGOHOSTOS=\"darwin\"\nGOOS=\"darwin\"\nGOPATH=\"/Users/arthur/golang\"\nGOPROXY=\"\"\nGORACE=\"\"\nGOROOT=\"/usr/local/go\"\nGOTMPDIR=\"\"\nGOTOOLDIR=\"/usr/local/go/pkg/tool/darwin_amd64\"\nGCCGO=\"gccgo\"\nCC=\"clang\"\nCXX=\"clang++\"\nCGO_ENABLED=\"1\"\nGOMOD=\"\"\nCGO_CFLAGS=\"-g -O2\"\nCGO_CPPFLAGS=\"\"\nCGO_CXXFLAGS=\"-g -O2\"\nCGO_FFLAGS=\"-g -O2\"\nCGO_LDFLAGS=\"-g -O2\"\nPKG_CONFIG=\"pkg-config\"\nGOGCCFLAGS=\"-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/nh/71f5qs9n3dz3v02z77nc86640000gn/T/go-build002514503=/tmp/go-build -gno-record-gcc-switches -fno-common\"\n"}


[Trace - 11:44:31 AM] Sending notification 'textDocument/didOpen'.
Params: {"textDocument":{"uri":"file:///Users/arthur/golang/src/icode.baidu.com/baidu/personal-code/goclaw/main.go","version":1,"languageId":"go","text":"package main\n\nimport (\n\t\"errors\"\n\t\"flag\"\n\t\"fmt\"\n\t\"math/rand\"\n\t\"net/http\"\n\t_ \"net/http/pprof\"\n\t\"os\"\n\t\"os/signal\"\n\t\"syscall\"\n\t\"time\"\n\n\t\"icode.baidu.com/baidu/go-lib/log\"\n\t\"icode.baidu.com/baidu/personal-code/goclaw/config\"\n\t\"icode.baidu.com/baidu/personal-code/goclaw/version\"\n)\n\nvar (\n\tErrCodeInvalid     = errors.New(\"error return code invalid\")\n\tErrChannelIsFull   = errors.New(\"error in put channel, channel is full\")\n\tErrParseConfigFile = errors.New(\"error in parse config\")\n\tErrInternal        = errors.New(\"error internal\")\n)\n\nfunc main() {\n\tconfpath := flag.String(\"c\", \"./config/config.toml\", \"set config file path\")\n\tlogpath := flag.String(\"l\", \"./log\", \"set log file path\")\n\thelp := flag.Bool(\"h\", false, \"show help information\")\n\tdbg := flag.Bool(\"debug\", false, \"enable go profiling server\")\n\tver := flag.Bool(\"v\", false, \"show version information\")\n\tflag.Parse()\n\tif !flag.Parsed() || *help {\n\t\tflag.Usage()\n\t\tos.Exit(0)\n\t}\n\tif *ver {\n\t\tversion.PrintVersionInfo()\n\t\tos.Exit(0)\n\t}\n\n\t// enable go debug\n\tif *dbg {\n\t\tgo func() { fmt.Println(http.ListenAndServe(\"localhost:6060\", nil)) }()\n\t}\n\n\t// load config\n\tconf, err := config.LoadConfig(*confpath)\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"error in load config, %v\", err)\n\t\tos.Exit(1)\n\t}\n\n\t// prepare resources\n\trand.Seed(time.Now().UnixNano())\n\tInitLogger(*logpath)\n\tInitRegExp(conf.TargetUrl)\n\n\t// new spider and start\n\tspider, err := NewSpider(conf)\n\tif err != nil {\n\t\tlog.Logger.Error(\"error in create spider %v\", err)\n\t\ttime.Sleep(100 * time.Millisecond)\n\t\tos.Exit(1)\n\n\t}\n\n\t// start spider task\n\tspider.Run()\n\n\t// it is required, to work around bug of log4go\n\ttime.Sleep(100 * time.Millisecond)\n\tlog.Logger.Info(\"All jobs done, Bye Bye!\")\n}\n\n// handleSignal nofify signal from system and do the process\nfunc handleSignal(done chan struct{}) {\n\tc := make(chan os.Signal, 1)\n\tsignal.Notify(c, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT)\n\tgo func() {\n\t\tsig := <-c\n\t\tswitch sig {\n\t\tcase syscall.SIGHUP:\n\t\t\t// TODO reload config and do some aditional job\n\t\t\tlog.Logger.Info(\"receive SIGHUP\")\n\t\tcase syscall.SIGQUIT:\n\t\t\t// gracefull stop\n\t\t\tlog.Logger.Info(\"receive SIGQUIT\")\n\t\t\tclose(done)\n\t\tcase syscall.SIGTERM:\n\t\t\t// abort\n\t\t\tlog.Logger.Info(\"receive SIGTERM\")\n\t\t\ttime.Sleep(100 * time.Millisecond)\n\t\t\tos.Exit(0)\n\t\t}\n\t}()\n}\n\nfunc InitLogger(logpath string) {\n\t// init logger. *.log, and *.wf.log The log will automatic rotate, and there is support for backup count\n\t// Init(progName string, levelStr string, logDir string,\n\t//\thasStdOut bool, when string, backupCount int\n\tif err := log.Init(\"spider\", \"INFO\", logpath, true, \"midnight\", 5); err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"error in create log, %v\", err)\n\t\tos.Exit(1)\n\t}\n}\n"}}


[Trace - 11:44:34 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {"uri":"file:///Users/arthur/golang/src/icode.baidu.com/baidu/personal-code/goclaw/main.go","diagnostics":[{"range":{"start":{"line":57,"character":1},"end":{"line":57,"character":11}},"severity":1,"source":"LSP","message":"undeclared name: InitRegExp"},{"range":{"start":{"line":60,"character":16},"end":{"line":60,"character":25}},"severity":1,"source":"LSP","message":"undeclared name: NewSpider"}]}


[Trace - 11:44:38 AM] Sending request 'textDocument/definition - (2)'.
Params: {"textDocument":{"uri":"file:///Users/arthur/golang/src/icode.baidu.com/baidu/personal-code/goclaw/main.go"},"position":{"character":1,"line":57}}


[Error - 11:44:38 AM] send textDocument/definition#2 no object for ident InitRegExp


[Trace - 11:45:02 AM] Sending request 'textDocument/definition - (3)'.
Params: {"textDocument":{"uri":"file:///Users/arthur/golang/src/icode.baidu.com/baidu/personal-code/goclaw/main.go"},"position":{"character":1,"line":57}}


[Error - 11:45:02 AM] send textDocument/definition#3 no object for ident InitRegExp

vim-ale log

(executable check - success) gopls
(started) ['/bin/bash', '-c', '''gopls'' -logfile=/Users/arthur/gopls.log -rpc.trace']

@arthurkiller
Copy link
Author

@stamblerre I am working under GOPATH

@stamblerre
Copy link
Contributor

What is the output of go list -e -json -test -compiled /Users/arthur/golang/src/icode.baidu.com/baidu/personal-code/goclaw?

Where is InitRegExp defined?

@stamblerre
Copy link
Contributor

Also, are you using build tags?

@arthurkiller
Copy link
Author

arthurkiller commented Jul 15, 2019

What is the output of go list -e -json -test -compiled /Users/arthur/golang/src/icode.baidu.com/baidu/personal-code/goclaw?

Where is InitRegExp defined?

In my working dir, under the same package.

Also, are you using build tags?

yes, I use -ldflages

@arthurkiller
Copy link
Author

arthurkiller commented Jul 15, 2019

What is the output of go list -e -json -test -compiled/Users/arthur/golang/src/icode.baidu.com/baidu/personal-code/goclaw?

from stdout

{
	"Dir": "/Users/arthur/golang/src/icode.baidu.com/baidu/personal-code/goclaw",
	"ImportPath": "icode.baidu.com/baidu/personal-code/goclaw",
	"Name": "main",
	"Target": "/Users/arthur/golang/bin/goclaw",
	"Root": "/Users/arthur/golang",
	"Match": [
		"/Users/arthur/golang/src/icode.baidu.com/baidu/personal-code/goclaw"
	],
	"GoFiles": [
		"job.go",
		"main.go",
		"parser.go",
		"spider.go",
		"urlset.go",
		"worker.go"
	],
	"Imports": [
		"bytes",
		"encoding/json",
		"errors",
		"flag",
		"fmt",
		"golang.org/x/text/encoding/simplifiedchinese",
		"golang.org/x/text/transform",
		"icode.baidu.com/baidu/go-lib/log",
		"icode.baidu.com/baidu/personal-code/goclaw/config",
		"icode.baidu.com/baidu/personal-code/goclaw/version",
		"io",
		"io/ioutil",
		"math/rand",
		"net/http",
		"net/http/pprof",
		"net/url",
		"os",
		"os/signal",
		"path",
		"regexp",
		"strings",
		"sync",
		"sync/atomic",
		"syscall",
		"time"
	],
	"Deps": [
		"bufio",
		"bytes",
		"compress/flate",
		"compress/gzip",
		"container/list",
		"context",
		"crypto",
		"crypto/aes",
		"crypto/cipher",
		"crypto/des",
		"crypto/dsa",
		"crypto/ecdsa",
		"crypto/elliptic",
		"crypto/hmac",
		"crypto/internal/randutil",
		"crypto/internal/subtle",
		"crypto/md5",
		"crypto/rand",
		"crypto/rc4",
		"crypto/rsa",
		"crypto/sha1",
		"crypto/sha256",
		"crypto/sha512",
		"crypto/subtle",
		"crypto/tls",
		"crypto/x509",
		"crypto/x509/pkix",
		"encoding",
		"encoding/asn1",
		"encoding/base64",
		"encoding/binary",
		"encoding/gob",
		"encoding/hex",
		"encoding/json",
		"encoding/pem",
		"encoding/xml",
		"errors",
		"flag",
		"fmt",
		"github.com/jehiah/go-strftime",
		"golang.org/x/text/encoding",
		"golang.org/x/text/encoding/internal",
		"golang.org/x/text/encoding/internal/identifier",
		"golang.org/x/text/encoding/simplifiedchinese",
		"golang.org/x/text/transform",
		"gopkg.in/gcfg.v1",
		"gopkg.in/gcfg.v1/scanner",
		"gopkg.in/gcfg.v1/token",
		"gopkg.in/gcfg.v1/types",
		"gopkg.in/warnings.v0",
		"hash",
		"hash/crc32",
		"html",
		"html/template",
		"icode.baidu.com/baidu/go-lib/log",
		"icode.baidu.com/baidu/go-lib/log/log4go",
		"icode.baidu.com/baidu/personal-code/goclaw/config",
		"icode.baidu.com/baidu/personal-code/goclaw/version",
		"internal/bytealg",
		"internal/cpu",
		"internal/fmtsort",
		"internal/nettrace",
		"internal/poll",
		"internal/race",
		"internal/singleflight",
		"internal/syscall/unix",
		"internal/testlog",
		"internal/x/crypto/chacha20poly1305",
		"internal/x/crypto/cryptobyte",
		"internal/x/crypto/cryptobyte/asn1",
		"internal/x/crypto/curve25519",
		"internal/x/crypto/hkdf",
		"internal/x/crypto/internal/chacha20",
		"internal/x/crypto/poly1305",
		"internal/x/net/dns/dnsmessage",
		"internal/x/net/http/httpguts",
		"internal/x/net/http/httpproxy",
		"internal/x/net/http2/hpack",
		"internal/x/net/idna",
		"internal/x/net/route",
		"internal/x/text/secure/bidirule",
		"internal/x/text/transform",
		"internal/x/text/unicode/bidi",
		"internal/x/text/unicode/norm",
		"io",
		"io/ioutil",
		"log",
		"math",
		"math/big",
		"math/bits",
		"math/rand",
		"mime",
		"mime/multipart",
		"mime/quotedprintable",
		"net",
		"net/http",
		"net/http/httptrace",
		"net/http/internal",
		"net/http/pprof",
		"net/textproto",
		"net/url",
		"os",
		"os/exec",
		"os/signal",
		"path",
		"path/filepath",
		"reflect",
		"regexp",
		"regexp/syntax",
		"runtime",
		"runtime/cgo",
		"runtime/internal/atomic",
		"runtime/internal/math",
		"runtime/internal/sys",
		"runtime/pprof",
		"runtime/trace",
		"sort",
		"strconv",
		"strings",
		"sync",
		"sync/atomic",
		"syscall",
		"text/tabwriter",
		"text/template",
		"text/template/parse",
		"time",
		"unicode",
		"unicode/utf16",
		"unicode/utf8",
		"unsafe"
	],
	"TestGoFiles": [
		"job_test.go",
		"parser_test.go",
		"urlset_test.go",
		"worker_test.go"
	],
	"TestImports": [
		"github.com/stretchr/testify/assert",
		"testing",
		"time"
	]
}
{
	"ImportPath": "icode.baidu.com/baidu/personal-code/goclaw.test",
	"Error": {
		"ImportStack": null,
		"Pos": "",
		"Err": "\nparser_test.go:17:1: expected selector or type assertion, found '}'\nparser_test.go:18:6: expected '(', found TestPrepareDir"
	}
}

and stderr got this

arthur@ArthursMacBookPro:~/g/s/i/b/p/goclaw:dev-study$ go list -e -json -test -compiled /Users/arthur/golang/src/icode.baidu.com/baidu/personal-code/goclaw| pbcopy
# runtime/cgo
_cgo_export.c:3:10: fatal error: 'stdlib.h' file not found

@arthurkiller
Copy link
Author

@stamblerre

@stamblerre
Copy link
Contributor

gopls doesn't work well with cgo, and it may have unexpected behavior with build tags (see https://github.com/golang/go/wiki/gopls#known-issues). I'm working on adding additional logging so that we can try to understand this bug a bit better, and I will update this issue when those changes are in.

@arthurkiller
Copy link
Author

I did not use CGO and after I removed build tags error still occoured. @stamblerre

@stamblerre
Copy link
Contributor

@arthurkiller: If you sync to the latest version of gopls (go get -u golang.org/x/tools/gopls@master), you should see more detailed logging. Also, do you see this error is you run gopls on the command line: gopls -v -rpc.trace check /path/to/file.go? Or is the issue only in your editor?

@arthurkiller
Copy link
Author

gopls version

version v0.1.3-cmd.gopls, built in $GOPATH mode

[Trace - 4:50:41 PM] Received notification 'window/logMessage' in 0ms.
Params: {"type":3,"message":"43.752942ms for GOROOT=/usr/local/go GOPATH=/Users/arthur/golang GO111MODULE= PWD=/Users/arthur/golang/src/github.com/distributedio/titan go \"list\" \"-e\" \"-json\" \"-compiled=true\" \"-test=true\" \"-export=false\" \"-deps=true\" \"-find=false\" \"--\" \"builtin\", stderr: \u003c\u003c\u003e\u003e\n"}


[Trace - 4:50:41 PM] Received response 'initialize - (1)' in 0ms.
Params: {"capabilities":{"textDocumentSync":{"openClose":true,"change":2,"save":{}},"hoverProvider":true,"completionProvider":{"triggerCharacters":["."]},"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"codeActionProvider":true,"documentFormattingProvider":true,"renameProvider":true,"documentLinkProvider":{},"typeDefinitionProvider":true,"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":"workspace/didChangeWorkspaceFolders"}}},"custom":null}


[Trace - 4:50:41 PM] Sending notification 'initialize' in 48ms.
Params: {"initializationOptions":{},"rootUri":"file:///Users/arthur/golang/src/github.com/distributedio/titan","capabilities":{"workspace":{"workspaceFolders":false,"configuration":false,"symbol":{"dynamicRegistration":false},"applyEdit":false,"didChangeConfiguration":{"dynamicRegistration":false}},"textDocument":{"documentSymbol":{"dynamicRegistration":false,"hierarchicalDocumentSymbolSupport":false},"references":{"dynamicRegistration":false},"publishDiagnostics":{"relatedInformation":true},"rename":{"dynamicRegistration":false},"completion":{"completionItem":{"snippetSupport":false,"commitCharactersSupport":false,"preselectSupport":false,"deprecatedSupport":false,"documentationFormat":["plaintext"]},"contextSupport":false,"dynamicRegistration":false},"synchronization":{"didSave":true,"willSaveWaitUntil":false,"willSave":false,"dynamicRegistration":false},"codeAction":{"dynamicRegistration":false},"typeDefinition":{"dynamicRegistration":false},"hover":{"dynamicRegistration":false,"contentFormat":["plaintext"]},"definition":{"dynamicRegistration":false,"linkSupport":false}}},"rootPath":"/Users/arthur/golang/src/github.com/distributedio/titan","processId":1613}


[Trace - 4:50:41 PM] Sending notification 'initialized' in 220ms.
Params: {}


[Trace - 4:50:41 PM] Received notification 'window/logMessage' in 0ms.
Params: {"type":3,"message":"Build info\n----------\nversion v0.1.3-cmd.gopls, built in $GOPATH mode\n\nGo info\n-------\ngo version go1.12.7 darwin/amd64\n\nGOARCH=\"amd64\"\nGOBIN=\"\"\nGOCACHE=\"/Users/arthur/Library/Caches/go-build\"\nGOEXE=\"\"\nGOFLAGS=\"\"\nGOHOSTARCH=\"amd64\"\nGOHOSTOS=\"darwin\"\nGOOS=\"darwin\"\nGOPATH=\"/Users/arthur/golang\"\nGOPROXY=\"\"\nGORACE=\"\"\nGOROOT=\"/usr/local/go\"\nGOTMPDIR=\"\"\nGOTOOLDIR=\"/usr/local/go/pkg/tool/darwin_amd64\"\nGCCGO=\"gccgo\"\nCC=\"clang\"\nCXX=\"clang++\"\nCGO_ENABLED=\"1\"\nGOMOD=\"\"\nCGO_CFLAGS=\"-g -O2\"\nCGO_CPPFLAGS=\"\"\nCGO_CXXFLAGS=\"-g -O2\"\nCGO_FFLAGS=\"-g -O2\"\nCGO_LDFLAGS=\"-g -O2\"\nPKG_CONFIG=\"pkg-config\"\nGOGCCFLAGS=\"-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/nh/71f5qs9n3dz3v02z77nc86640000gn/T/go-build985823329=/tmp/go-build -gno-record-gcc-switches -fno-common\"\n"}


[Trace - 4:50:41 PM] Sending notification 'textDocument/didOpen' in 218ms.
Params: {"textDocument":{"uri":"file:///Users/arthur/golang/src/github.com/distributedio/titan/db/zlist.go","version":1,"languageId":"go","text":"package db\n\nimport (\n\t\"bytes\"\n\n\tpb \"github.com/distributedio/titan/db/zlistproto\"\n\t\"github.com/golang/protobuf/proto\"\n)\n\n// GetZList generate List objectm with auto reation, if zip is true, zipped list will be choose\nfunc GetZList(txn *Transaction, metaKey []byte, obj *Object, val []byte) (*ZList, error) {\n\tl := &ZList{\n\t\trawMetaKey: metaKey,\n\t\ttxn:        txn,\n\t}\n\tif err := l.Unmarshal(obj, val); err != nil {\n\t\treturn nil, err\n\t}\n\treturn l, nil\n}\n\n//NewZList create new list object ,the key is not checked for presence\nfunc NewZList(txn *Transaction, key []byte) List {\n\tmetaKey := MetaKey(txn.db, key)\n\tts := Now()\n\tobj := Object{\n\t\tExpireAt:  0,\n\t\tCreatedAt: ts,\n\t\tUpdatedAt: ts,\n\t\tType:      ObjectList,\n\t\tID:        UUID(),\n\t\tEncoding:  ObjectEncodingZiplist,\n\t}\n\tl := &ZList{\n\t\tObject:     obj,\n\t\tvalue:      pb.Zlistvalue{},\n\t\trawMetaKey: metaKey,\n\t\ttxn:        txn,\n\t}\n\tPutZList(txn, metaKey)\n\treturn l\n}\n\n// ZList ZListMeta defined zip list, with only objectMeta info.\ntype ZList struct {\n\tObject\n\trawMetaKey []byte\n\tvalue      pb.Zlistvalue //[][]byte\n\ttxn        *Transaction\n}\n\n//Exist if zlist is  effective return true ,otherwise return false\nfunc (l *ZList) Exist() bool {\n\tif l.value.V == nil {\n\t\treturn false\n\t}\n\treturn true\n}\n\n// Marshal encode zlist into byte slice\nfunc (l *ZList) Marshal() ([]byte, error) {\n\tb := EncodeObject(&l.Object)\n\tmeta, err := proto.Marshal(&l.value)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn append(b, meta...), nil\n}\n\n// zlistCommit try to marshal zlist values and then do set\nfunc (l *ZList) zlistCommit() error {\n\tb, err := l.Marshal()\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn l.txn.t.Set(l.rawMetaKey, b)\n}\n\n// Unmarshal parse meta data into meta field\nfunc (l *ZList) Unmarshal(obj *Object, b []byte) (err error) {\n\tl.Object = *obj\n\tif err := proto.Unmarshal(b[ObjectEncodingLength:], &l.value); err != nil {\n\t\treturn err\n\t}\n\treturn nil\n}\n\n// Length return z list length\nfunc (l *ZList) Length() int64 { return int64(len(l.value.V)) }\n\n//LPush append new elements to the object values\nfunc (l *ZList) LPush(data ...[]byte) (err error) {\n\tcv := make([][]byte, len(data), len(data)+len(l.value.V))\n\n\tj := 0 // data->[] lpush\n\tfor i := len(data) - 1; i >= 0; i-- {\n\t\tcv[j] = data[i]\n\t\tj++\n\t}\n\tcv = append(cv, l.value.V...)\n\tl.value.V = cv\n\treturn l.zlistCommit()\n}\n\n// RPush insert data befroe object values\nfunc (l *ZList) RPush(data ...[]byte) (err error) {\n\tl.value.V = append(l.value.V, data...) // []<-data rpush\n\treturn l.zlistCommit()\n}\n\n// Set the index object with given value, return ErrIndex on out of range error.\nfunc (l *ZList) Set(n int64, data []byte) error {\n\tif n < 0 {\n\t\tn = int64(len(l.value.V)) + n\n\t}\n\tif n < 0 || n >= int64(len(l.value.V)) {\n\t\treturn ErrOutOfRange\n\t}\n\tl.value.V[n] = data\n\treturn l.zlistCommit()\n}\n\n// Insert v before/after pivot in zlist\nfunc (l *ZList) Insert(pivot, v []byte, before bool) error {\n\tindex := -1\n\tfor index = range l.value.V {\n\t\tif bytes.Equal(l.value.V[index], pivot) {\n\t\t\tbreak\n\t\t}\n\t}\n\t// if pivot not exist, index will reach len(l.valus.V)\n\tif index == len(l.value.V) {\n\t\treturn ErrKeyNotFound\n\t}\n\n\tif !before {\n\t\tindex++\n\t}\n\n\tcv := make([][]byte, len(l.value.V)+1, len(l.value.V)+1)\n\tcopy(cv[:index], l.value.V[:index])\n\tcv[index] = v\n\tcopy(cv[index+1:], l.value.V[index:])\n\n\tl.value.V = cv\n\treturn l.zlistCommit()\n}\n\n//Index return the value at index\nfunc (l *ZList) Index(n int64) (data []byte, err error) {\n\tif n < 0 {\n\t\tn += int64(len(l.value.V))\n\t}\n\tif n < 0 || n >= int64(len(l.value.V)) {\n\t\treturn nil, ErrOutOfRange\n\t}\n\treturn l.value.V[n], nil\n}\n\n// LPop return and delete the left most element\nfunc (l *ZList) LPop() (data []byte, err error) {\n\tv := l.value.V[0]\n\tl.value.V = l.value.V[1:]\n\n\t//destory on last key\n\tif len(l.value.V) == 0 {\n\t\treturn v, l.Destory()\n\t}\n\treturn v, l.zlistCommit()\n}\n\n// RPop return and delete the right most element\nfunc (l *ZList) RPop() ([]byte, error) {\n\tv := l.value.V[len(l.value.V)-1]\n\tl.value.V = l.value.V[:len(l.value.V)-1]\n\t//destory on last key\n\tif len(l.value.V) == 0 {\n\t\treturn v, l.Destory()\n\t}\n\treturn v, l.zlistCommit()\n}\n\n// Range return the elements in [left, right]\nfunc (l *ZList) Range(left, right int64) (value [][]byte, err error) {\n\tif right < 0 {\n\t\tif right = int64(len(l.value.V)) + right; right < 0 {\n\t\t\treturn [][]byte{}, nil\n\t\t}\n\t}\n\tif left < 0 {\n\t\tif left = int64(len(l.value.V)) + left; left < 0 {\n\t\t\tleft = 0\n\t\t}\n\t}\n\tif right >= int64(len(l.value.V)) {\n\t\tright = int64(len(l.value.V) - 1)\n\t}\n\t// return 0 elements\n\tif left > right {\n\t\treturn [][]byte{}, nil\n\t}\n\treturn l.value.V[left : right+1], nil\n}\n\n// LTrim get keys from start index to stop index\nfunc (l *ZList) LTrim(start int64, stop int64) error {\n\tif start < 0 {\n\t\tif start = int64(len(l.value.V)) + start; start < 0 {\n\t\t\tstart = 0\n\t\t}\n\t}\n\tif stop < 0 {\n\t\tstop += int64(len(l.value.V))\n\t}\n\tif stop > int64(len(l.value.V)-1) {\n\t\tstop = int64(len(l.value.V) - 1)\n\t}\n\n\tif start > stop {\n\t\treturn l.Destory()\n\t}\n\n\tl.value.V = l.value.V[start : stop+1]\n\treturn l.zlistCommit()\n}\n\n// LRem begin delete the count of n key from v\nfunc (l *ZList) LRem(v []byte, n int64) (int, error) {\n\tcv := make([][]byte, len(l.value.V), len(l.value.V))\n\tcount := 0\n\tif n < 0 { // delete from tail to head, then trim the cv\n\t\tj := len(l.value.V) - 1\n\t\tfor i := j; i >= 0 && count < int(n); i-- {\n\t\t\tif !bytes.Equal(l.value.V[i], v) {\n\t\t\t\tcv[j] = l.value.V[i]\n\t\t\t\tj--\n\t\t\t} else {\n\t\t\t\tcount++\n\t\t\t}\n\t\t}\n\t\tl.value.V = cv[j+1:]\n\t} else if n == 0 {\n\t\tj := 0\n\t\tfor i := range l.value.V {\n\t\t\tif !bytes.Equal(l.value.V[i], v) {\n\t\t\t\tcv[j] = l.value.V[i]\n\t\t\t\tj++\n\t\t\t} else {\n\t\t\t\tcount++\n\t\t\t}\n\t\t}\n\t\tl.value.V = cv[:j]\n\t} else {\n\t\tj := 0\n\t\tfor i := j; i < len(l.value.V) && count < int(n); i-- {\n\t\t\tif !bytes.Equal(l.value.V[i], v) {\n\t\t\t\tcv[j] = l.value.V[i]\n\t\t\t\tj++\n\t\t\t} else {\n\t\t\t\tcount++\n\t\t\t}\n\t\t}\n\t\tl.value.V = cv[:j]\n\t}\n\treturn count, l.zlistCommit()\n}\n\n// Destory the zlist\nfunc (l *ZList) Destory() error {\n\t// delete the meta data\n\treturn l.txn.t.Delete(l.rawMetaKey)\n}\n\n// TransferToLList create an llist and put values into llist from zlist, LList will inheritance\n// information from ZList\nfunc (l *ZList) TransferToLList(dbns []byte, dbid DBID, key []byte) (*LList, error) {\n\tll := &LList{\n\t\tLListMeta: LListMeta{\n\t\t\tObject: Object{\n\t\t\t\tExpireAt:  0,\n\t\t\t\tCreatedAt: l.CreatedAt,\n\t\t\t\tUpdatedAt: l.UpdatedAt,\n\t\t\t\tType:      ObjectList,\n\t\t\t\tID:        l.ID,\n\t\t\t\tEncoding:  ObjectEncodingLinkedlist,\n\t\t\t},\n\t\t\tLen:    0,\n\t\t\tLindex: 0,\n\t\t\tRindex: 0,\n\t\t},\n\t\ttxn:        l.txn,\n\t\trawMetaKey: l.rawMetaKey,\n\t}\n\tdataKeyPrefix := []byte{}\n\tdataKeyPrefix = append(dataKeyPrefix, dbns...)\n\tdataKeyPrefix = append(dataKeyPrefix, ':')\n\tdataKeyPrefix = append(dataKeyPrefix, dbid.Bytes()...)\n\tdataKeyPrefix = append(dataKeyPrefix, ':', 'D', ':')\n\tdataKeyPrefix = append(dataKeyPrefix, ll.Object.ID...)\n\tll.rawDataKeyPrefix = append(dataKeyPrefix, ':')\n\treturn ll, ll.RPush(l.value.V...)\n}\n"}}


[Trace - 4:50:43 PM] Received notification 'window/logMessage' in 0ms.
Params: {"type":3,"message":"2.301407988s for GOROOT=/usr/local/go GOPATH=/Users/arthur/golang GO111MODULE= PWD=/Users/arthur/golang/src/github.com/distributedio/titan go \"list\" \"-e\" \"-json\" \"-compiled=true\" \"-test=true\" \"-export=false\" \"-deps=true\" \"-find=false\" \"--\" \"/Users/arthur/golang/src/github.com/distributedio/titan/db\", stderr: \u003c\u003c# runtime/cgo\n_cgo_export.c:3:10: fatal error: 'stdlib.h' file not found\n\u003e\u003e\n"}


[Trace - 4:50:44 PM] Received notification 'window/logMessage' in 0ms.
Params: {"type":3,"message":"216.11981ms for GOROOT=/usr/local/go GOPATH=/Users/arthur/golang GO111MODULE= PWD=/Users/arthur/golang/src/github.com/distributedio/titan go \"list\" \"-e\" \"-json\" \"-compiled=true\" \"-test=true\" \"-export=false\" \"-deps=true\" \"-find=false\" \"--\" \"/Users/arthur/golang/src/github.com/distributedio/titan/db/zlist.go\", stderr: \u003c\u003c\u003e\u003e\n"}


[Trace - 4:50:44 PM] Received notification 'window/logMessage' in 0ms.
Params: {"type":3,"message":"go/packages.Load\n\tpackages = 1"}


[Trace - 4:50:44 PM] Received notification 'window/logMessage' in 0ms.
Params: {"type":3,"message":"go/packages.Load\n\tpackage = command-line-arguments\n\tfiles = [/Users/arthur/golang/src/github.com/distributedio/titan/db/zlist.go]"}


[Trace - 4:50:44 PM] Received notification 'textDocument/publishDiagnostics' in 0ms.
Params: {"uri":"file:///Users/arthur/golang/src/github.com/distributedio/titan/db/zlist.go","diagnostics":[{"range":{"start":{"line":10,"character":19},"end":{"line":10,"character":30}},"severity":1,"source":"LSP","message":"undeclared name: Transaction"},{"range":{"start":{"line":10,"character":53},"end":{"line":10,"character":59}},"severity":1,"source":"LSP","message":"undeclared name: Object"},{"range":{"start":{"line":45,"character":1},"end":{"line":45,"character":7}},"severity":1,"source":"LSP","message":"undeclared name: Object"},{"range":{"start":{"line":48,"character":13},"end":{"line":48,"character":24}},"severity":1,"source":"LSP","message":"undeclared name: Transaction"},{"range":{"start":{"line":22,"character":19},"end":{"line":22,"character":30}},"severity":1,"source":"LSP","message":"undeclared name: Transaction"},{"range":{"start":{"line":22,"character":44},"end":{"line":22,"character":48}},"severity":1,"source":"LSP","message":"undeclared name: List"},{"range":{"start":{"line":79,"character":31},"end":{"line":79,"character":37}},"severity":1,"source":"LSP","message":"undeclared name: Object"},{"range":{"start":{"line":275,"character":50},"end":{"line":275,"character":54}},"severity":1,"source":"LSP","message":"undeclared name: DBID"},{"range":{"start":{"line":275,"character":70},"end":{"line":275,"character":75}},"severity":1,"source":"LSP","message":"undeclared name: LList"},{"range":{"start":{"line":276,"character":8},"end":{"line":276,"character":14}},"severity":1,"source":"LSP","message":"undeclared name: LList"},{"range":{"start":{"line":277,"character":13},"end":{"line":277,"character":23}},"severity":1,"source":"LSP","message":"undeclared name: LListMeta"},{"range":{"start":{"line":278,"character":11},"end":{"line":278,"character":18}},"severity":1,"source":"LSP","message":"undeclared name: Object"},{"range":{"start":{"line":280,"character":17},"end":{"line":280,"character":26}},"severity":1,"source":"LSP","message":"l.CreatedAt undefined (type *ZList has no field or method CreatedAt)"},{"range":{"start":{"line":281,"character":17},"end":{"line":281,"character":26}},"severity":1,"source":"LSP","message":"l.UpdatedAt undefined (type *ZList has no field or method UpdatedAt)"},{"range":{"start":{"line":282,"character":15},"end":{"line":282,"character":25}},"severity":1,"source":"LSP","message":"undeclared name: ObjectList"},{"range":{"start":{"line":283,"character":17},"end":{"line":283,"character":19}},"severity":1,"source":"LSP","message":"l.ID undefined (type *ZList has no field or method ID)"},{"range":{"start":{"line":284,"character":15},"end":{"line":284,"character":39}},"severity":1,"source":"LSP","message":"undeclared name: ObjectEncodingLinkedlist"},{"range":{"start":{"line":154,"character":14},"end":{"line":154,"character":27}},"severity":1,"source":"LSP","message":"undeclared name: ErrOutOfRange"},{"range":{"start":{"line":132,"character":9},"end":{"line":132,"character":23}},"severity":1,"source":"LSP","message":"undeclared name: ErrKeyNotFound"},{"range":{"start":{"line":116,"character":9},"end":{"line":116,"character":22}},"severity":1,"source":"LSP","message":"undeclared name: ErrOutOfRange"},{"range":{"start":{"line":81,"character":29},"end":{"line":81,"character":49}},"severity":1,"source":"LSP","message":"undeclared name: ObjectEncodingLength"},{"range":{"start":{"line":61,"character":6},"end":{"line":61,"character":18}},"severity":1,"source":"LSP","message":"undeclared name: EncodeObject"},{"range":{"start":{"line":62,"character":1},"end":{"line":62,"character":5}},"severity":1,"source":"LSP","message":"meta declared but not used"},{"range":{"start":{"line":23,"character":12},"end":{"line":23,"character":19}},"severity":1,"source":"LSP","message":"undeclared name: MetaKey"},{"range":{"start":{"line":24,"character":7},"end":{"line":24,"character":10}},"severity":1,"source":"LSP","message":"undeclared name: Now"},{"range":{"start":{"line":25,"character":8},"end":{"line":25,"character":15}},"severity":1,"source":"LSP","message":"undeclared name: Object"},{"range":{"start":{"line":29,"character":13},"end":{"line":29,"character":23}},"severity":1,"source":"LSP","message":"undeclared name: ObjectList"},{"range":{"start":{"line":30,"character":13},"end":{"line":30,"character":17}},"severity":1,"source":"LSP","message":"undeclared name: UUID"},{"range":{"start":{"line":31,"character":13},"end":{"line":31,"character":34}},"severity":1,"source":"LSP","message":"undeclared name: ObjectEncodingZiplist"},{"range":{"start":{"line":39,"character":1},"end":{"line":39,"character":9}},"severity":1,"source":"LSP","message":"undeclared name: PutZList"}]}


[Trace - 4:50:47 PM] Received response 'textDocument/definition - (2)' in 0ms.
Params: {}


[Trace - 4:50:47 PM] Sending notification 'textDocument/definition' in 1ms.
Params: {"textDocument":{"uri":"file:///Users/arthur/golang/src/github.com/distributedio/titan/db/zlist.go"},"position":{"character":25,"line":10}}



@arthurkiller
Copy link
Author

@stamblerre FYI

@arthurkiller
Copy link
Author

image

@stamblerre
Copy link
Contributor

Thank you - based on the logs, it seems like we are treating your package as if it were just a single file. For gopls you have to set a workspace root (#32394), so that gopls knows where to find the go.mod file. I'm not sure how to configure that with your editor, but that may be the problem here.

@arthurkiller
Copy link
Author

arthurkiller commented Jul 23, 2019

@stamblerre Thx a lot.
BTW, how to set the workspace root from cmd line?

@stamblerre
Copy link
Contributor

I'm not sure how to do it for your particular set up - you may want to check on that repo. We have information for some editors here: https://github.com/golang/go/wiki/gopls#installation.

Also, #33107 (comment) may also be helpful to you, as I see a similar error in your logs.

@stamblerre
Copy link
Contributor

@arthurkiller: Just to follow up, is this issue resolved for you?

@arthurkiller
Copy link
Author

@stamblerre sorry to say not at all.

@stamblerre
Copy link
Contributor

Do you see the same errors when you run gopls on the command line? What is the output of gopls -rpc.trace -v check /path/to/file.go?

@stamblerre stamblerre changed the title x/tools/cmd/gopls: gopls did not work with mixed of GOPATH and GoModule. x/tools/gopls: not working inside of $GOPATH Aug 2, 2019
@arthurkiller
Copy link
Author

FYI @stamblerre

2019/08/05 11:06:00 Info:146.084107ms for GOROOT= GOPATH=/Users/arthur/golang GO111MODULE= PWD=/Users/arthur/golang/src/github.com/arthurkiller/rollingwriter go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "builtin", stderr: <<>>
2019/08/05 11:06:02 Info:Build info
----------
version v0.1.3-cmd.gopls, built in $GOPATH mode

Go info
-------
go version go1.12.7 darwin/amd64

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/arthur/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/arthur/golang"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/nh/71f5qs9n3dz3v02z77nc86640000gn/T/go-build591601686=/tmp/go-build -gno-record-gcc-switches -fno-common"
2019/08/05 11:06:04 Info:1.994433875s for GOROOT= GOPATH=/Users/arthur/golang GO111MODULE= PWD=/Users/arthur/golang/src/github.com/arthurkiller/rollingwriter go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/Users/arthur/golang/src/github.com/arthurkiller/rollingwriter", stderr: <<# runtime/cgo
_cgo_export.c:3:10: fatal error: 'stdlib.h' file not found
>>
2019/08/05 11:06:04 Info:131.15536ms for GOROOT= GOPATH=/Users/arthur/golang GO111MODULE= PWD=/Users/arthur/golang/src/github.com/arthurkiller/rollingwriter go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/Users/arthur/golang/src/github.com/arthurkiller/rollingwriter/manager.go", stderr: <<>>
2019/08/05 11:06:04 Info:go/packages.Load
	packages = 1
2019/08/05 11:06:04 Info:go/packages.Load
	package = command-line-arguments
	files = [/Users/arthur/golang/src/github.com/arthurkiller/rollingwriter/manager.go]
/Users/arthur/golang/src/github.com/arthurkiller/rollingwriter/manager.go:26:20-26: undeclared name: Config
/Users/arthur/golang/src/github.com/arthurkiller/rollingwriter/manager.go:26:29-36: undeclared name: Manager
/Users/arthur/golang/src/github.com/arthurkiller/rollingwriter/manager.go:89:34-40: undeclared name: Config
/Users/arthur/golang/src/github.com/arthurkiller/rollingwriter/manager.go:129:37-43: undeclared name: Config
/Users/arthur/golang/src/github.com/arthurkiller/rollingwriter/manager.go:39:7-21: undeclared name: WithoutRolling
/Users/arthur/golang/src/github.com/arthurkiller/rollingwriter/manager.go:41:7-18: undeclared name: TimeRolling
/Users/arthur/golang/src/github.com/arthurkiller/rollingwriter/manager.go:48:7-20: undeclared name: VolumeRolling
/Users/arthur/golang/src/github.com/arthurkiller/rollingwriter/manager.go:50:22-33: undeclared name: LogFilePath
/Users/arthur/golang/src/github.com/arthurkiller/rollingwriter/manager.go:54:37-46: undeclared name: Precision
/Users/arthur/golang/src/github.com/arthurkiller/rollingwriter/manager.go:55:16-27: undeclared name: LogFilePath

@arthurkiller
Copy link
Author

And you can get the code from my repo.

github.com/arthurkiller/rollingwriter

@stamblerre
Copy link
Contributor

net/http depends on packages that have cgo code. It looks like these are runtime/cgo, net, and crypto/x509.

If the -compiled flag is passed to go list, listed packages and their dependencies are compiled, and the paths to the compiled .a files are included in the output. If cgo is enabled, a C compiler is required to build those packages. I'm guessing gopls uses the compiled .a files for type information, but even if it didn't, cgo may be required for type checking.

@bwmarrin Have you tried disabling cgo by setting CGO_ENABLED=0 in your environment? I don't believe cgo is disabled automatically depending on whether there is a C compiler in PATH.

@arthurkiller: I believe this quote from #33018 (comment) should explain your problem. Can you try setting CGO_ENABLED=0 in your environment? Do you have a C compiler in your $PATH?

@arthurkiller
Copy link
Author

@stamblerre yes and yes. I have clang in my path.

setting CGO_ENABLED=0 works for me. But I still think this is a bug about gopls.

@stamblerre
Copy link
Contributor

Indeed we do need to fix the behavior. #33462 will track this, and you can follow along for updates there. Thanks for bearing with me while we diagnosed this issue!

@arthurkiller
Copy link
Author

LOL you too, thx for your patience

@golang golang locked and limited conversation to collaborators Aug 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls.
Projects
None yet
Development

No branches or pull requests

3 participants