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/imports: should not scan bazel-out directories #35914

Open
ashi009 opened this issue Nov 30, 2019 · 10 comments
Open

x/tools/imports: should not scan bazel-out directories #35914

ashi009 opened this issue Nov 30, 2019 · 10 comments

Comments

@ashi009
Copy link

@ashi009 ashi009 commented Nov 30, 2019

What did you do?

Open our monolith repository in VS Code, then open a go file and wait.

What did you expect to see?

Nothing.

What did you see instead?

The CPU usage goes up periodically due to gopls.

Build info

golang.org/x/tools/gopls 0.2.0
    golang.org/x/tools/gopls@v0.2.1 h1:qXHEqJw4CqROYvoDXinY1ZOkyAFS+jcPOvLRK76dvwY=
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/sergi/go-diff@v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
    golang.org/x/sync@v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
    golang.org/x/tools@v0.0.0-20191108194844-46f05828f2fe h1:FNzasIzfY1IIdyTs/+o3Qv1b7YdffPbBXyjZ5VJJdIA=
    golang.org/x/xerrors@v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
    honnef.co/go/tools@v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=

Go info

go version go1.13.3 darwin/amd64

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/xiaoyi/Library/Caches/go-build"
GOENV="/Users/xiaoyi/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/xiaoyi/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/xiaoyi/homebrew/Cellar/go/1.13.3/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/xiaoyi/homebrew/Cellar/go/1.13.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/cb/j3f4sj8j3yq46t5kqcc5mpj80000gn/T/go-build258309595=/tmp/go-build -gno-record-gcc-switches -fno-common"

VSCode settings

  "go.formatTool": "goimports",
  "go.useLanguageServer": true,
  "go.languageServerFlags": [
    "-rpc.trace",
    "serve",
    "--debug=localhost:6060",
  ],

Relevant logs

[Trace - 00:49:10.532 AM] Sending notification '$/cancelRequest'.
Params: {"id":7}


2019/12/01 00:49:24 gopathwalk: scanned /Users/xiaoyi/Projects/depot in 14.658742489s
2019/12/01 00:49:24 gopathwalk: scanning /Users/xiaoyi/go/pkg/mod
2019/12/01 00:49:24 Directory added to ignore list: /Users/xiaoyi/go/pkg/mod/cache
2019/12/01 00:49:25 gopathwalk: scanned /Users/xiaoyi/go/pkg/mod in 448.168315ms
[Trace - 00:49:27.343 AM] Received response 'textDocument/codeAction - (7)' in 17316ms.
Result: {}


2019/12/01 00:49:27 : context canceled
Params: {"type":3,"message":"2019/12/01 00:56:29 done loading package names for 10 packages"}


2019/12/01 00:56:29 gopathwalk: scanning /Users/xiaoyi/homebrew/Cellar/go/1.13.3/libexec/src
[Info  - 12:56:29 AM] 2019/12/01 00:56:29 done loading package names for 10 packages
2019/12/01 00:56:29 gopathwalk: scanned /Users/xiaoyi/homebrew/Cellar/go/1.13.3/libexec/src in 2.097875ms
2019/12/01 00:56:29 gopathwalk: scanning /Users/xiaoyi/Projects/depot
[Trace - 00:56:30.166 AM] Sending notification '$/cancelRequest'.
Params: {"type":3,"message":"2019/12/01 00:58:00 loading package names for 10 packages"}


2019/12/01 00:58:00 gopathwalk: scanning /Users/xiaoyi/homebrew/Cellar/go/1.13.3/libexec/src
[Info  - 12:58:00 AM] 2019/12/01 00:58:00 fixImports(filename="/Users/xiaoyi/Projects/depot/ecnova/tools/rebem/compgen/parser.go"), abs="/Users/xiaoyi/Projects/depot/ecnova/tools/rebem/compgen/parser.go", srcDir="/Users/xiaoyi/Projects/depot/ecnova/tools/rebem/compgen" ...
[Trace - 00:58:00.913 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2019/12/01 00:58:00 done loading package names for 10 packages"}


[Info  - 12:58:00 AM] 2019/12/01 00:58:00 loading package names for 10 packages
[Info  - 12:58:00 AM] 2019/12/01 00:58:00 done loading package names for 10 packages
2019/12/01 00:58:00 gopathwalk: scanned /Users/xiaoyi/homebrew/Cellar/go/1.13.3/libexec/src in 3.525719ms
2019/12/01 00:58:00 gopathwalk: scanning /Users/xiaoyi/Projects/depot
[Trace - 00:58:01.083 AM] Sending request 'textDocument/foldingRange - (22)'.
Params: {"textDocument":{"uri":"file:///Users/xiaoyi/Projects/depot/ecnova/tools/rebem/compgen/parser.go"}}




2019/12/01 00:58:17 gopathwalk: scanned /Users/xiaoyi/Projects/depot in 16.553269931s
2019/12/01 00:58:17 gopathwalk: scanning /Users/xiaoyi/go/pkg/mod
2019/12/01 00:58:17 Directory added to ignore list: /Users/xiaoyi/go/pkg/mod/cache
2019/12/01 00:58:17 gopathwalk: scanned /Users/xiaoyi/go/pkg/mod in 21.910985ms
[Trace - 00:58:17.518 AM] Received response 'textDocument/codeAction - (21)' in 16609ms.
Result: {}


2019/12/01 00:58:17 gopathwalk: scanning /Users/xiaoyi/homebrew/Cellar/go/1.13.3/libexec/src
[Info  - 12:58:17 AM] 2019/12/01 00:58:17 done loading package names for 10 packages
2019/12/01 00:58:17 gopathwalk: scanned /Users/xiaoyi/homebrew/Cellar/go/1.13.3/libexec/src in 25.22796ms
2019/12/01 00:58:17 gopathwalk: scanning /Users/xiaoyi/Projects/depot
2019/12/01 00:58:32 gopathwalk: scanned /Users/xiaoyi/Projects/depot in 15.012563751s
2019/12/01 00:58:32 gopathwalk: scanning /Users/xiaoyi/go/pkg/mod
2019/12/01 00:58:32 Directory added to ignore list: /Users/xiaoyi/go/pkg/mod/cache
2019/12/01 00:58:32 gopathwalk: scanned /Users/xiaoyi/go/pkg/mod in 19.820343ms
[Trace - 00:58:33.510 AM] Received response 'textDocument/codeAction - (23)' in 32367ms.
Result: {}

More Info

By inspecting the file opened by gopls, it's scanning bazel-out.

@gopherbot
Copy link

@gopherbot gopherbot commented Nov 30, 2019

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

@ashi009 ashi009 changed the title gopls: extreemly ow gopls: extremely code actions due to gopathwalk Nov 30, 2019
@odeke-em odeke-em changed the title gopls: extremely code actions due to gopathwalk x/tools/gopls: extremely code actions due to gopathwalk Dec 1, 2019
@gopherbot gopherbot added this to the Unreleased milestone Dec 1, 2019
@gopherbot gopherbot added the Tools label Dec 1, 2019
@heschi heschi changed the title x/tools/gopls: extremely code actions due to gopathwalk x/tools/imports: should not scan bazel-out directories Dec 2, 2019
@heschi
Copy link
Contributor

@heschi heschi commented Dec 2, 2019

I assume goimports behaves the same way, so retitling.

We don't currently support .goimportsignore in module mode. Possibly we should. See also #30058 and https://golang.org/cl/182417.

@heschi
Copy link
Contributor

@heschi heschi commented Dec 2, 2019

Concretely, I'd suggest that the main module, and any replace targets, could contain a .goimportsignore. Paths in that file would be processed relative to the module root or replace dir.

@vincepri, would that work for you as well? It would mean checking in a bunch of .goimportsignore files.

@burdiyan
Copy link

@burdiyan burdiyan commented Dec 2, 2020

I just commented in the other closed issue, but this is also relevant for this one I believe: #30058 (comment)

@burdiyan
Copy link

@burdiyan burdiyan commented Dec 2, 2020

For now, the workaround that we will probably have to do for our monorepo is to move our top-level go.mod into the subdirectory where only go files exist. This will break go build ./... for us, and would be cumbersome in all sorts of ways. Also it would break VS Code as support for nested go.mod which are not top-level is experimental now, and doesn't work without special gopls configuration.

I think for multi-language repositories having some way to ignore certain directories by all go tools is a must have! The case of node_modules was discussed multiple times in many different issues, but seems like people were unable to agree on a solution.

@robpike didn't want to create more dot files, so being able to configure this in go.mod instead of additional .goignore (which I don't mind either) sounds like a reasonable idea.

@heschi
Copy link
Contributor

@heschi heschi commented Dec 2, 2020

This issue is specific to the goimports code plus its use in gopls. If you want a solution that covers the go command, you're going to need to try to get some traction on #30058 or file a new issue/proposal. If you want a solution for just gopls, we may cover that as part of #42473.

@burdiyan
Copy link

@burdiyan burdiyan commented Dec 3, 2020

@heschik Thanks a lot for the clarification!

I will try to submit a proposal for a global ignore mechanism for all the Go ecosystem.

@burdiyan
Copy link

@burdiyan burdiyan commented Dec 3, 2020

Shall this one be closed in favor of #42473 then? It seems to be more general.

@mknyszek
Copy link
Contributor

@mknyszek mknyszek commented Apr 16, 2021

Because this is no longer assigned, it popped back into my wheelhouse. Given that #42473 is closed, should this be closed as well? Marking as NeedsDecision.

@heschi
Copy link
Contributor

@heschi heschi commented Apr 16, 2021

No, this is a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants