Skip to content

x/tools/gopls: allow for semanticTokens maxFullFileSize to be user configurable #79685

Description

@Jay-Madden

gopls version

❯ gopls version
golang.org/x/tools/gopls v0.22.0

go env

AR='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='c++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/jaymadden/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/jaymadden/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/g7/q92rbdc954j16ntmpvgt9g2h0000gn/T/go-build1901075686=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/Users/jaymadden/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/jaymadden/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.24.5/libexec'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/jaymadden/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.24.5/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.5'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Generated this file https://codeberg.org/Jay-Madden/toobig/src/branch/master/big.go then loaded it with gopls in neovim.

What did you see happen?

❯ nvim --clean --headless -u scratch.lua big.go
lsp_err_code=0
lsp_err_message=semantic tokens: range /Users/jaymadden/temp/toobig/big.go too large (271612 > 100000)
result=nil

What did you expect to see?

Above^ It comes from here https://github.com/golang/tools/blob/master/gopls/internal/golang/semtok.go#L69 which is a hardcoded constant in gopls.

It would be nice to expose that value as a configurable option so we could get allow larger file sizes and take the loading hit upfront?

Editor and settings

    vim.lsp.config("gopls", {
      cmd = { "gopls" },
      filetypes = { "go", "gomod", "gowork", "gotmpl" },
      settings = {
        gopls = {
          experimentalPostfixCompletions = true,
          analyses = {
            unusedparams = true,
            shadow = false,
          },
          staticcheck = false,
          gofumpt = true,
          completeUnimported = true,
        },
      },
      init_options = {
        usePlaceholders = false,
        semanticTokens = true,
      },
    })
    vim.lsp.enable("gopls")

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions