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: semantic tokenizing of package identifier #46475

Closed
soypat opened this issue May 31, 2021 · 6 comments
Closed

x/tools/gopls: semantic tokenizing of package identifier #46475

soypat opened this issue May 31, 2021 · 6 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. 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.

Comments

@soypat
Copy link

soypat commented May 31, 2021

What version of Go 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=

What did you do?

Import any package like so:

import main

import "io"

func main() {
    err := io.EOF
    panic(err)
}

What did you expect to see?

io tokenized differently from variables such as err in this case.

What did you see instead?

io and err have same color.

Motivation

I may be wrong, but are packages tokenized just like variables? It seems to be the case. I propose there be some distinction so that one can easily identify when one is dealing with a package level identifier (i.e. io.EOF) vs. a method/field (i.e. err.Error()).

Tokens available for a LSP implementation are listed here.. I believe class semantic token would be suited for packages as they represent a similar namespacey construct.

@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 31, 2021
@gopherbot gopherbot added this to the Unreleased milestone May 31, 2021
@pjweinb
Copy link

pjweinb commented May 31, 2021 via email

@soypat
Copy link
Author

soypat commented Jun 1, 2021

First of all thanks for the quick reply. You are right about there being a editor.tokenColorCustomizations option but I'm getting only the following properties available

  • comments
  • functions
  • variables
  • keywords
  • numbers
  • strings
  • textMateRules
  • types

I'm on VSCode using Darcula theme. Using namespace as a property has no effect. variables does have a effect

@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.7.0 Jun 1, 2021
@stamblerre stamblerre added this to To Do in gopls semantic tokens via automation Jun 1, 2021
@stamblerre
Copy link
Contributor

Import any package like so:

import main

import "io"

func main() {
    err := io.EOF
    panic(err)
}

I just wanted to point out that there's a mistake in this example--it should be package main on the first line. Does fixing that correct the issue for you?

@soypat
Copy link
Author

soypat commented Jun 1, 2021

@stamblerre I was testing actual working packages, I typed the example up as a MWE. The issue still holds.

@stamblerre
Copy link
Contributor

I think that, in this instance, this is an issue with the Darcula theme that you could perhaps raise in that repository. For contrast, see how it looks with VS Code's default dark theme:

Screen Shot 2021-06-02 at 10 21 23 AM

io is indeed tokenized as a namespace:

Screen Shot 2021-06-02 at 10 22 33 AM

which logically makes more sense than changing it to class.

And err is a variable, as expected:

Screen Shot 2021-06-02 at 10 23 10 AM

If the Darcula theme doesn't provide differing colorization for namespace tokens, then that is an issue with the theme, not the tokenization here.

@stamblerre stamblerre added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jun 2, 2021
@soypat
Copy link
Author

soypat commented Jun 2, 2021

You are right. Switching to VSCode default highlighting I can see the namespace colorization. I'm not sure what I was doing wrong before but after testing this and changing the settings (below) I can change Darcula's namespace token color.

"editor.semanticTokenColorCustomizations": {"rules": {"type": "#ff0000","namespace":"#ff0000"}},

I'm closing this as it is not an issue related to go or gopls.

@soypat soypat closed this as completed Jun 2, 2021
gopls semantic tokens automation moved this from To Do to Done Jun 2, 2021
@stamblerre stamblerre removed this from the gopls/v0.7.0 milestone Jun 2, 2021
@golang golang locked and limited conversation to collaborators Jun 2, 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. 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
No open projects
Development

No branches or pull requests

4 participants