x/tools/gopls: disable code actions from gopls
xtrats opened this issue · 7 comments
gopls version
Build info
----------
golang.org/x/tools/gopls v0.16.1
golang.org/x/tools/gopls@v0.16.1 h1:1hO/dCeUvjEYx3V0rVvCtOkwnpEpqS29paE+Jw4dcAc=
github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/google/go-cmp@v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
golang.org/x/exp/typeparams@v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
golang.org/x/mod@v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
golang.org/x/sync@v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/telemetry@v0.0.0-20240607193123-221703e18637 h1:3Wt8mZlbFwG8llny+t18kh7AXxyWePFycXMuVdHxnyM=
golang.org/x/text@v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/tools@v0.22.1-0.20240628205440-9c895dd76b34 h1:Kd+Z5Pm6uwYx3T2KEkeHMHUMZxDPb/q6b1m+zEcy62c=
golang.org/x/vuln@v1.0.4 h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I=
honnef.co/go/tools@v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=
mvdan.cc/gofumpt@v0.6.0 h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=
mvdan.cc/xurls/v2@v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.22.4
go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/root/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/root/go'
GOPRIVATE=''
GOPROXY='-- private --'
GOROOT='/usr/local/go'
GOSUMDB='-- private --'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.4'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/data/project/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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4255324789=/tmp/go-build -gno-record-gcc-switches'What did you do?
There are two code actions from gopls on every single line of the source code, which will drown out the truly useful ones:
What did you see happen?
Refer to the previous section.
What did you expect to see?
I would like to be able to disable certain specific code actions of gopls through configuration.
Editor and settings
No response
Logs
No response
Related Issues and Documentation
- x/tools/gopls: Implement action should ignore importing the current package #61830 (closed)
- x/tools/gopls: codeAction returns invalid text edits #35458 (closed)
- x/tools/gopls: Add refactor "move to a new file" #65707 (closed)
- x/tools/gopls: gopls falls behind user input in large repository #45089 (closed)
- x/tools/gopls: negated build flag causes error #59346
- x/tools/gopls: #52425 (closed)
- x/tools/gopls: Is there any way to filter errors? #68624 (closed)
- x/tools/gopls: completion often uses all of 1s time budget #68063
- x/tools/gopls: gopls becomes unresponsive from time to time #61969 (closed)
- x/tools/gopls: gopls walks entire filesystem of a go module #52993 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
I would like to be able to disable certain specific code actions of gopls through configuration.
Such control is supported directly by the Language Server Protocol: a CodeAction request has a field, only, that allows the client to choose a subset of the code action kinds supported by the server. The default set can be found in the gopls source at gopls/internal/settings/default.go (unfortunately this list is not yet directly reflected in the documentation). If you remove "source.doc" and "source.assembly", then the server will not return these code actions.
I'll leave this issue open to address the question of whether the new defaults are inappropriate for a significant fraction of our users.
@xtrats which editor and LSP client are you using? In VS Code, these actions are less obtrusive, only appearing in the nested source action menu. It may be that they are more distracting in your editor than in others.
@xtrats which editor and LSP client are you using? In VS Code, these actions are less obtrusive, only appearing in the nested source action menu. It may be that they are more distracting in your editor than in others.
I'm using neovim v0.10.1 with "neovim/nvim-lspconfig" plugin, using the "glepnir/lspsaga.nvim" and "aznhe21/actions-preview.nvim" plugins to discover and preview code actions.
When there are available code actions for the current line where the cursor is located, a lightbulb icon will be displayed, so a lightbulb icon will be shown on every line.

When there are available code actions for the current line where the cursor is located, a lightbulb icon will be displayed, so a lightbulb icon will be shown on every line.
One possibility is for us to reduce the number of code actions that gopls offers based on cursor location alone, and instead require the user to select a non-empty region of text (e.g. an identifier or part of one) before offering code actions such as source.doc and source.assembly. I wonder whether there are any established UI conventions we can rely on here.
Change https://go.dev/cl/604818 mentions this issue: gopls/internal/settings: use CodeActionKind hierarchy