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

Comments

@soypat
Copy link

@soypat 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 this to the Unreleased milestone May 9, 2021
@findleyr
Copy link
Contributor

@findleyr findleyr commented May 10, 2021

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

@pjweinb
Copy link

@pjweinb 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
@gopherbot
Copy link

@gopherbot gopherbot commented May 11, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants