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: complete third-party unimported too slow #55873

Closed
3Xpl0it3r opened this issue Sep 26, 2022 · 17 comments
Closed

x/tools/gopls: complete third-party unimported too slow #55873

3Xpl0it3r opened this issue Sep 26, 2022 · 17 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. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@3Xpl0it3r
Copy link

go env

GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/l0calh0st/Library/Caches/go-build"
GOENV="/Users/l0calh0st/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
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="/usr/local/Cellar/go/1.18.4/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.18.4/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18.4"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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 -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/x7/vm1w670d4_5fn5b8vrn3mrv40000gn/T/go-build3773192071=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  When i use gopls complete third-party unimport, it's too slow, may be wait 3-5s
image

Editor and settings

NVIM v0.7.2
Build type: Release
LuaJIT 2.1.0-beta3
编译者 brew@BigSur

Features: +acl +iconv +tui
See ":help feature-compile"

 系统 vimrc 文件: "$VIM/sysinit.vim"
     $VIM 预设值: "/usr/local/Cellar/neovim/0.7.2_1/share/nvim"

Run :checkhealth for more info

    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 = "10ms", -- completionBudget is the soft latency goal for completion requests
        matcher = "CaseInsensitive", -- matcher sets the algorithm that is used when calculating completion candidates. CaseInsensitive | CaseSensitive | Fuzzy
        completeUnimported = true,
        deepCompletion = false, -- If true, this turns on the ability to return completions from deep inside relevant entities, rather than just the locally accessible ones.

        experimentalWatchedFileDelay = "10ms"

    },

Logs

[ERROR][2022-09-26 19:07:46] ...lsp/handlers.lua:455 "2022/09/26 19:07:46 no signature help: no signature help within a string literal\n\tposition={18 16}\n"
[ERROR][2022-09-26 19:07:50] ...lsp/handlers.lua:455 "2022/09/26 19:07:50 github.com/3Xpl0it3r/minio-operator/pkg/controller/minio: no dep handle for github.com/3: no metadata for github.com/3\n\tsnapshot=16\n"
[ERROR][2022-09-26 19:07:50] ...lsp/handlers.lua:455 "2022/09/26 19:07:50 github.com/3Xpl0it3r/minio-operator/pkg/controller/minio: no dep handle for github.com/3: no metadata for github.com/3\n\tsnapshot=16\n"
[ERROR][2022-09-26 19:07:50] ...lsp/handlers.lua:455 "2022/09/26 19:07:50 no signature help: no signature help within a string literal\n\tposition={18 17}\n"
[ERROR][2022-09-26 19:07:52] ...lsp/handlers.lua:455 "2022/09/26 19:07:52 github.com/3Xpl0it3r/minio-operator/pkg/controller/minio: no dep handle for github.com/3X: no metadata for github.com/3X\n\tsnapshot=17\n"
[ERROR][2022-09-26 19:07:52] ...lsp/handlers.lua:455 "2022/09/26 19:07:52 github.com/3Xpl0it3r/minio-operator/pkg/controller/minio: no dep handle for github.com/3X: no metadata for github.com/3X\n\tsnapshot=17\n"
[ERROR][2022-09-26 19:07:52] ...lsp/handlers.lua:455 "2022/09/26 19:07:52 no signature help: no signature help within a string literal\n\tposition={18 18}\n"
[ERROR][2022-09-26 19:07:53] ...lsp/handlers.lua:455 "2022/09/26 19:07:53 github.com/3Xpl0it3r/minio-operator/pkg/controller/minio: no dep handle for github.com/3Xpl0it3r/: no metadata for github.com/3Xpl0it3r/\n\tsnapshot=19\n"
[ERROR][2022-09-26 19:07:53] ...lsp/handlers.lua:455 "2022/09/26 19:07:53 no signature help: no signature help within a string literal\n\tposition={18 26}\n"
[START][2022-09-26 19:21:04] LSP logging initiated

@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 Sep 26, 2022
@gopherbot gopherbot added this to the Unreleased milestone Sep 26, 2022
@hyangah
Copy link
Contributor

hyangah commented Sep 26, 2022

  • Is the module that contains the package already in your go.mod, and already in your module cache?
  • can you capture a gopls log (I don't know nvim-specific instruction, but I guess this involves passing args in the gopls language server command setting following this general instruction.

@hyangah hyangah added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 26, 2022
@3Xpl0it3r
Copy link
Author

  1. yeah, the package has already in go.mod, has ready in cache
  2. here is the gopls debug log
    gopls.log

@jinzhongjia
Copy link

i alse have this problem, and I solved it temporarily by restarting lsp

@3Xpl0it3r
Copy link
Author

@jinzhongjia it doesn't work for me -,-
gopls works well beside this issue, i this it may works in a lazy loading model.

@jinzhongjia
Copy link

@jinzhongjia it doesn't work for me -,- gopls works well beside this issue, i this it may works in a lazy loading model.

now , i try golangci-lint,and it works very well

@3Xpl0it3r
Copy link
Author

3Xpl0it3r commented Sep 28, 2022

@jinzhongjia thx for your answer, is your edit is neovim/vim?

I have tried it just now, I found that it has it's own language server named golangci-lint-langserver,but it seems does't work in neovim(nvim-lspconfig).

@jinzhongjia
Copy link

@jinzhongjia thx for your answer, is your edit is neovim/vim?

I have tried it just now, I found that it has it's own language server named golangci-lint-langserver,but it seems does't work in neovim.

you need install golangci-lint and golangci-lint-langserver,but the golangci-lint-langserver no function Lspsaga hover_doc

when u have installed them ,you just add require("lspconfig").golangci_lint_ls.setup to your config

@jinzhongjia
Copy link

and now , i am back to gopls

@jinzhongjia
Copy link

and now , i am back to gopls

I can't stand without hover_doc

@findleyr
Copy link
Contributor

Hi! Can you start gopls with the -debug=localhost:8098 option and visit http://localhost:8098/trace/textDocument/completion. Can you share the trace of what gopls is doing during your slowest completion?

@findleyr
Copy link
Contributor

My theory of the problem is as follows: typing in an import path invalidates package metadata (because the import graph may have changed), which has a ripple effect of invalidation. Completion must wait for the go command and follow-up type-checking. But import completion should not require type-checking, so we should be able to bypass this.

This may have been a regression caused by work on invalidation.

@findleyr
Copy link
Contributor

@3Xpl0it3r there is something I don't understand in your logs: why earlier requests are completing rather than being canceled. I can't see enough information to understand why. Would you be willing to build and use a gopls branch that has additional logging, so that we can gather more information?

@3Xpl0it3r
Copy link
Author

Hi! Can you start gopls with the -debug=localhost:8098 option and visit http://localhost:8098/trace/textDocument/completion. Can you share the trace of what gopls is doing during your slowest completion?

image
image

here is the trace information

@3Xpl0it3r
Copy link
Author

@3Xpl0it3r there is something I don't understand in your logs: why earlier requests are completing rather than being canceled. I can't see enough information to understand why. Would you be willing to build and use a gopls branch that has additional logging, so that we can gather more information?

ofcourse, which branch should I use?
my curren gopls version is

~ gopls version
golang.org/x/tools/gopls v0.9.5
    golang.org/x/tools/gopls@v0.9.5 h1:F3TO5th6TUg40FHrpxZfMkMlVaaTmByeEvylgVHGH2A=
➜  ~ 

@3Xpl0it3r
Copy link
Author

My theory of the problem is as follows: typing in an import path invalidates package metadata (because the import graph may have changed), which has a ripple effect of invalidation. Completion must wait for the go command and follow-up type-checking. But import completion should not require type-checking, so we should be able to bypass this.

This may have been a regression caused by work on invalidation.

it there any option in configure can skip this ?

@findleyr findleyr added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Sep 29, 2022
@findleyr
Copy link
Contributor

@3Xpl0it3r this is the issue: as you are typing, your LSP client is asking for things like documentHighlight on each keypress. For gopls, this involves computing type information, which can take time. But on subsequent keypresses your client does not cancel the requests from older versions, so gopls does not proceed to processing the next keypress until it is done with the earlier documentHighlight request.

Most other LSP clients cancel requests relating to older file versions, when a new version arrives. I suspect that your client should do the same.

@findleyr
Copy link
Contributor

Here's a relevant section of the LSP spec:

/**
	 * The server detected that the content of a document got
	 * modified outside normal conditions. A server should
	 * NOT send this error code if it detects a content change
	 * in it unprocessed messages. The result even computed
	 * on an older state might still be useful for the client.
	 *
	 * If a client decides that a result is not of any use anymore
	 * the client should cancel the request.
	 */
	export const ContentModified: [integer](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#integer) = -32801;

Per my reading, this is saying that if the client doesn't explicitly cancel a request, we should continue to process it with the older content. In light of this, I think this is a client bug: the client should cancel the older requests if they are no longer needed.

@findleyr findleyr added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 29, 2022
@findleyr findleyr removed their assignment Sep 29, 2022
@findleyr findleyr removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 29, 2022
@golang golang locked and limited conversation to collaborators Sep 30, 2023
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. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants