-
Notifications
You must be signed in to change notification settings - Fork 57
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
Add type, external, let word coloring && unit as constant #85
Add type, external, let word coloring && unit as constant #85
Conversation
Hey thanks! I'll review this later but make sure you've seen #8 (comment) |
@chenglou Yep, I saw it and I tried to implement those changes in the smallest way possible, but i have no idea to which scopes we want/should assign those so I went with I will probably need to look into those changes once again, because since I open this PR, @bobzhang was able to ship pattern match over modules (which is great)! 🥳 So my PR needs some work. But not sure how we should approach that here (like i said earlier, regexp is not my favorite thing in the world 😄 ). Anyway, any feedback is welcome |
I don't think However it's a good idea to assign some scope to And yeah this implementation is nice and simple but I think we're missing patterns (each let binding is a pattern too), e.g. As for types, I'm 1. not sure they should be highlighted the same way as values and 2. Either way they're not recursively highlighted here within fields and for annotations like And yeah no worries about the regexes. The problem isn't the regex, it's the archaic TextMate grammar format. ReScript's grammar is complex and we're essentially trying to use regexes and very weak TextMate matching logic here to emulate a full blown parser program. That's why in that thread I advised thinking only in tokenizer and not parser (but even that falls apart because JSX and template literal are that complex). Anyway, just some brain dump. |
It's technically a constant but I think if the parentheses in `f()` and `let f = () => 1` are highlighted but not `f(a)` and `let f = (a) => 1`, then it's confusing. The elegance of `()` being "just" a regular value in ocaml (which isn't even true; it's already a special piece of syntax) doesn't translate well here and nor should we highlight said elegance when the analogy with function parens is stretched that thin.
`_foo` can actually be used as a value, so highlighting it as a comment is very misleading. Imagine seeing that greyed out, removing it, and seeing a type error. We can potentially highlight `_`, because that's genuinely not usable as a value, except we VSCode/textmate doesn't have a good scope for it...
grammars/rescript.tmLanguage.json
Outdated
@@ -516,10 +512,6 @@ | |||
{ | |||
"include": "#jsx" | |||
}, | |||
{ | |||
"include": "#jsx-attributes" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I tried to also include some jsx highlight - but i just gave up, and forget to remove it 😅
Hi, I will try to look at it in June. But I cant make any promises! 😅 |
This will fix #89 (I guess I didn't search well enough when I logged it) |
Now I exactly understand what you meant 😄 My latetest changes:
But I also wanted to improve the rest of coloring, but even If i find matching scope for something, it is supported in one theme, but not in other. So the next ones are kind of a stretch 😅
Results: @chenglou No hurt feelings, if this will be closed and not merged. I see now that creating correct grammar with proper logical text-mate scoping and correctnes of colors in popular themes, is a hell of a task to get it right. But personally I will prefer having not that correct coloring with stupid scopes, than no coloring at all. But I read your reasoning behind it, and I understand you 100%. So if i need to develop with rescript again, i will probably copy my changes and paste it directly to extension grammar :P Feedback welcome |
@chenglou Also I am starting to wonder, if dedicated theme for rescript might be a good idea? (for example with two variants dark, and light) I started play with Elixir, and they are also have complicated grammar, and I find elixir specific theme for vscode really delightful https://marketplace.visualstudio.com/items?itemName=Arsen.darcula-theme-for-elixir I am might be able to give it a shoot to create one with your guidance, on what, and how we want to highlight things |
What about Disclaimer: no idea if TextMate grammar can do it at all. |
@Faliszek would you consider releasing this as a standalone vscode extension? Or would you mind if I did one based on your work? I didn't realise a grammar-only extension was possible, but I just found this A dedicated extension would be easier to use than patching the installed ReScript extension, which is what was recommended on the forum. It would also give us a good place to battle-test highlighting ideas before recommending them to the main extension. |
@TheSpyder I mean if other authors of this extension have nothing against fork this extension, feel free to use my changes as you like :) Personally I probably won't find time needed to release and maintain extension in near future. |
My intention is not to fork the whole extension and compete, only to have a way to use your grammar without patching installed extensions. I’ll see what I can cook up this weekend. |
@zth yup, I already saw your PR, it looks great! Thank you so much for doing this! You rock :) So I think it's ok to close this one :) |
Hi,
First things first. I want to thank you all for your work on this amazing project and this extension.
And now the rest.
Description
One thing that i want to point straight away, I rarely wrote any regexp so sorry in advance if those changes are just garbage 😅
But I look through on files in my project and I think i didn't break any working grammar.
Presented code is mostly from rescript/reason docs, I think i don't miss any possible scenario for using let, external, and type.
What changed
When working with .re files and with vscode-ocaml-platform I have (imo) beatiful syntax highlighting:
and rescript file look like this:
This pr is mostly about 2 changes:
let, type, external
but alsotype rec, let rec
keyword asentity.name.function
(the same way vscode-ocaml-platform does it).The word I am matching is
[a-z][a-z_A-Z_0-9_]*
- this (i hope) match every valid name for type and let name declaration.NOTE: one small change that I thought would be nice to have is match variable started with
_
as comment (line 22 on screens) it looks very cool in my current One Dark Pro theme. (the same way as ocaml-platform)()
- (again inspired by vscode-ocaml-platform)In my actual theme One Dark Pro
Before
After
Dark+
Before:
After: