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

Add basic semantic tokens implementation #3099

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

u9g
Copy link

@u9g u9g commented May 5, 2024

This pr adds an ast visitor and a semantic token implementation for

  • {module}.{label}
  • {tuple}.{label}
  • {tuple}.{index}
  • {record}.{label}
  • pattern of variable (ie let x = 9)
  • import coloring depending on whether the import is a type, function, record, or other

@u9g u9g changed the title add basic semantic tokens implementation Add basic semantic tokens implementation May 5, 2024
Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! What functionality does this provide to the user?

It would be best to open an issue to discuss new features before implementing them as there's no guarantee we can accept any particular change.

@u9g
Copy link
Author

u9g commented May 6, 2024

Hello! What functionality does this provide to the user?

Here's a before and after in vscode
image
image

It would be best to open an issue to discuss new features before implementing them as there's no guarantee we can accept any particular change.

it's fine if this isn't accepted, I developed this for my own use but I also think it would be nice to see an implementation land in the standard LSP too.

@lpil
Copy link
Member

lpil commented May 6, 2024

Sorry, I'm a bit confused. It looks like it broke your syntax highlighting?

@u9g
Copy link
Author

u9g commented May 6, 2024

Sorry, I'm a bit confused. It looks like it broke your syntax

This is using the latest released vscode-gleam, not my syntax.

@inoas
Copy link
Contributor

inoas commented May 7, 2024

I think it shows function values versus other values in different colours

@lpil
Copy link
Member

lpil commented May 7, 2024

In the after screenshot it seems to inconsistently highlight variables, and not all the keywords are highlighted any more.

That aside, what does this enable for the programmer?

@PgBiel
Copy link
Contributor

PgBiel commented May 15, 2024

I believe the main point is that information about the types of values can be used for highlighting (depending on how your theme handles this information), but this is also useful for basic highlighting in some editors which support it, such as KDE's Kate. If correctly done, this can be pretty valuable.

@MystPi
Copy link
Contributor

MystPi commented May 15, 2024

I've been wanting something like this for a long time! When I started out with Gleam this was one of the features I missed most from the LSP.

In the after screenshot it seems to inconsistently highlight variables, and not all the keywords are highlighted any more.

That aside, what does this enable for the programmer?

It's not highlighting variables inconsistently; they are highlighted based on whether they are a function (yellow) or another value (blue). This is actually really helpful in other languages like JavaScript that do this:
image

The only keyword that looks wrong (from what I can tell) is the as in the topmost import. Likely something that would need to be fixed before merging.

@nicklimmm
Copy link
Contributor

We have an existing AST visitor implementation here: https://github.com/gleam-lang/gleam/blob/main/compiler-core/src/ast/visit.rs

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

Successfully merging this pull request may close these issues.

None yet

6 participants