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: autocomplete returns packages within excluded directories (per build.directoryFilters) #52347

Open
gonzojive opened this issue Apr 14, 2022 · 4 comments
Labels
gopls/completion Issues related to auto-completion in gopls. gopls/imports gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@gonzojive
Copy link

Related to #48939 and reproduced in a repository.

screenshot

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

$ go version

Does this issue reproduce with the latest release?

Yes:

~/git/go-tools$ git log -n 1
commit fe932b4680bd8878524bfea7a12f7cf30e1e0438

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

go env Output
$ $ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/red/.cache/go-build"
GOENV="/home/red/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/red/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/red/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.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/red/git/gopls-bug-workspace-filters/go.mod"
GOWORK=""
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-build2678705596=/tmp/go-build -gno-record-gcc-switches"

What did you do?

  1. Check out https://github.com/gonzojive/gopls-bug-workspace-filters
  2. Open internal/activework/activework.go
  3. Try to tab complete myl within a function. The autocomplete list will include a library in the generated_stuff dir, which is included in the build.directoryFilters exclusion list:
{
    "gopls": {
        "build.directoryFilters": [
            "-generated_stuff",
        ],
        "formatting.local": "github.com/api-definitions/keyval",
    },
}

What did you expect to see?

Packages in generated_stuff shouldn't be included in autocomplete list?

I can't tell if this is working as intended. It came up before in #37697, but I interpret the build.directoryFilters to mean that the generated_stuff folder should be ignored in this context as well: https://github.com/golang/vscode-go/blob/master/docs/settings.md#builddirectoryfilters.

What did you see instead?

mylib is included in the autocomplete list.

@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 Apr 14, 2022
@gopherbot gopherbot added this to the Unreleased milestone Apr 14, 2022
@gonzojive gonzojive changed the title x/tools/gopls: x/tools/gopls: autocomplete returns packages within excluded directories (per build.directoryFilters) Apr 14, 2022
@jamalc jamalc added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 14, 2022
@jamalc jamalc modified the milestones: Unreleased, gopls/on-deck Apr 14, 2022
@gonzojive
Copy link
Author

I came across a related issue: #42965

From browsing the source, I wonder if the call to imports.GetAllCandidates from completions.go could be altered to pass in a filter derived from the directoryFilters that gets used in the dirFound callback that imports.GetAllCandidates uses to limit what packages it scans.

@gonzojive
Copy link
Author

This bug may also be a duplicate of #51265, not totally sure.

gonzojive added a commit to gonzojive/tools that referenced this issue Apr 19, 2022
gonzojive added a commit to gonzojive/tools that referenced this issue Apr 19, 2022
@hyangah hyangah added the gopls/completion Issues related to auto-completion in gopls. label May 10, 2022
@findleyr findleyr modified the milestones: gopls/later, gopls/v0.10.0 Aug 8, 2022
@findleyr findleyr modified the milestones: gopls/v0.10.0, gopls/v0.10.1 Oct 11, 2022
@findleyr findleyr modified the milestones: gopls/v0.10.1, gopls/v0.10.2 Nov 1, 2022
@findleyr findleyr modified the milestones: gopls/v0.11.0, gopls/v0.12.0 Dec 8, 2022
@findleyr findleyr modified the milestones: gopls/v0.12.0, gopls/v0.13.0 Mar 27, 2023
@findleyr findleyr modified the milestones: gopls/v0.14.0, gopls/v0.15.0 Sep 28, 2023
@findleyr
Copy link
Member

I just implemented something similar to this in https://go.dev/cl/531417.

Notes on how to implement this:

  • Thread through directory filters to where we do 'metadata'-based unimported completion
    • here, for package names
    • here, for package members
  • Apply directory filters for each compiled go file in the package; if all are excluded, ignore the package. (or just pick the first file to consider).
  • For any excluded package path, also filter from module cache completion implemented via completer.completionCallbacks

May not get to this for v0.14, which we want to cut ASAP to include a completion performance fix.

@powellnorma
Copy link

Would this completely stop gopls from scanning excluded sub directories?
I was getting #42255 because a sub-sub directory has a NFS mounted to it, and gopls apparently tried to scan the entire NFS file tree..

@findleyr findleyr removed this from the gopls/v0.15.0 milestone Jan 17, 2024
@findleyr findleyr added this to the gopls/v0.16.0 milestone Jan 17, 2024
@findleyr findleyr modified the milestones: gopls/v0.16.0, gopls/v0.17.0 May 23, 2024
@findleyr findleyr modified the milestones: gopls/v0.17.0, gopls/v0.18.0 Oct 28, 2024
@findleyr findleyr modified the milestones: gopls/v0.18.0, gopls/v0.19.0 Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/completion Issues related to auto-completion in gopls. gopls/imports gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

7 participants