Skip to content

Neovim client: fix semantic tokens #757

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

Merged
merged 2 commits into from
Apr 13, 2023

Conversation

aspeddro
Copy link
Contributor

Neovim 0.9 add support for semantic tokens.

When opening a file and editing I get the following error: E5248: Invalid character in group name

I saw that the server registers tokens that are not in the specification: support-type-primitive, jsx-tag and jsx-lowercase.

This PR change name of tokens:

  • support-type-primitive -> type
  • jsx-tag -> class (class was used as module name, now it's namespace)
  • jsx-lowercase -> interface (div, h1)

One question: Why emit a token for jsx-tag, the < and > in <div>? Couldn't this be done via regex?

Forum post: https://forum.rescript-lang.org/t/neovim-vim-rescript-lsp-semantic-tokens-issue-and-maintenance/4387

Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

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

I don't remember all the details on top of my head, but the names were selected after trying many themes.
Now we'd need to know that these changes have no effect on those themes.

@cristianoc
Copy link
Collaborator

Can semantic tokens be turned off in neovim until all works?

@aspeddro
Copy link
Contributor Author

Can semantic tokens be turned off in neovim until all works?

yes

@cristianoc
Copy link
Collaborator

I'm afraid this PR will (from memory but I could be wrong) break some themes.

@aspeddro
Copy link
Contributor Author

aspeddro commented Apr 12, 2023

It seems not, because semanticTokenScopes maps to the same TextMate Scope.

This changes the name of the token the server emit, but the semanticTokenScopes field didn't change the TextMate scope target.

Example: previously the token jsx-lowercase was mapped to entity.name.tag, I changed jsx-lowercase to interface but it still gets mapped to entity.name.tag

VSCode Semantic token map

Edit 1:

This PR can change colors.

If a theme applied a color to the class token it would highlight the module name, with this PR the color will be different because the module name now uses the namespace token.

@aspeddro
Copy link
Contributor Author

I'm going to do some tests.

@aspeddro
Copy link
Contributor Author

Dark (default dark)

Before:

image

After:

image

Light (default light)

Before:

image

After:

image

Solarized Dark

Before:

image

After:

image

Solarized Light

Before:

image

After:

image

Monokai Dimmed ⚠️

Before:

image

After:

image

Tomorrow Night Blue ⚠️

Before:

image

After:

image

One Dark Pro ⚠️

Before:

image

After:

image

@aspeddro
Copy link
Contributor Author

aspeddro commented Apr 13, 2023

Three themes have changed: Monokai Dimmed, Tomorrow Night Blue and One Dark Pro.

The changes were in the token < and >

Curious that the token </ is not emited.

@cristianoc
Copy link
Collaborator

Three themes have changed: Monokai Dimmed, Tomorrow Night Blue and One Dark Pro.

The changes were in the token < and >

Curious that the token </ is not emited.

The token </, if I remember correctly, is handled via regexp, as it's easy to recognise. While < and > are really overloaded and need the help of semantic highlighting.

So based on these findings, is it possible to handle the issue on the neovim side?

@cristianoc
Copy link
Collaborator

In general, I just don't know what the constraints are with neovim. One could also do everything via grammar, which is less precise but avoids breaking things. As long as that extra complexity does not affect the main extension.

@aspeddro
Copy link
Contributor Author

So based on these findings, is it possible to handle the issue on the neovim side?

No, because it is necessary to change the name of the token emited by the server. Ideally, the specification would have a name for the token < and >, but it doesn't.

The best approach is to not emit < and > as jsx_tag.

@cristianoc
Copy link
Collaborator

So based on these findings, is it possible to handle the issue on the neovim side?

No, because it is necessary to change the name of the token emited by the server. Ideally, the specification would have a name for the token < and >, but it doesn't.

The best approach is to not emit < and > as jsx_tag.

That breaks things for 98% of users to benefit 2%? Or maybe I don't understand the suggestion.

@aspeddro
Copy link
Contributor Author

Yes, you are correct.

What I'm saying is that the LSP specification should have a token to jsx.

I will continue emitting the token, but I will change the token type.

@aspeddro
Copy link
Contributor Author

I changed the token from class to modifier.

One Dark Pro

After:

image

Tomorrow Night Blue

After:

image

@cristianoc
Copy link
Collaborator

So this seems to solve the issue.
Anything else pending, or can this go ahead?

@cristianoc
Copy link
Collaborator

I guess a quick check is needed that the other styles still work.

@aspeddro
Copy link
Contributor Author

Yes, I tested it on all themes supported by the extension.

@cristianoc
Copy link
Collaborator

Yes, I tested it on all themes supported by the extension.

Fantastic. Thank you so much for sorting this out. Pretty subtle stuff.

@cristianoc cristianoc merged commit 82192fb into rescript-lang:master Apr 13, 2023
@aspeddro aspeddro deleted the fix-semantic-tokens branch October 12, 2023 02:04
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.

2 participants