-
Notifications
You must be signed in to change notification settings - Fork 59
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
Improve Semantic Token Type #213
Comments
In case you don't know this, The vscode-zig extension relies on the ZLS LSP which is responsible for providing the semantic tokens. So everything I am about to talk about is mostly unrelated to the vscode-zig extension.
This has very recently been resolved in zigtools/zls@2e5a2a5. Function parameter should now get the semantic token type "parameter" even when
There is no standardized semantic token type for a constant. All pre-defined semantic token types can be found here. Instead a "variable" semantic token type can be emitted with the "readonly" modifier. In the past, I had looked into adding the "readonly" modifier to all constants in Zig but this caused some observable changes to the default VS Code themes:
I have also tested Sublime Text and some colorschemes in neovim but they did not have any observable changes. Even though I think that an LSP should not decide how to emit semantic token information based on how it affects various editors, I personally find this change worse than the status quo. Zig code is usually heavy on const variables. With the addition of function parameters and capture values which are also constants, the code becomes littered with "readonly" tokens. But this is just my personal option, the code in the images above is a bit cherry-picked by me to highlight this behavior. One possible solution I am considering is to lie to the editor/client and give non-const variables the "readonly" modifier. This is how it would look like:
This would avoid the "everything becomes blue" problem while still allowing themes to make use of the "readonly" modifier. I have created a branch of ZLS that implements a config option the experiment with different behaviour for the "readonly" modifier. "zig.zls.path": "/path/to/zls/zig-out/bin/zls",
"zig.zls.additionalOptions": {
// `never` means that nothing will get the "readonly" modifier.
// `mutable_is_readonly` means that non-const variables with get the "readonly" modifier.
// `constant_is_readonly` means that all constants including function parameters and capture values will get the "readonly" modifier.
"zig.zls.semanticTokensReadonlyBehaviour": "constant_is_readonly",
}, It would also be possible to keep the status quo and instead emit a custom non-standardized semantic token modifier like |
Hello @Techatrix and thanks for your answer that is really detailed. Keep up the good work and thank you again ;) |
Hi, I'm toying with theme improvement (cattpuccin) for Zig and I ran into few tokens that are :
First image: Token don't exists
Second image: Mark as Variable instead of constant
So is there any chance that this will be improved in a near futur ? :)
The text was updated successfully, but these errors were encountered: