Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add type, external, let word coloring && unit as constant#85

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@Faliszek
Copy link

@FaliszekFaliszek commentedFeb 22, 2021
edited
Loading

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:
reason

and rescript file look like this:

one-pro-before

This pr is mostly about 2 changes:

  1. Coloring word afterlet, type, externalbut 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)

  1. Coloring unit -() - (again inspired by vscode-ocaml-platform)

In my actual themeOne Dark Pro

Before
one-pro-before

After
one-pro-after

Dark+

Before:
dark-plus-before

After:
dark-plus-after

mewhhaha, danwetherald, and mxthevs reacted with thumbs up emojiandrefilimono, zetashift, LeoLeBras, fhammerschmidt, jjlee, danwetherald, ila-embsys, and mxthevs reacted with rocket emoji
@FaliszekFaliszek marked this pull request as ready for reviewFebruary 22, 2021 22:13
@chenglou
Copy link
Member

Hey thanks! I'll review this later but make sure you've seen#8 (comment)

@Faliszek
Copy link
Author

Faliszek commentedMar 15, 2021
edited
Loading

@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 withentity.name.function.

I will probably need to look into those changes once again, because since I open this PR,@bobzhang was able to shippattern 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

@chenglou
Copy link
Member

chenglou commentedMar 20, 2021
edited
Loading

I don't think() and and_unused should be specially highlighted; the former because it feels a bit too specialized and the latter because_unused can still be used, so it'll be misleading. Thecomment scope is misleading as well; as you've seen in that post, our priority is correctness of highlighting, so assigningcomment to_unused kinda doubly violates that.

However it's a good idea to assign some scope to_, because that one's truly "unused"/unusable. There's no good textmate scope for it though...

And yeah this implementation is nice and simple but I think we're missing patterns (each let binding is a pattern too), e.g.let Coords(x) = c and/or fields, but maybe that's ok... It's hard to tell where to cut and where to stop here.

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(a: int). I'm also thinking maybe we should just highlight every lower case identifier, but that might be too much.

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.

Faliszek reacted with thumbs up emoji

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...
"include":"#jsx"
},
{
"include":"#jsx-attributes"
Copy link
Author

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 😅

@bjornj12
Copy link

What is the status of this PR? would love syntax highlighting on let 🙏

Also is it just me or does this feel a bit weird?
I might be too used to Reasonml syntax (still stuck there working on jsx3 🙈) but should the "name" and "friends" not be a specific color?
image

Faliszek and lucas-teks reacted with thumbs up emoji

@Faliszek
Copy link
Author

Hi,
Sorry I am just stuck with work probably until end of May, so I will not continue working on it right now, but I would also love to have thefriends andname highlighted, but it is more complicated, and I didnt want to bloat this code unnecessary.

I will try to look at it in June. But I cant make any promises! 😅

@TheSpyder
Copy link

This will fix#89 (I guess I didn't search well enough when I logged it)

@Faliszek
Copy link
Author

Faliszek commentedJun 5, 2021
edited
Loading

And yeah no worries about the regexes. The problem isn't the regex, it's the archaic TextMate grammar format.

Now I exactly understand what you meant 😄
You guys already did great job with this grammar, but to finish all edge cases even only in all listed themes in README.md with correct scopes from language point of view might be very difficult to get it right.

My latetest changes:

  1. Set object property asvariable.object.property, but I don't go too far with it. So unfortunately in(a: int) -a also will be highlighted.

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 😅

  1. Add to existing polymorphic variant regexp additional scopesvariable.other.enummember (kind of correct from language point of view) andconstant.other.symbol (just to have different color) in One Dark pro.
  2. I also wanted to improve punctuation, but Dark+ don't highlight this scope. I found a scopeconstant.character - and it looks nicely in Dark+ and One Dark Pro but once again. Kind of stretch from logical point of view. I added it because when reading code, characters lik(, {, [ - are suggesting for me some kind of scope, and it is just easier to read. I also wanted to highlight "<", ">" but there is some trickery with jsx

Results:
Dark+

Zrzut ekranu 2021-06-5 o 18 54 08

One Dark pro
Zrzut ekranu 2021-06-5 o 18 54 24

@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

fhammerschmidt, Freddy03h, bjornj12, tsnobip, danwetherald, carere, and mxthevs reacted with heart emoji

@Faliszek
Copy link
Author

Faliszek commentedJun 7, 2021
edited
Loading

@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 delightfulhttps://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

bjornj12 reacted with thumbs up emoji

@hoichi
Copy link

What aboutlet with destructuring? I got a special style forlet bindings withOCaml Platform extension, but e.g., identifiers inlet (state, setState) = React.useState(...) are not tokenized and therefore not highlighted, which is kind of a bummer.

Disclaimer: no idea if TextMate grammar can do it at all.

@TheSpyder
Copy link

@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
https://marketplace.visualstudio.com/items?itemName=glennsl.sane-reason-grammar

A dedicated extension would be easier to use than patching the installed ReScript extension, which iswhat 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.

LeoLeBras, carere, fhammerschmidt, and tsnobip reacted with thumbs up emoji

@Faliszek
Copy link
Author

@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.

@TheSpyder
Copy link

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.

Faliszek, carere, LeoLeBras, fhammerschmidt, hoichi, Lomand, and tsnobip reacted with heart emojiFaliszek, carere, LeoLeBras, and fhammerschmidt reacted with rocket emoji

@zth
Copy link
Member

zth commentedMar 17, 2022

Just dropping a note in here that#367 will implement the equivalent of this, although in a different way. Thank you for your great work@Faliszek !

Faliszek reacted with heart emojiFaliszek reacted with rocket emoji

@Faliszek
Copy link
Author

Faliszek commentedMar 17, 2022
edited
Loading

@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 :)

zth reacted with heart emoji

@zthzth mentioned this pull requestMar 20, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@Faliszek@chenglou@bjornj12@TheSpyder@hoichi@zth

[8]ページ先頭

©2009-2025 Movatter.jp