-
-
Notifications
You must be signed in to change notification settings - Fork 388
Semantic Tokens: Distinguish (possibly-partially-applied) infix operators from normal functions/variables #3969
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
Comments
We even have a good LSP token type for this: |
Also, what about |
Indeed, as I already suggested in my solution section 😃
Good catch. Both seem making sense, but I prefer treating it as a function provided that |
I realized, there is also a possible overlap here. take |
Yep. I think you already have support for returning multiple types and picking one. I note that there is a client capability for supporting overlapping tokens. I guess in principle that means we could return two tokens for the same span? I don't know what that would do. |
I suspect it is scarcely supported by clients. I am inclined to take precedency of |
I agree |
I prefer it to be infix operator, but it is just a matter of taste. We might be able to make such precedence preference configurable, but that seems rather complex and non-ergonomic. After all, humans can tell the infix operators from plain class method as it consists of (non-letter) symbols. So, yes, treating it as class method seems making sense to me. |
I think operator(as class, function, class method, field, type operator) might be bertter off as modifier. But default LSP does not have such modifier. |
We have several clashes already, in fact:
Something can be all of a function, an operator, and a method! On the configurability front, we could consider making it so that we don't take certain things into account. So e.g. you could turn off highlighting methods entirely, with the intention that you now get the next token assignation that makes sense. Alternatively we could expose priority options for the different token types (as integers), and let people change them. |
Yes, it does make sense to offer more configurability. |
@soulomoon Thanks! And, sorry for my late reply (I had been a bit busy for the past two weeks). I will give it a try. |
Looks good! Here is the example (I switched the colour theme from One Monokai to Material Theme Ocean, as the former doesn't work well with semantic tokens for the time being). Without semantic tokens: ... and with semantic tokens: Now we can distinguish binary operators from functions! Looks really good 😄 I also tested Without semantic tokens: ... and with semantic tokens: The above example has both symbolic and
I think the current treatment is good enough - after all, |
Thank you for the detailed feed back on this. @konn |
Is your enhancement request related to a problem? Please describe.
First of all, thank you @soulomoon for implementating fantastic support for semantic tokens! I've long been waiting for this feature 🎉
After the release of 2.6.0.0, I've just tested it and looks really good. I think it will become even better if one can tell (possibly partially-applied) infix operators from ordinary variable/functions semantically.
For example, the image below is what I apply One Monokai + Semantic Tokens to the code fragments containing several
($)
s:In above, functions being applied and
($)
s are all coloured homogeneously. Without semantic colouring, OTOH, we got:I think the latter case gives more legible highlighting - binary operator shines between functions.
Describe the solution you'd like
Add something like
TBinaryOperator
constructor toHsSemanticTokenType
, map its default tooperator
token, and also allowing users to map them to what they like (as we already did forhaskell.plugin.semanticTokens.config.dataConstructorToken
etc).Describe alternatives you've considered
Perhaps, as we have already done to plain symbols, there can be
TBinaryFunction
andTBinaryVariable
, as the function declaration can take its argument in infix-form.The text was updated successfully, but these errors were encountered: