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: Cannot jump to definitions in k8s stage dir/vendor #60842

Closed
3Xpl0it3r opened this issue Jun 16, 2023 · 2 comments
Closed

x/tools/gopls: Cannot jump to definitions in k8s stage dir/vendor #60842

3Xpl0it3r opened this issue Jun 16, 2023 · 2 comments
Labels
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

@3Xpl0it3r
Copy link

gopls cannot work well in kubernetes source code stage dir; it cannot jump to definitions when trace source go into stage dir(vendor).

gopls version

➜  vendor git:(master) ✗ gopls version
golang.org/x/tools/gopls v0.12.1
    golang.org/x/tools/gopls@(devel)

go env

➜  kubernetes git:(master) ✗ go env
GO111MODULE="auto"
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/l0calh0st/Library/Caches/go-build"
GOENV="/Users/l0calh0st/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/l0calh0st/Git/Go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/l0calh0st/Git/Go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn"
GOROOT="/opt/homebrew/Cellar/go/1.20.5/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.20.5/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.5"
GCCGO="gccgo"
AR="ar"
CC="cc"
CXX="c++"
CGO_ENABLED="1"
GOMOD="/Users/l0calh0st/Git/l0calh0st/go/kubernetes/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/7s/606mx9pd39l1fbghgslk29000000gn/T/go-build2833370136=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

 I trace k8s source code until jump into stage/src dir, lsp report many errors like xxx undefined
image

Editor and settings

M.gopls = {
	cmd = { "gopls", "serve", "-debug=localhost:8098" },
	filetypes = { "go", "gomod" },
	root_dir = util.root_pattern("go.work", "go.mod", ".git"),
	settings = {
		gopls = {
			symbolStyle = "Full", -- Full| Dynamic | Package
			------------------------------------------------
			----      Analyses Setting
			------------------------------------------------
			analyses = {
				unusedparams = true,
				unreachable = true,
				fillstruct = true,
			},
			------------------------------------------------
			----      Complete Setting
			------------------------------------------------
			usePlaceholders = true, -- placeholders enables placeholders for function parameters or struct fields in completion responses.
			-- completionBudget = "0ms", -- completionBudget is the soft latency goal for completion requests
			matcher = "Fuzzy", -- matcher sets the algorithm that is used when calculating completion candidates. CaseInsensitive | CaseSensitive | Fuzzy
			completeUnimported = true,
			deepCompletion = true, -- If true, this turns on the ability to return completions from deep inside relevant entities, rather than just the locally accessible ones.
			-- experimentalWatchedFileDelay = "10ms"

			------------------------------------------------
			----      Inlayhint
			------------------------------------------------
			hints = {
				assignVariableTypes = true, -- i/* int*/, j/* int*/ := 0, len(r)-1
				compositeLiteralFields = true, -- {/*in: */"Hello, world", /*want: */"dlrow ,olleH"}
				compositeLiteralTypes = true, -- /*struct{ in string; want string }*/{"Hello, world", "dlrow ,olleH"},
				constantValues = true, -- KindNone   Kind = iota/* = 0*/
				functionTypeParameters = true, -- myFoo/*[int, string]*/(1, "hello")
				parameterNames = true, -- parseInt(/* str: */ "123", /* radix: */ 8)
				rangeVariableTypes = true, -- for k/* int*/, v/* string*/ := range []string{} {
			},
		},
	},
	single_file_support = true,
}

Logs

  nvim cat lsp.log

[START][2023-06-16 18:04:33] LSP logging initiated
[ERROR][2023-06-16 18:04:33] ...lsp/handlers.lua:535    "2023/06/16 18:04:33 no signature help: cannot find an enclosing function\n\tposition=0:0\n"
[ERROR][2023-06-16 18:04:33] ...lsp/handlers.lua:535    "2023/06/16 18:04:33 no signature help: cannot find an enclosing function\n\tposition=32:16\n"
[ERROR][2023-06-16 18:04:33] ...lsp/handlers.lua:535    "2023/06/16 18:04:33 no signature help: cannot find an enclosing function\n\tposition=32:16\n"
[ERROR][2023-06-16 18:04:33] ...lsp/handlers.lua:535    "2023/06/16 18:04:33 no signature help: cannot find an enclosing function\n\tposition=32:16\n"
[ERROR][2023-06-16 18:04:34] ...lsp/handlers.lua:535    "2023/06/16 18:04:34 no signature help: cannot find an enclosing function\n\tposition=85:5\n"
[ERROR][2023-06-16 18:04:35] ...lsp/handlers.lua:535    "2023/06/16 18:04:35 no signature help: cannot find an enclosing function\n\tposition=87:2\n"
[ERROR][2023-06-16 18:04:38] ...lsp/handlers.lua:535    "2023/06/16 18:04:38 no signature help: cannot find an enclosing function\n\tposition=147:2\n"
[ERROR][2023-06-16 18:04:39] ...lsp/handlers.lua:535    "2023/06/16 18:04:39 no signature help: cannot find an enclosing function\n\tposition=147:2\n"
[ERROR][2023-06-16 18:04:40] ...lsp/handlers.lua:535    "2023/06/16 18:04:40 no signature help: cannot find an enclosing function\n\tposition=171:0\n"
[ERROR][2023-06-16 18:04:41] ...lsp/handlers.lua:535    "2023/06/16 18:04:41 no signature help: cannot find an enclosing function\n\tposition=166:0\n"
[ERROR][2023-06-16 18:04:43] ...lsp/handlers.lua:535    "2023/06/16 18:04:43 no signature help: cannot find an enclosing function\n\tposition=167:8\n"
[ERROR][2023-06-16 18:04:44] ...lsp/handlers.lua:535    "2023/06/16 18:04:44 no signature help: cannot find an enclosing function\n\tposition=181:5\n"
[ERROR][2023-06-16 18:04:46] ...lsp/handlers.lua:535    "2023/06/16 18:04:46 no signature help: cannot find an enclosing function\n\tposition=185:1\n"
[ERROR][2023-06-16 18:04:46] ...lsp/handlers.lua:535    "2023/06/16 18:04:46 no signature help: cannot find an enclosing function\n\tposition=186:1\n"
[ERROR][2023-06-16 18:04:47] ...lsp/handlers.lua:535    "2023/06/16 18:04:47 no signature help: cannot find an enclosing function\n\tposition=183:21\n"
[ERROR][2023-06-16 18:04:48] ...lsp/handlers.lua:535    "2023/06/16 18:04:48 no signature help: cannot find an enclosing function\n\tposition=183:21\n"
[ERROR][2023-06-16 18:04:52] ...lsp/handlers.lua:535    "2023/06/16 18:04:52 no signature help: cannot find an enclosing function\n\tposition=133:25\n"
[ERROR][2023-06-16 18:04:52] ...lsp/handlers.lua:535    "2023/06/16 18:04:52 no signature help: cannot find an enclosing function\n\tposition=139:22\n"
[ERROR][2023-06-16 18:04:53] ...lsp/handlers.lua:535    "2023/06/16 18:04:53 no signature help: cannot find an enclosing function\n\tposition=134:15\n"
[ERROR][2023-06-16 18:04:59] ...lsp/handlers.lua:535    "2023/06/16 18:04:59 no signature help: cannot find an enclosing function\n\tposition=667:25\n"
[ERROR][2023-06-16 18:04:59] ...lsp/handlers.lua:535    "2023/06/16 18:04:59 no signature help: cannot find an enclosing function\n\tposition=668:22\n"
[ERROR][2023-06-16 18:04:59] ...lsp/handlers.lua:535    "2023/06/16 18:04:59 no signature help: cannot find an enclosing function\n\tposition=667:78\n"
[ERROR][2023-06-16 18:05:00] ...lsp/handlers.lua:535    "2023/06/16 18:05:00 no signature help: cannot find an enclosing function\n\tposition=667:78\n"
@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 Jun 16, 2023
@gopherbot gopherbot added this to the Unreleased milestone Jun 16, 2023
@AlexanderYastrebov
Copy link
Contributor

#33551 seems related

@3Xpl0it3r
Copy link
Author

@AlexanderYastrebov thx, I know the problem
Resolve it by add a go workspace

go work init 
go work use .
go work use staging/src/k8s.io

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

3 participants