gleam icon indicating copy to clipboard operation
gleam copied to clipboard

Add basic semantic tokens implementation

Open u9g opened this issue 1 year ago • 8 comments

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 avatar May 05 '24 02:05 u9g

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.

u9g avatar May 06 '24 00:05 u9g

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

lpil avatar May 06 '24 08:05 lpil

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

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

u9g avatar May 06 '24 12:05 u9g

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

inoas avatar May 07 '24 18:05 inoas

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?

lpil avatar May 07 '24 18:05 lpil

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.

PgBiel avatar May 15 '24 19:05 PgBiel

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.

MystPi avatar May 15 '24 19:05 MystPi

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

nicklimmm avatar May 17 '24 15:05 nicklimmm

Closing due to inactivity. Please feel free to reopen in future.

lpil avatar Jun 20 '24 13:06 lpil