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: missing semantic tokens for function parameters in block #56257

Closed
danicc097 opened this issue Oct 16, 2022 · 6 comments
Closed
Assignees
Labels
FrozenDueToAge 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. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@danicc097
Copy link

gopls version

Build info

golang.org/x/tools/gopls v0.9.5
golang.org/x/tools/gopls@v0.9.5 h1:F3TO5th6TUg40FHrpxZfMkMlVaaTmByeEvylgVHGH2A=
github.com/BurntSushi/toml@v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
github.com/google/go-cmp@v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
golang.org/x/exp@v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
golang.org/x/exp/typeparams@v0.0.0-20220722155223-a9213eeb770e h1:7Xs2YCOpMlNqSQSmrrnhlzBXIE/bpMecZplbLePTJvE=
golang.org/x/mod@v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/sync@v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
golang.org/x/sys@v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/text@v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/tools@v0.1.13-0.20220908144252-ce397412b6a4 h1:glzimF7qHZuKVEiMbE7UqBu44MyTjt5u6j3Jz+rfMRM=
golang.org/x/vuln@v0.0.0-20220901221904-62b0186a1058 h1:YnB27EXBD8XxB0JcaOeluuvhF2kS4DrH0k+lpopG2xc=
honnef.co/go/tools@v0.3.2 h1:ytYb4rOqyp1TSa2EPvNVwtPQJctSELKaMyLfqNP4+34=
mvdan.cc/gofumpt@v0.3.1 h1:avhhrOmv0IuvQVK7fvwV91oFSGAk5/6Po8GXTzICeu8=
mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.19.1

go env

GO111MODULE=""
GOARCH="amd64"
GOBIN="//bin/tools"
GOCACHE="/home/daniel/.cache/go-build"
GOENV="/home/daniel/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/daniel/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/daniel/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.19.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/
/go.mod"
GOWORK="/***/go.work"
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2391207226=/tmp/go-build -gno-record-gcc-switches"

What did you do?

What did you expect to see?

Screenshot 2022-10-16 171523 -expected

What did you see instead?

Screenshot 2022-10-16 171523

Editor and settings

"go.testFlags": [],
"go.coverOnSingleTest": true,
"go.coverOnSingleTestFile": true,
"go.coverOnTestPackage": true,
"go.useLanguageServer": true,
"go.useCodeSnippetsOnFunctionSuggest": true,
"go.formatTool": "gofumpt",
"go.toolsManagement.autoUpdate": true,
"go.autocompleteUnimportedPackages": false,
"[go]": {
  "editor.insertSpaces": false,
  "editor.autoClosingBrackets": "always",
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.organizeImports": true
  },
  "editor.suggest.snippetsPreventQuickSuggestions": false,
  "editor.semanticHighlighting.enabled": true
},
"gopls": {
  "formatting.gofumpt": true,
  "build.experimentalWorkspaceModule": true,
  "ui.noSemanticString": true,
  "ui.noSemanticNumber": true,
  "ui.semanticTokens": true,
  "ui.diagnostic.staticcheck": true,
  "ui.completion.matcher": "Fuzzy",
  "analyses": {
    "ST1000": false,
    "ST1003": false,
    "SA5001": false,
    "nilness": true,
    "unusedwrite": true,
    "fieldalignment": false,
    "shadow": false,
    "composites": false
  },
  "ui.codelenses": {
    "generate": false,
    "regenerate_cgo": true,
    "test": true,
    "vendor": true,
    "tidy": true,
    "upgrade_dependency": true,
    "gc_details": true
  },
  "ui.diagnostic.annotations": {
    "bounds": true,
    "inline": true,
    "escape": true,
    "nil": true,
  },
},

Logs

@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 Oct 16, 2022
@gopherbot gopherbot added this to the Unreleased milestone Oct 16, 2022
@findleyr
Copy link
Contributor

CC @pjweinb

@findleyr findleyr added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 20, 2022
@findleyr findleyr modified the milestones: Unreleased, gopls/later Oct 20, 2022
@pjweinb
Copy link

pjweinb commented Oct 20, 2022

Thanks for reporting this. We need more information: what's the definition of 'routers'? Is it a type, a variable, or what?

@pjweinb pjweinb added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 20, 2022
@danicc097
Copy link
Author

In the example all are variables. To be more specific, consider:

image

variables in the block should be tokenized as variable.parameter as well. It's behavior already present in Pylance, for example

image

image

@pjweinb
Copy link

pjweinb commented Oct 21, 2022

  1. According to the spec a semantic token could be either one of 'parameter' or 'variable', but not both.
  2. Here is a file, like your example, with the semantic tokenization inserted as comments. (The comment has the length of the language token, the semantic token assigned, and a slice of semantic token modifiers.) What should be different?

/⇒4,keyword,[]/func /⇒1,function,[definition]/f[/⇒1,parameter,[definition]/T /⇒10,type,[]/comparable](/⇒1,parameter,[definition]/s []/⇒1,typeParameter,[]/T) /⇒5,type,[]/error {
/⇒3,variable,[definition]/set /⇒2,operator,[]/:= /⇒4,function,[defaultLibrary]/make(/⇒3,keyword,[]/map[/⇒1,typeParameter,[]/T]/⇒6,keyword,[]/struct{})
/⇒3,keyword,[]/for _, /⇒1,variable,[definition]/e := /⇒5,keyword,[]/range /⇒1,variable,[]/s {
/⇒2,keyword,[]/if _, /⇒2,variable,[definition]/ok /⇒2,operator,[]/:= /⇒3,variable,[]/set[/⇒1,typeParameter,[]/e]; /⇒2,variable,[]/ok {
/⇒6,keyword,[]/return /⇒3,namespace,[]/fmt./⇒6,function,[]/Errorf(/⇒8,string,[]/"bad %T", /⇒1,typeParameter,[]/e)
}
/⇒3,variable,[]/set[/⇒1,typeParameter,[]/e] /⇒1,operator,[]/= /⇒6,keyword,[]/struct{}{}
}
/⇒6,keyword,[]/return /⇒3,variable,[readonly defaultLibrary]/nil
}

@danicc097
Copy link
Author

Sorry I was referring to textmate scope of variable.parameter.
The semantic token should remain "parameter" inside the function. As of now it's variable, so I believe it should be:

/⇒4,keyword,[]/func /⇒1,function,[definition]/f[/⇒1,parameter,[definition]/T /⇒10,type,[]/comparable](/⇒1,parameter,[definition]/s []/⇒1,typeParameter,[]/T) /⇒5,type,[]/error {
/⇒3,variable,[definition]/set /⇒2,operator,[]/:= /⇒4,function,[defaultLibrary]/make(/⇒3,keyword,[]/map[/⇒1,parameter,[]/T]/⇒6,keyword,[]/struct{})
/⇒3,keyword,[]/for _, /⇒1,variable,[definition]/e := /⇒5,keyword,[]/range /⇒1,parameter,[]/s {
/⇒2,keyword,[]/if _, /⇒2,variable,[definition]/ok /⇒2,operator,[]/:= /⇒3,variable,[]/set[/⇒1,typeParameter,[]/e]; /⇒2,variable,[]/ok {
/⇒6,keyword,[]/return /⇒3,namespace,[]/fmt./⇒6,function,[]/Errorf(/⇒8,string,[]/"bad %T", /⇒1,typeParameter,[]/e)
}
/⇒3,variable,[]/set[/⇒1,typeParameter,[]/e] /⇒1,operator,[]/= /⇒6,keyword,[]/struct{}{}
}
/⇒6,keyword,[]/return /⇒3,variable,[readonly defaultLibrary]/nil
}

@gopherbot
Copy link

Change https://go.dev/cl/445095 mentions this issue: tools/gopls: argument in function bodies marked as parameter by semantic tokens

@golang golang locked and limited conversation to collaborators Oct 26, 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. 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. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants