-
Notifications
You must be signed in to change notification settings - Fork 48
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
Confusing syntax highlighting #11
Comments
I understand your problems with the highlighting, however some of that is due to your theme. In my theme function names in type signatures have a color different from that of prelude functions, so I think the only way to 'fix' that is to remove highlighting for prelude functions alltogether, which might not be the worst idea, since the set of types and functions exposed in prelude differs a lot between different versions of haskell/ghc. For some reason on my theme though prelude types now have the same color as data constructors, even though I didn't change anything. If you want to influence that however, you can either edit the theme, or try reassigning the tags in the language grammar. Also for your list, I'd add (as distiction)
As for function arguments, this one's quite tricky, because of how permissive Haskell's grammar is with newlines. |
Oh and I think the issue with the three colors for types, is that there's no appropriate rule for inline type signatures. |
Yes. Also I don't really see value in highlighting Prelude functions as there is no inherent difference.
That is true some fit better than others.
Type constructors are basically types. It would make sense to color type variables slightly different. But it's not a priority to me.
Defintely. I would treat them like regular functions, which they are.
Why can't there just be Type? Why differentiate? I don't think there is a difference between an inline type and the regular "type signature" type. Is there? |
Me neither. Interestingly, if you look at the theme selector and visual rules, they aren't special because they are prelude functions, but because they are the only ones actually marked as functions. All other functions are unmarked.
I think its nice for beginners, to have a visual distinction here.
Maybe, but they differ from functions because they are infix, which in my opinion warrants a visual distinction too.
That's not what I meant. I don't mean to make a visual distinction. What I'm saying is that the Haskell grammar currently does not detect inline type signatures as type signatures. |
Maybe, but you have to be careful. Too many colors reduce readability. And infix functions are usually pretty readable by default as they are symbols most of the time.
I see. I am not familiar with the internals. Maybe there's a way to use regex since all types appear after |
Removed all prelude functions Added rules for inline type signatures Changed data, newtype and type markup to be like type signature See #11
Added more end chars to inline type signature See #11
I have implemented some of your suggestions, maybe have a look at it and tell me what you think. |
I agree, I like it too. If you noticed I also changed how data definitions and type definitions are highlighted, they are constant with type signatures now. As for the function itself, I'm still trying to figure out how best to do that. I't be relatively easy to highlight the function name, if there is an I't probably (most likely) also apply to And there's the question whether to highlight ne name only if there are arguments following it. In my opinion it'd be best to highlight them all, which should make it easier to figure out where something is defined, no matter whether it's a function or other constant. |
Also as a tip: the grammar only adds tags to the source code elements. The theme governs the actual colors. If you want to change how the highlighting works, you can probably submit some patches to the theme, by adding Haskell specific rules. |
I am not sure if highlighting let the same way as global functions is such a good idea. It's easier to scroll through a file when you immediately see where a function begins. But anyway.. you forgot that there are ways to define functions without fun a
| a > 3 = ...
| otherwise = ... |
I didn't forget. As I said, those with Have you had a look at it yet? I implemented the version with |
I did. Yeah you're right, both technically only differ in scope. But I still find it a bit annoying if there something in my do-block that looks like a new global function. It's hard to see where global functions start and end. |
I've published a new version ( I'm not sure yet whether to add the highlighting for function names in definitions and for identifiers and so on. |
@JustusAdam Are you accepting pull requests? I, too, think that I'd be glad to add these in if you don't mind. Also, slightly unrelated to above, but, while the mic is still hot..... How attached are you to the XML format? Would you accept a PR if I addressed the above issues and converted from XML to JSON? IMHO, JSON is much easier to maintain. Thanks for considering 😊 |
Are As far as the JSON, XML thing is concerned: I personally prefer JSON, but when I wrote/converted this grammar there was no mention of a JSON format for the grammar in the vscode docs. |
Yep, just confirmed again to make sure.
That's a fair point. No disagreement with your logic. However.... Would it be fair to say that for an overwhelming majority of the cases, the operations defined in What about a compromise between our opinions here and scoping the operations in Do seasoned haskell users ever re-declare those functions to non-functions? Or are they generally the same type in those circumstances?
Fair concern. I'll leave that to you. At the end of the day, if we can't find a common ground, I'll prob just fork the repo. No hard feelings either way! |
I have reached a decision. Besides I think there's already a lot of colour floating around here so I don't think adding more makes anything easier to read. Let me know if you'd like to submit a PR for that change otherwise I'm putting it on my agenda. In actuality I'd really like to hear from a beginner Haskell programmer how they feel about special highlighting for "standard" functions and operators (and by "standard" I mean a stable, useful subset of As for the JSON language configuration. I'd tend to agree that a JSON formatted config is easier to read, maintain and reason about because there's less syntax clutter. If vscode accepts a JSON grammar I'll merge a PR for this if you send me one. |
@JustusAdam thank you so much for this extension.. I'm doing Haskell for the first time and it's.. brutal, but this extension helps a lot, great work! @dsifford regarding the brackets.. I suggest to try: Bracket Pair Colorizer Definitely helps with Haskell: My biggest trouble when reading Haskell is differentiating constructor and functions from variables or arguments: here the function, the arguments, the constructor Lcall are all of the same color, it makes reading Haskell code very difficult for beginners.. because you have to spot where the functions are vs Constructors vs arguments vs variables. Let me know if I can help in any way 🙏 |
@phil-lgr That is an issue of your theme, not the Haskell highlighting. I cannot, unfortunately, directly influence how things are highlighted I can only make suggestions to the theme. If you choose a different theme ("Monokai" for instance) it will actually highlight the constructors 😉 |
As @phil-lgr said, Is it possible to differentiate functions from variables or arguments ? I used TM Scope to inspect these elements , they're all recognized as "source.haskell". |
@nanlan2017 You mean top level function declarations? Like this one? foo argument = body You want |
I'm using https://www.monokai.pro/ and yes.. it would be really nice |
So first of all, I don't think it is a good idea to highlight functions specifically. Haskell makes no distinction between functions and data (apart from a bit of syntactic sugar) and so neither should we. However that's not the real problem. The grammar possibilities in vscode are somewhat limited. Specifically highlighting top level identifiers is tricky, if the So we could highlight foo arg = bar But not foo arg
= bar Which is common syntax, especially when the argument patterns are longer. I think this would lead to very confusing behaviour of the highlighter. |
Closing as syntax highlighting for prelude functions/types has since been removed. |
The purpose of syntax highlighting is in my opinion to tell different type of constructs apart. It would be great to tell these apart by color:
Int
,Text
,IO a
let
,otherwise
,::
,->
5
,"String"
Right
,Just
(
,)
, `But right now, there are:
I find the highlighting confusing at the moment. What do you think?
btw. this is not just the theme I'm using, most other themes behave like that
The text was updated successfully, but these errors were encountered: