Forked from #31561. This issue is not for packages that directly import "C"; that issue is #35721.
Various features, notably Go to Definition and friends, fail when the declaring package uses cgo. That's because the Go code for cgo files is actually in a generated file in the build cache, not the .go file the user might expect. The generated file has //line directives that point to the original code, but gopls is currently not honoring those directives. Fixing that should improve the experience for people who depend on a cgo library.
If there are other features that break when depending on a cgo package, please note them here so that we can make sure they're fixed and add tests.
Change https://golang.org/cl/208101 mentions this issue: internal/lsp: rename Files to CompiledGoFiles
Change https://golang.org/cl/208100 mentions this issue: internal: avoid use of (*token.File).Name
Change https://golang.org/cl/208501 mentions this issue: internal/span: support line directives
Change https://golang.org/cl/208502 mentions this issue: internal/lsp: track and parse non-compiled go files
Change https://golang.org/cl/208503 mentions this issue: internal/lsp: add tests for cgo package users
Thank you for improving this. Does golang.org/x/tools/gopls@latest not include it yet?
@frou: It does not yet, but I will update https://github.com/golang/go/issues/33030 when a new version (and this fix) is released.
Most helpful comment
@frou: It does not yet, but I will update https://github.com/golang/go/issues/33030 when a new version (and this fix) is released.