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: can't generate completion for go-libzfs #34345

Closed
didrocks opened this issue Sep 17, 2019 · 3 comments
Closed

x/tools/gopls: can't generate completion for go-libzfs #34345

didrocks opened this issue Sep 17, 2019 · 3 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.
Milestone

Comments

@didrocks
Copy link

didrocks commented Sep 17, 2019

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

$ go version
go version go1.13 linux/amd64

Does this issue reproduce with the latest release?

Yes, gopls refreshed from latest release (v0.1.6)

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/didrocks/.cache/go-build"
GOENV="/home/didrocks/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/didrocks/.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"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build855760674=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I typed the follow go code, with go-libzfs at 0.2.2:

package main

import (
	zfs "github.com/bicomsystems/go-libzfs"
)

func main() {
	zfs.
}

when pressing "." after zfs, I receive garbage completion: "Global.mtx.{Lock;Unlock}". The gopls log outputs shows a lot of lines like:

[Error - 14:47:07] 2019/09/17 14:47:07 error generating completion item: no file for file:///home/didrocks/.go/pkg/mod/github.com/bicomsystems/go-libzfs@v0.2.2-0.20190807094932-e50663fa5901/common.go
[Error - 14:47:07] 2019/09/17 14:47:07 error generating completion item: no file for file:///home/didrocks/.go/pkg/mod/github.com/bicomsystems/go-libzfs@v0.2.2-0.20190807094932-e50663fa5901/common.go
[Error - 14:47:07] 2019/09/17 14:47:07 error generating completion item: no file for file:///home/didrocks/.go/pkg/mod/github.com/bicomsystems/go-libzfs@v0.2.2-0.20190807094932-e50663fa5901/zpool.go
[Error - 14:47:07] 2019/09/17 14:47:07 error generating completion item: no file for file:///home/didrocks/.go/pkg/mod/github.com/bicomsystems/go-libzfs@v0.2.2-0.20190807094932-e50663fa5901/common.go
[Error - 14:47:07] 2019/09/17 14:47:07 error generating completion item: no file for file:///home/didrocks/.go/pkg/mod/github.com/bicomsystems/go-libzfs@v0.2.2-0.20190807094932-e50663fa5901/common.go
[Error - 14:47:07] 2019/09/17 14:47:07 error generating completion item: no file for file:///home/didrocks/.go/pkg/mod/github.com/bicomsystems/go-libzfs@v0.2.2-0.20190807094932-e50663fa5901/zpool.go
[…]

Note that those files with that path exists on disk.

What did you expect to see?

I expect to see go-libzfs completion options.

What did you see instead?

I got unexpected completion proposals.

Go-pls information:

$  gopls version
golang.org/x/tools/gopls v0.1.6
    golang.org/x/tools/gopls@v0.1.6 h1:jXi39uPnkIKQKqLUsZqznHkHyLqTXqjMId0kTrakGMI=

vscode settings are the default from the wiki page.

gopls -rpc.trace -v check logs on that example file. Note the cgo linker failures (go-libzfs is using cgo against libzfs header libs). However, go build on the same machine works fine, using compatible system headers which are installed on the machine (/usr/lib, /usr/include).

Note the cflags/ldflags in common.go:

common.go:#cgo CFLAGS: -I /usr/include/libzfs -I /usr/include/libspl -DHAVE_IOCTL_IN_SYS_IOCTL_H -D_GNU_SOURCE
common.go:#cgo LDFLAGS: -lzfs -lzpool -lnvpair
2019/09/17 14:52:09 Info:2019/09/17 14:52:09 Build info
----------
golang.org/x/tools/gopls v0.1.6
    golang.org/x/tools/gopls@v0.1.6 h1:jXi39uPnkIKQKqLUsZqznHkHyLqTXqjMId0kTrakGMI=
    golang.org/x/sync@v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
    golang.org/x/tools@v0.0.0-20190916172013-cb62a53de387 h1:K9AD1n6qD+pzpEX+97w2rRrY26Xti5UWFyZNfmXDf3A=
    golang.org/x/xerrors@v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=

Go info
-------
go version go1.13 linux/amd64

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/didrocks/.cache/go-build"
GOENV="/home/didrocks/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/didrocks/.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"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build798046758=/tmp/go-build -gno-record-gcc-switches"
2019/09/17 14:52:09 Info:2019/09/17 14:52:09 2.559809ms for GOROOT= GOPATH=/home/didrocks/.go GO111MODULE= PWD=/home/didrocks go "list" "-m" "-json" "all", stderr: <<go list -m: not using modules
>>
2019/09/17 14:52:09 Info:2019/09/17 14:52:09 3.36455ms for GOROOT= GOPATH=/home/didrocks/.go GO111MODULE= PWD=/home/didrocks go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "builtin", stderr: <<>>
2019/09/17 14:52:09 Info:2019/09/17 14:52:09 4.132051ms for GOROOT= GOPATH=/home/didrocks/.go GO111MODULE= PWD=/home/didrocks go "env" "GOMOD", stderr: <<>>
2019/09/17 14:52:09 Info:2019/09/17 14:52:09 4.131733ms for GOROOT= GOPATH=/home/didrocks/.go GO111MODULE= PWD=/home/didrocks go "env" "GOPATH", stderr: <<>>
2019/09/17 14:52:09 Info:2019/09/17 14:52:09 2.792277ms for GOROOT= GOPATH=/home/didrocks/.go GO111MODULE= PWD=/home/didrocks go "list" "-m" "-json" "all", stderr: <<go list -m: not using modules
>>
2019/09/17 14:52:09 Info:2019/09/17 14:52:09 2.939044ms for GOROOT= GOPATH=/home/didrocks/.go GO111MODULE= PWD=/home/didrocks go "env" "GOMOD", stderr: <<>>
2019/09/17 14:52:09 Info:2019/09/17 14:52:09 2.016652ms for GOROOT= GOPATH=/home/didrocks/.go GO111MODULE= PWD=/home/didrocks go "env" "GOPATH", stderr: <<>>
2019/09/17 14:52:09 Info:2019/09/17 14:52:09 2.693774ms for GOROOT= GOPATH=/home/didrocks/.go GO111MODULE= PWD=/home/didrocks go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/home/didrocks/work/foo", stderr: <<>>
2019/09/17 14:52:12 Info:2019/09/17 14:52:12 3.087340008s for GOROOT= GOPATH=/home/didrocks/.go GO111MODULE= PWD=/home/didrocks go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/home/didrocks/work/foo/zfs.go", stderr: <<# github.com/bicomsystems/go-libzfs
zpool.c:82:30: error: ‘ZPOOL_REWIND_POLICY’ undeclared here (not in a function); did you mean ‘sZPOOL_REWIND_POLICY’?
   82 | char *sZPOOL_REWIND_POLICY = ZPOOL_REWIND_POLICY;
      |                              ^~~~~~~~~~~~~~~~~~~
      |                              sZPOOL_REWIND_POLICY
zpool.c:83:31: error: ‘ZPOOL_REWIND_REQUEST’ undeclared here (not in a function); did you mean ‘sZPOOL_REWIND_REQUEST’?
   83 | char *sZPOOL_REWIND_REQUEST = ZPOOL_REWIND_REQUEST;
      |                               ^~~~~~~~~~~~~~~~~~~~
      |                               sZPOOL_REWIND_REQUEST
zpool.c:84:35: error: ‘ZPOOL_REWIND_REQUEST_TXG’ undeclared here (not in a function); did you mean ‘sZPOOL_REWIND_REQUEST_TXG’?
   84 | char *sZPOOL_REWIND_REQUEST_TXG = ZPOOL_REWIND_REQUEST_TXG;
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~~
      |                                   sZPOOL_REWIND_REQUEST_TXG
zpool.c:85:35: error: ‘ZPOOL_REWIND_META_THRESH’ undeclared here (not in a function); did you mean ‘sZPOOL_REWIND_META_THRESH’?
   85 | char *sZPOOL_REWIND_META_THRESH = ZPOOL_REWIND_META_THRESH;
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~~
      |                                   sZPOOL_REWIND_META_THRESH
zpool.c:86:35: error: ‘ZPOOL_REWIND_DATA_THRESH’ undeclared here (not in a function); did you mean ‘sZPOOL_REWIND_DATA_THRESH’?
   86 | char *sZPOOL_REWIND_DATA_THRESH = ZPOOL_REWIND_DATA_THRESH;
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~~
      |                                   sZPOOL_REWIND_DATA_THRESH
zpool.c: In function ‘go_zpool_search_import’:
zpool.c:497:2: error: unknown type name ‘importargs_t’
  497 |  importargs_t idata;
      |  ^~~~~~~~~~~~
zpool.c:498:27: error: ‘importargs_t’ undeclared (first use in this function)
  498 |  memset(&idata, 0, sizeof(importargs_t));
      |                           ^~~~~~~~~~~~
zpool.c:498:27: note: each undeclared identifier is reported only once for each function it appears in
zpool.c:500:7: error: request for member ‘path’ in something not a structure or union
  500 |  idata.path = path;
      |       ^
zpool.c:501:7: error: request for member ‘paths’ in something not a structure or union
  501 |  idata.paths = paths;
      |       ^
zpool.c:504:2: warning: implicit declaration of function ‘thread_init’; did you mean ‘thread_exit’? [-Wimplicit-function-declaration]
  504 |  thread_init();
      |  ^~~~~~~~~~~
      |  thread_exit
zpool.c:505:10: warning: implicit declaration of function ‘zpool_search_import’; did you mean ‘go_zpool_search_import’? [-Wimplicit-function-declaration]
  505 |  pools = zpool_search_import(zfsh, &idata);
      |          ^~~~~~~~~~~~~~~~~~~
      |          go_zpool_search_import
zpool.c:505:8: warning: assignment to ‘nvlist_ptr’ {aka ‘struct nvlist *’} from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
  505 |  pools = zpool_search_import(zfsh, &idata);
      |        ^
zpool.c:506:2: warning: implicit declaration of function ‘thread_fini’; did you mean ‘thread_join’? [-Wimplicit-function-declaration]
  506 |  thread_fini();
      |  ^~~~~~~~~~~
      |  thread_join
>>
2019/09/17 14:52:12 Info:2019/09/17 14:52:12 go/packages.Load
	packages = 1
2019/09/17 14:52:12 Info:2019/09/17 14:52:12 go/packages.Load
	package = command-line-arguments
	files = [/home/didrocks/work/foo/zfs.go]
/home/didrocks/work/foo/zfs.go:9: expected selector or type assertion, found '}'
@gopherbot gopherbot added this to the Unreleased milestone Sep 17, 2019
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 17, 2019
@gopherbot
Copy link

Thank you for filing a gopls issue! Please take a look at the Troubleshooting section of the gopls Wiki page, and make sure that you have provided all of the relevant information here.

@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Sep 17, 2019
@ianthehat
Copy link

This is probably a cgo related issue, in which case the tracking bug for that is #32898

@stamblerre stamblerre assigned stamblerre and heschi and unassigned stamblerre Nov 7, 2019
@stamblerre stamblerre changed the title x/tools/cmd/gopls: can't generate completion for go-libzfs x/tools/gopls: can't generate completion for go-libzfs Nov 13, 2019
@heschi
Copy link
Contributor

heschi commented Nov 20, 2019

Closing this as a dup of newly-created #35720. I'm working on it now.

@heschi heschi closed this as completed Nov 20, 2019
@golang golang locked and limited conversation to collaborators Nov 19, 2020
@rsc rsc unassigned heschi Jun 23, 2022
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.
Projects
None yet
Development

No branches or pull requests

5 participants