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: You are outside of a module and outside of $GOPATH/src #45015

Closed
mingulov opened this issue Mar 15, 2021 · 6 comments
Closed

x/tools/gopls: You are outside of a module and outside of $GOPATH/src #45015

mingulov opened this issue Mar 15, 2021 · 6 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@mingulov
Copy link

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

$ go version
go version go1.16.2 linux/amd64

Does this issue reproduce with the latest release?

Yes. (gopls 0.6.6 and gopls 0.6.7-pre.1)

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user/.cache/go-build"
GOENV="/home/user/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/user/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/user/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.2"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build556413977=/tmp/go-build -gno-record-gcc-switches"
gopls -v version Output
Build info
----------
golang.org/x/tools/gopls v0.6.7
    golang.org/x/tools/gopls@v0.6.7-pre.1 h1:c1imMWz2YQhJo80BaWdhY5NneVrJgUTDvD8aHE6qiQw=
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/google/go-cmp@v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/mod@v0.4.1 h1:Kvvh58BN8Y9/lBi7hTekvtMpm07eUZ0ck5pRHpsMWrY=
    golang.org/x/sync@v0.0.0-20201020160332-67f06af15bc9 h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck=
    golang.org/x/sys@v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
    golang.org/x/tools@v0.1.1-0.20210310201602-f3da8934356a h1:wtsfTQvoSxHhNCmmTXFd6D3/uXlQSa9SfUZbHgvlPUA=
    golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
    honnef.co/go/tools@v0.1.1 h1:EVDuO03OCZwpV2t/tLLxPmPiomagMoBOgfPt0FM+4IY=
    mvdan.cc/gofumpt@v0.1.0 h1:hsVv+Y9UsZ/mFZTxJZuHVI6shSQCtzZ11h1JEFPAZLw=
    mvdan.cc/xurls/v2@v2.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=
Visual Studio Code version Output
VS Code on Windows, remote session to Ubuntu 20.04.
Version: 1.54.2 (user setup)
Commit: fd6f3bce
Date: 2021-03-11T00:56
Electron: 11.3.0
Chrome: 87.0.4280.141
Node.js: 12.18.3
V8: 8.7.220.31-electron.0
OS: Windows_NT x64 10.0.19041

What did you do?

I just open .go file in Visual Studio Code (with Go extension).

What did you expect to see?

I do not see any strange warnings. Sometime ago (month?..) it worked fine, but I am not sure which version I had at that time.

What did you see instead?

I see a warning in statusbar "Error loading workspace: You are outside of a module and outside of $GOPATH/src" - which is too wide, it just prevents me to see the current line/column in the status bar + some other info there. If it would be possible just suppress this warning from showing in status bar even if it will be really there - it would be nice for me.

Screenshot and behaviour can be checked in the already closed #44363

gopls (server) logs Output
[Trace - 12:54:17.676 PM] Sending notification 'textDocument/didOpen'.
Params: {"textDocument":{"uri":"file:///home/user/src/prj/functions/productoperations/getproduct/handler.go","languageId":"go","version":45,"text":"package function\n\nimport (\n\t\"encoding/json\"\n\t\"errors\"\n\t\"net/http\"\n\t\"os\"\n\n\t\"github.com/go-kit/kit/log\"\n\t\"github.com/go-kit/kit/log/level\"\n\t\"github.com/google/uuid\"\n\tproductdb \"gitlab.com/co/cs/u/prj/common.git/pkg/pdb\"\n)\n\nvar (\n\tlogger      log.Logger\n\tproductconf productdb.DatabaseConfiguration\n\tstore       productdb.DBStore\n)\n\n// ProductList a list of products\ntype ProductList struct {\n\tItems []productdb.Product `json:\"items\"`\n}\n\nfunc init() {\n\tlogger = log.NewJSONLogger(log.NewSyncWriter(os.Stderr))\n\tvar lev level.Option\n\tlogLevel := os.Getenv(\"LOGLEVEL\")\n\n\tswitch logLevel {\n\tcase \"DEBUG\":\n\t\tlev = level.AllowDebug()\n\tcase \"INFO\":\n\t\tlev = level.AllowInfo()\n\tcase \"WARN\":\n\t\tlev = level.AllowWarn()\n\tcase \"ALL\":\n\t\tlev = level.AllowAll()\n\tcase \"NONE\":\n\t\tlev = level.AllowNone()\n\tcase \"ERROR\":\n\t\tlev = level.AllowError()\n\tdefault:\n\t\tlev = level.AllowInfo()\n\t}\n\tlogger = level.NewFilter(logger, lev)\n\tlogger = log.With(logger, \"ts\", log.DefaultTimestampUTC)\n\tlogger = log.With(logger, \"caller\", log.DefaultCaller)\n\t// Log this fuction\n\tlogme := log.With(logger, \"method\", \"init\")\n\t_ = level.Info(logme).Log(\"desc\", \"App Info\", \"Version\", AppVersion, \"Version ID\", AppVersionID, \"Build date\", buildDate())\n\t_ = level.Debug(logme).Log(\"DBinitstarted\", true)\n\n\t// Create product DB store with logger\n\tvar err error\n\n\terr = productdb.GetConfig(&productconf, logger)\n\tif err != nil {\n\t\t_ = level.Error(logme).Log(\"desc\", \"The DB init failed\", \"detailed\", err)\n\t\tos.Exit(1)\n\t}\n\tstore, _ = productdb.New(productconf, logger)\n\terr = store.Conn(true)\n\tif err != nil {\n\t\t_ = level.Error(logme).Log(\"desc\", \"The DB initialization failed\", \"detailed\", err)\n\t\tos.Exit(1)\n\t}\n}\n\n// Handle handler\nfunc Handle(w http.ResponseWriter, r *http.Request) {\n\t// Log this fuction\n\txReqid := r.Header.Get(\"X-Request-Id\")\n\tlogme := log.With(logger, \"method\", \"Handle\", \"X-Request-Id\", xReqid)\n\n\tvar outData []byte\n\tvar err error\n\n\t// request '.../products/?id=' is a request for get_product, not get_all_products\n\tids, ok := r.URL.Query()[\"id\"]\n\tif ok {\n\t\tid, err := uuid.Parse(ids[0])\n\t\tif err != nil {\n\t\t\t_ = level.Error(logme).Log(\"desc\", \"Uuid parsing\", \"detailed\", err)\n\t\t\thttp.Error(w, err.Error(), http.StatusBadRequest)\n\t\t\treturn\n\t\t}\n\t\t// Filter or obfuscate some of the values.\n\t\tobsValue := \"**********************\"\n\t\tproduct, err := store.GetProduct(id)\n\t\tif err != nil {\n\t\t\tif errors.Is(err, productdb.ErrRecordNotFound) {\n\t\t\t\t_ = level.Debug(logme).Log(\"desc\", \"Product is not found\", \"id\", id)\n\t\t\t\thttp.Error(w, err.Error(), http.StatusNotFound)\n\t\t\t\treturn\n\t\t\t}\n\t\t\t_ = level.Error(logme).Log(\"desc\", \"DB get product failed\", \"id\", id, \"detailed\", err)\n\t\t\thttp.Error(w, err.Error(), http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\n\t\t// Obfuscate AES , PASSPHRASE and private key values\n\t\tfor i := range product.SoftwareKeys {\n\t\t\tkey := &product.SoftwareKeys[i]\n\t\t\tif key.AESKey != \"\" {\n\t\t\t\tkey.AESKey = obsValue\n\t\t\t}\n\t\t\tif key.PassPhrase != \"\" {\n\t\t\t\tkey.PassPhrase = obsValue\n\t\t\t}\n\t\t\tif key.PrivateKey != \"\" {\n\t\t\t\tkey.PrivateKey = obsValue\n\t\t\t}\n\t\t}\n\n\t\t// Filter out SRKTable, SRKHash and efusebits. They are distributed using the client. Not shown in the product json.\n\t\tfor i := len(product.KeyValuePairs) - 1; i >= 0; i-- {\n\t\t\tname := &product.KeyValuePairs[i].Name\n\t\t\tif name != nil && (*name == productdb.SRKHash || *name == productdb.SRKTable || *name == productdb.EFusePPKBits) {\n\t\t\t\tproduct.KeyValuePairs = append(product.KeyValuePairs[:i],\n\t\t\t\t\tproduct.KeyValuePairs[i+1:]...)\n\t\t\t}\n\t\t}\n\n\t\tjs, err := json.Marshal(product)\n\t\tif err != nil {\n\t\t\t_ = level.Error(logme).Log(\"desc\", \"Encoding error\", \"detailed\", err)\n\t\t\thttp.Error(w, err.Error(), http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\t\toutData = js\n\t} else {\n\t\t// get product list with deep info to load product operations also\n\t\tproducts, err := store.GetProductList(true)\n\t\tif err != nil {\n\t\t\t_ = level.Error(logme).Log(\"desc\", \"DB get product list failed\", \"detailed\", err)\n\t\t\thttp.Error(w, err.Error(), http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\t\t_ = level.Debug(logme).Log(\"product list - length\", len(products))\n\n\t\t// Go trough all products and get the product operations strip everything else.\n\t\tresprods := make([]productdb.Product, 0, len(products))\n\t\tfor _, product := range products {\n\t\t\tresops := make([]productdb.ProductOperation, 0, len(product.ProductOperations))\n\t\t\tfor _, c := range product.ProductOperations {\n\t\t\t\tname := c.Name\n\t\t\t\tdesc := c.Description\n\t\t\t\toptype := c.OperationType\n\t\t\t\toper := productdb.ProductOperation{\n\t\t\t\t\tID:            c.ID,\n\t\t\t\t\tName:          name,\n\t\t\t\t\tDescription:   desc,\n\t\t\t\t\tOperationType: optype,\n\t\t\t\t}\n\t\t\t\tresops = append(resops, oper)\n\t\t\t}\n\n\t\t\tid := product.ID\n\t\t\tname := product.Name\n\t\t\tdesc := product.Description\n\t\t\tprod := productdb.Product{\n\t\t\t\tID:                id,\n\t\t\t\tName:              name,\n\t\t\t\tDescription:       desc,\n\t\t\t\tProductOperations: resops,\n\t\t\t}\n\t\t\tresprods = append(resprods, prod)\n\t\t}\n\n\t\tproductlist := ProductList{\n\t\t\tItems: resprods,\n\t\t}\n\t\tjs, err := json.Marshal(productlist)\n\t\tif err != nil {\n\t\t\t_ = level.Error(logme).Log(\"desc\", \"Encoding error\", \"detailed\", err)\n\t\t\thttp.Error(w, err.Error(), http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\n\t\toutData = js\n\t}\n\tw.Header().Set(\"Content-Type\", \"application/json\")\n\tw.WriteHeader(http.StatusOK)\n\tif len(outData) > 0 {\n\t\t_, err = w.Write(outData)\n\t\tif err != nil {\n\t\t\t_ = level.Error(logme).Log(\"desc\", \"Error serializing header to wire format\", \"length\", len(outData))\n\t\t\t// The desired behaviour here should be looked at\n\t\t\t// https://stackoverflow.com/questions/43976140/check-errors-when-calling-http-responsewriter-write\n\t\t}\n\t}\n\t_ = level.Info(logme).Log(\"desc\", \"SUCCESS\", \"length\", len(outData))\n}\n"}}

[Trace - 12:54:17.677 PM] Sending request 'textDocument/documentLink - (1)'.
Params: {"textDocument":{"uri":"file:///home/user/src/prj/functions/productoperations/getproduct/handler.go"}}

[Trace - 12:54:17.677 PM] Sending request 'textDocument/codeAction - (2)'.
Params: {"textDocument":{"uri":"file:///home/user/src/prj/functions/productoperations/getproduct/handler.go"},"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":0}},"context":{"diagnostics":[]}}

[Trace - 12:54:17.677 PM] Sending request 'textDocument/documentSymbol - (3)'.
Params: {"textDocument":{"uri":"file:///home/user/src/prj/functions/productoperations/getproduct/handler.go"}}

[Trace - 12:54:17.677 PM] Received request 'client/registerCapability - (7)'.
Params: {"registrations":[{"id":"workspace/didChangeWatchedFiles-1","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"**/*.{go,mod,sum}","kind":7},{"globPattern":"{/home/user/src/prj/functions,/home/user/src/prj/functions/productoperations,/home/user/src/prj/functions/productoperations/getproduct}","kind":7}]}}]}

[Trace - 12:54:17.680 PM] Sending response 'client/registerCapability - (7)' in 2ms.
Result:

[Trace - 12:54:17.680 PM] Received request 'client/unregisterCapability - (8)'.
Params: {"unregisterations":[{"id":"workspace/didChangeWatchedFiles-0","method":"workspace/didChangeWatchedFiles"}]}

[Trace - 12:54:17.690 PM] Sending response 'client/unregisterCapability - (8)' in 10ms.
Result:

[Trace - 12:54:17.792 PM] Sending request 'textDocument/foldingRange - (4)'.
Params: {"textDocument":{"uri":"file:///home/user/src/prj/functions/productoperations/getproduct/handler.go"}}

[Trace - 12:54:17.929 PM] Sending notification '$/cancelRequest'.
Params: {"id":2}

[Trace - 12:54:17.963 PM] Sending request 'textDocument/codeLens - (5)'.
Params: {"textDocument":{"uri":"file:///home/user/src/prj/functions/productoperations/getproduct/handler.go"}}

[Trace - 12:54:18.360 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2021/03/15 12:54:18 go/packages.Load\n\tsnapshot=1\n\tdirectory=/home/user/src/prj\n\tquery=[file=/home/user/src/prj/functions/productoperations/getproduct/handler.go]\n\tpackages=1\n"}

[Trace - 12:54:18.361 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2021/03/15 12:54:18 go/packages.Load\n\tsnapshot=1\n\tpackage="command-line-arguments"\n\tfiles=[/home/user/src/prj/functions/productoperations/getproduct/handler.go]\n"}

[Info - 12:54:18 PM] 2021/03/15 12:54:18 go/packages.Load
snapshot=1
directory=/home/user/src/prj
query=[file=/home/user/src/prj/functions/productoperations/getproduct/handler.go]
packages=1

[Info - 12:54:18 PM] 2021/03/15 12:54:18 go/packages.Load
snapshot=1
package="command-line-arguments"
files=[/home/user/src/prj/functions/productoperations/getproduct/handler.go]

[Trace - 12:54:18.414 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2021/03/15 12:54:18 command-line-arguments: no dep handle for gitlab.com/co/cs/u/prj/common.git/pkg/pdb: no metadata for gitlab.com/co/cs/u/prj/common.git/pkg/pdb\n\tsnapshot=1\n"}

[Error - 12:54:18 PM] 2021/03/15 12:54:18 command-line-arguments: no dep handle for gitlab.com/co/cs/u/prj/common.git/pkg/pdb: no metadata for gitlab.com/co/cs/u/prj/common.git/pkg/pdb
snapshot=1

[Trace - 12:54:18.415 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2021/03/15 12:54:18 command-line-arguments: no dep handle for github.com/google/uuid: no metadata for github.com/google/uuid\n\tsnapshot=1\n"}

[Error - 12:54:18 PM] 2021/03/15 12:54:18 command-line-arguments: no dep handle for github.com/google/uuid: no metadata for github.com/google/uuid
snapshot=1

[Trace - 12:54:18.425 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2021/03/15 12:54:18 go/packages.Load\n\tsnapshot=1\n\tpackage="command-line-arguments"\n\tfiles=[/home/user/src/prj/functions/productoperations/getproduct/handler.go]\n"}

[Info - 12:54:18 PM] 2021/03/15 12:54:18 go/packages.Load
snapshot=1
package="command-line-arguments"
files=[/home/user/src/prj/functions/productoperations/getproduct/handler.go]

[Trace - 12:54:18.427 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2021/03/15 12:54:18 go/packages.Load\n\tsnapshot=1\n\tdirectory=/home/user/src/prj\n\tquery=[file=/home/user/src/prj/functions/productoperations/getproduct/handler.go]\n\tpackages=1\n"}

[Info - 12:54:18 PM] 2021/03/15 12:54:18 go/packages.Load
snapshot=1
directory=/home/user/src/prj
query=[file=/home/user/src/prj/functions/productoperations/getproduct/handler.go]
packages=1

[Trace - 12:54:18.428 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2021/03/15 12:54:18 command-line-arguments: no dep handle for github.com/google/uuid: no metadata for github.com/google/uuid\n\tsnapshot=1\n"}

[Error - 12:54:18 PM] 2021/03/15 12:54:18 command-line-arguments: no dep handle for github.com/google/uuid: no metadata for github.com/google/uuid
snapshot=1

[Trace - 12:54:18.430 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2021/03/15 12:54:18 command-line-arguments: no dep handle for gitlab.com/co/cs/u/prj/common.git/pkg/pdb: no metadata for gitlab.com/co/cs/u/prj/common.git/pkg/pdb\n\tsnapshot=1\n"}

[Error - 12:54:18 PM] 2021/03/15 12:54:18 command-line-arguments: no dep handle for gitlab.com/co/cs/u/prj/common.git/pkg/pdb: no metadata for gitlab.com/co/cs/u/prj/common.git/pkg/pdb
snapshot=1

[Trace - 12:54:19.087 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {"uri":"file:///home/user/src/prj/functions/productoperations/getproduct/handler.go","version":45,"diagnostics":[{"range":{"start":{"line":10,"character":1},"end":{"line":10,"character":25}},"severity":1,"code":"BrokenImport","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#BrokenImport"},"source":"compiler","message":"could not import github.com/google/uuid (cannot find package "github.com/google/uuid" in any of \n\t/usr/local/go/src/github.com/google/uuid (from $GOROOT)\n\t/home/user/go/src/github.com/google/uuid (from $GOPATH))"},{"range":{"start":{"line":11,"character":11},"end":{"line":11,"character":90}},"severity":1,"code":"BrokenImport","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#BrokenImport"},"source":"compiler","message":"could not import gitlab.com/co/cs/u/prj/common.git/pkg/pdb (cannot find package "gitlab.com/co/cs/u/prj/common.git/pkg/pdb" in any of \n\t/usr/local/go/src/gitlab.com/co/cs/u/prj/common.git/pkg/pdb (from $GOROOT)\n\t/home/user/go/src/gitlab.com/co/cs/u/prj/common.git/pkg/pdb (from $GOPATH))"},{"range":{"start":{"line":51,"character":58},"end":{"line":51,"character":68}},"severity":1,"code":"UndeclaredName","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UndeclaredName"},"source":"compiler","message":"undeclared name: AppVersion"},{"range":{"start":{"line":51,"character":84},"end":{"line":51,"character":96}},"severity":1,"code":"UndeclaredName","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UndeclaredName"},"source":"compiler","message":"undeclared name: AppVersionID"},{"range":{"start":{"line":51,"character":112},"end":{"line":51,"character":121}},"severity":1,"code":"UndeclaredName","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UndeclaredName"},"source":"compiler","message":"undeclared name: buildDate"}]}

[Trace - 12:54:19.089 PM] Received response 'textDocument/documentLink - (1)' in 1411ms.
Result: [{"range":{"start":{"line":3,"character":2},"end":{"line":3,"character":15}},"target":"https://pkg.go.dev/encoding/json?utm_source=gopls"},{"range":{"start":{"line":4,"character":2},"end":{"line":4,"character":8}},"target":"https://pkg.go.dev/errors?utm_source=gopls"},{"range":{"start":{"line":5,"character":2},"end":{"line":5,"character":10}},"target":"https://pkg.go.dev/net/http?utm_source=gopls"},{"range":{"start":{"line":6,"character":2},"end":{"line":6,"character":4}},"target":"https://pkg.go.dev/os?utm_source=gopls"},{"range":{"start":{"line":8,"character":2},"end":{"line":8,"character":27}},"target":"https://pkg.go.dev/github.com/go-kit/kit/log?utm_source=gopls"},{"range":{"start":{"line":9,"character":2},"end":{"line":9,"character":33}},"target":"https://pkg.go.dev/github.com/go-kit/kit/log/level?utm_source=gopls"},{"range":{"start":{"line":10,"character":2},"end":{"line":10,"character":24}},"target":"https://pkg.go.dev/github.com/google/uuid?utm_source=gopls"},{"range":{"start":{"line":11,"character":12},"end":{"line":11,"character":89}},"target":"https://pkg.go.dev/gitlab.com/co/cs/u/prj/common.git/pkg/pdb?utm_source=gopls"},{"range":{"start":{"line":190,"character":6},"end":{"line":190,"character":102}},"target":"https://stackoverflow.com/questions/43976140/check-errors-when-calling-http-responsewriter-write"}]

[Error - Received] 12:54:19.089 PM #2 JSON RPC cancelled

[Trace - 12:54:19.089 PM] Received response 'textDocument/documentSymbol - (3)' in 1412ms.
Result: [{"name":"logger","detail":"log.Logger","kind":13,"range":{"start":{"line":14,"character":0},"end":{"line":18,"character":1}},"selectionRange":{"start":{"line":15,"character":1},"end":{"line":15,"character":7}}},{"name":"productconf","detail":"invalid type","kind":13,"range":{"start":{"line":14,"character":0},"end":{"line":18,"character":1}},"selectionRange":{"start":{"line":16,"character":1},"end":{"line":16,"character":12}}},{"name":"store","detail":"invalid type","kind":13,"range":{"start":{"line":14,"character":0},"end":{"line":18,"character":1}},"selectionRange":{"start":{"line":17,"character":1},"end":{"line":17,"character":6}}},{"name":"ProductList","detail":"struct{...}","kind":23,"range":{"start":{"line":21,"character":5},"end":{"line":23,"character":1}},"selectionRange":{"start":{"line":21,"character":5},"end":{"line":21,"character":16}},"children":[{"name":"Items","detail":"[]invalid type","kind":8,"range":{"start":{"line":22,"character":1},"end":{"line":22,"character":41}},"selectionRange":{"start":{"line":22,"character":1},"end":{"line":22,"character":6}}}]},{"name":"init","detail":"()","kind":12,"range":{"start":{"line":25,"character":0},"end":{"line":68,"character":1}},"selectionRange":{"start":{"line":25,"character":5},"end":{"line":25,"character":9}}},{"name":"Handle","detail":"(w http.ResponseWriter, r *http.Request)","kind":12,"range":{"start":{"line":71,"character":0},"end":{"line":194,"character":1}},"selectionRange":{"start":{"line":71,"character":5},"end":{"line":71,"character":11}}}]

[Trace - 12:54:19.091 PM] Received response 'textDocument/foldingRange - (4)' in 1299ms.
Result: [{"startLine":2,"startCharacter":8,"endLine":11,"endCharacter":90,"kind":"imports"},{"startLine":14,"startCharacter":5,"endLine":17,"endCharacter":30},{"startLine":21,"startCharacter":25,"endLine":22,"endCharacter":41},{"startLine":25,"startCharacter":13,"endLine":67,"endCharacter":2},{"startLine":30,"startCharacter":18,"endLine":44,"endCharacter":25},{"startLine":31,"startCharacter":14,"endLine":32,"endCharacter":26},{"startLine":33,"startCharacter":13,"endLine":34,"endCharacter":25},{"startLine":35,"startCharacter":13,"endLine":36,"endCharacter":25},{"startLine":37,"startCharacter":12,"endLine":38,"endCharacter":24},{"startLine":39,"startCharacter":13,"endLine":40,"endCharacter":25},{"startLine":41,"startCharacter":14,"endLine":42,"endCharacter":26},{"startLine":43,"startCharacter":9,"endLine":44,"endCharacter":25},{"startLine":58,"startCharacter":16,"endLine":60,"endCharacter":12},{"startLine":64,"startCharacter":16,"endLine":66,"endCharacter":12},{"startLine":71,"startCharacter":53,"endLine":193,"endCharacter":69},{"startLine":81,"startCharacter":8,"endLine":131,"endCharacter":14},{"startLine":83,"startCharacter":17,"endLine":86,"endCharacter":9},{"startLine":91,"startCharacter":17,"endLine":99,"endCharacter":9},{"startLine":92,"startCharacter":51,"endLine":95,"endCharacter":10},{"startLine":103,"startCharacter":39,"endLine":113,"endCharacter":4},{"startLine":105,"startCharacter":24,"endLine":106,"endCharacter":25},{"startLine":108,"startCharacter":28,"endLine":109,"endCharacter":29},{"startLine":111,"startCharacter":28,"endLine":112,"endCharacter":29},{"startLine":117,"startCharacter":56,"endLine":122,"endCharacter":4},{"startLine":119,"startCharacter":117,"endLine":121,"endCharacter":36},{"startLine":120,"startCharacter":35,"endLine":121,"endCharacter":35},{"startLine":126,"startCharacter":17,"endLine":129,"endCharacter":9},{"startLine":132,"startCharacter":9,"endLine":181,"endCharacter":14},{"startLine":135,"startCharacter":17,"endLine":138,"endCharacter":9},{"startLine":144,"startCharacter":36,"endLine":168,"endCharacter":36},{"startLine":146,"startCharacter":48,"endLine":156,"endCharacter":33},{"startLine":150,"startCharacter":39,"endLine":154,"endCharacter":26},{"startLine":162,"startCharacter":29,"endLine":166,"endCharacter":29},{"startLine":171,"startCharacter":29,"endLine":172,"endCharacter":18},{"startLine":175,"startCharacter":17,"endLine":178,"endCharacter":9},{"startLine":185,"startCharacter":22,"endLine":191,"endCharacter":3},{"startLine":187,"startCharacter":17,"endLine":188,"endCharacter":104},{"startLine":189,"startCharacter":52,"endLine":190,"endCharacter":102,"kind":"comment"}]

[Trace - 12:54:19.091 PM] Received response 'textDocument/codeLens - (5)' in 1128ms.
Result: null

[Trace - 12:54:19.366 PM] Received request 'window/workDoneProgress/create - (9)'.
Params: {"token":"6129484611666145821"}

[Trace - 12:54:19.366 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2021/03/15 12:54:19 errors loading workspace: You are outside of a module and outside of $GOPATH/src.\nIf you are using modules, please open your editor to a directory in your module.\nIf you believe this warning is incorrect, please file an issue: https://github.com/golang/go/issues/new.\n\tsnapshot=1\n\tdirectory=file:///home/user/src/prj\n"}

[Error - 12:54:19 PM] 2021/03/15 12:54:19 errors loading workspace: You are outside of a module and outside of $GOPATH/src.
If you are using modules, please open your editor to a directory in your module.
If you believe this warning is incorrect, please file an issue: https://github.com/golang/go/issues/new.
snapshot=1
directory=file:///home/user/src/prj

[Trace - 12:54:19.369 PM] Sending response 'window/workDoneProgress/create - (9)' in 3ms.
Result:

[Trace - 12:54:19.370 PM] Received notification '$/progress'.
Params: {"token":"6129484611666145821","value":{"kind":"begin","title":"Error loading workspace","message":"You are outside of a module and outside of $GOPATH/src. If you are using modules, please open your editor to a directory in your module. If you believe this warning is incorrect, please file an issue: https://github.com/golang/go/issues/new."}}

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Mar 15, 2021
@gopherbot gopherbot added this to the Unreleased milestone Mar 15, 2021
@stamblerre
Copy link
Contributor

gopls will not work well when you are outside of GOPATH and outside of a module. Is there any reason that you don't want to create a module, or is there a go.mod file in your project?

@stamblerre stamblerre added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 15, 2021
@mingulov
Copy link
Author

mingulov commented Mar 15, 2021

is there a go.mod file in your project?

Yes it is.
In the gopls server log - there is an opened /home/user/src/prj/functions/productoperations/getproduct/handler.go, so:

$ ls -al /home/user/src/prj/functions/productoperations/getproduct/
Total 68
drwxrwxr-x  3 user user  4096 maalis 15 10:06 .
drwxrwxr-x 12 user user  4096 maalis 15 10:22 ..
-rw-rw-r--  1 user user   729 maalis 15 10:06 build.go
-rw-rw-r--  1 user user   257 maalis 15 10:06 go.mod
-rw-rw-r--  1 user user 40374 maalis 15 10:06 go.sum
-rw-rw-r--  1 user user  5727 maalis 15 10:06 handler.go
drwxrwxr-x  5 user user  4096 maalis 15 09:59 vendor

$ cat /home/user/src/prj/functions/productoperations/getproduct/go.mod
module gitlab.com/co/prj/functions/getproduct

go 1.15

require (
	github.com/go-kit/kit v0.10.0
	github.com/google/uuid v1.2.0
	gitlab.com/valid_line/pkg/productdboperations v0.0.0-20210312065413-42c581ce6655
)

$ go test
?   	gitlab.com/co/prj/functions/getproduct	[no test files]

@stamblerre
Copy link
Contributor

It looks like you're opening the /home/user/src/prj directory in VS Code. Can you try opening /home/user/src/prj/functions/productoperations/getproduct/ directory and seeing if you still face the same issue? If there are multiple modules in the /home/user/src/prj directory, gopls will not be able to pick which one you are working with.

@stamblerre stamblerre reopened this Mar 15, 2021
@stamblerre stamblerre modified the milestones: Unreleased, gopls/v1.0.0 Mar 15, 2021
@mingulov
Copy link
Author

Can you try opening /home/user/src/prj/functions/productoperations/getproduct/

Yes there is no such problem.

If there are multiple modules in the /home/user/src/prj directory, gopls will not be able to pick which one you are working with.

The issue is reproducible if I open folder /home/user/src/prj/functions/productoperations/ in VS Code, there are also some other modules (/home/user/src/prj/functions/productoperations/createproduct/ etc). There is no any go.mod in /home/user/src/prj/functions/productoperations/ (and any upper - in .../prj, .../prj/functions).

gopls is the only tool which has a problems with such folder setup, briefly it is a go project with git submodules.

Also I can not remove that warning even if I would close all open files in VS Code, it still remains, seems the only way to remove it is to re-start VS Code.

@stamblerre
Copy link
Contributor

gopls currently requires you to open a module per-workspace folder. A detailed explanation of this requirement can be found in the workspace documentation. Please take a look at that and let me know if that answers your questions.

@mingulov
Copy link
Author

Thank you, I see now that it is an official way even in VS Code, so I have to add each project separately to workspace. It is not very user friendly, but I have to do this just once, so it is ok.
Thank you again.

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. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants