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: embedded types are tokenized as identifiers #46068

Closed
soypat opened this issue May 9, 2021 · 3 comments
Closed

x/tools/gopls: embedded types are tokenized as identifiers #46068

soypat opened this issue May 9, 2021 · 3 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@soypat
Copy link

soypat commented May 9, 2021

What did you do?

Write the following code with semantic tokenizing enabled

type Model struct {}

type attitude float64

type Product struct {
	Model
	attitude
	V int // this line for demonstration of different tokens
}

What happened

Model and attitude are tokenized as identifiers (same color as V), not types (color of int).

What you expected

I expected Model and attitude to be tokenized as types, they are after all user defined types. One could argue they can be accessed as if they were identifiers (product.Model and product.attitude) but this obfuscates what really is happening: the type is being embedded and Model and attitude are type names, not field names.

Version info/env

What version of Go & gopls are you using (go version)?

$ go version
go version go1.16.3 linux/amd64
$ gopls version
golang.org/x/tools/gopls v0.6.11
    golang.org/x/tools/gopls@v0.6.11 h1:7S2k0xuVYc3secjy2uz0n+fGYxGJU6gXsLOmQ/r1HoI=
@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 May 9, 2021
@gopherbot gopherbot added this to the Unreleased milestone May 9, 2021
@findleyr
Copy link
Member

I agree with your assessment. It is more helpful to highlight them as types. @pjweinb what do you think?

@findleyr findleyr added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label May 10, 2021
@findleyr findleyr modified the milestones: Unreleased, gopls/unplanned May 10, 2021
@pjweinb
Copy link

pjweinb commented May 10, 2021

I think the code is failing to distinguish between the field specs
type A struct {
Model
}
type B struct {
Model int
}
The second 'Model' is a variable, the first might better be a type. I'll try to get to it soon; there's a few semantic token issues already on the queue.

@pjweinb pjweinb self-assigned this May 10, 2021
@findleyr findleyr added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels May 10, 2021
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/318749 mentions this issue: internal/lsp: in semantic tokens, better distinguish between types and variables

@golang golang locked and limited conversation to collaborators May 11, 2022
@rsc rsc unassigned pjweinb Jun 23, 2022
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. NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants