Skip to content
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

Dune syntax highlighting fix #742

Merged
merged 4 commits into from
Feb 1, 2022
Merged

Conversation

SaySayo
Copy link
Contributor

@SaySayo SaySayo commented Oct 16, 2021

Fixed the dune syntax by rewriting the dune.json in a similar fashion to the dune-project.json and dune-workspace.json syntaxes (#106). @mnxn please review

@mnxn mnxn self-requested a review October 16, 2021 17:14
@mnxn
Copy link
Collaborator

mnxn commented Oct 19, 2021

A couple of things I've noticed so far:

  • Missing executable fields
    image

  • Missing lint
    image

  • Overuse of variable.other.declaration.dune. I only used this scope name when something is being declared. In this example, I would only expect public_name and name to have the variable.other.declaration.dune highlighting.
    image

@rgrinberg: do you know of any large dune files that could be used to verify the syntax highlighting?

@SaySayo
Copy link
Contributor Author

SaySayo commented Oct 19, 2021

I used this dune docs(https://dune.readthedocs.io/en/stable/dune-files.html#dune) which I assumed is the official doc for referencing of the stanzas and It didn't contain lint and most of the executables you just listed, hence why they weren't included. Can you please recommend a more accurate doc that contains all the executables so I can update it.

@mnxn
Copy link
Collaborator

mnxn commented Oct 19, 2021

Hmm. You are right about lint, I don't know why it isn't documented. That is the official documentation.

The executable fields are all listed though: https://dune.readthedocs.io/en/stable/dune-files.html#executable
Scroll down to where it describes the <optional-fields>.

@SaySayo
Copy link
Contributor Author

SaySayo commented Oct 19, 2021

Also, I assumed the declarations were variables because the available syntax highlight options with a foreground color were either constants, variables, keywords, or strings. And I was certain they weren't constants or keywords. What do you recommend I use instead so I can make necessary changes

@mnxn
Copy link
Collaborator

mnxn commented Oct 19, 2021

either constants, variables, keywords, or strings.

If it's not one of those, then don't include the contentName field, it's optional.

"1": { "name": "keyword.language.dune" }
},
"patterns": [{
"comment": "name/public_name/package/libraries/link_flags/link_deps/modules/root_module/preprocess/preprocessor_deps/modules_without_implementation/optional/enabled_if/promote/foreign_stubs/foreign_archives/forbidden_libraries/embed_in_plugin_libraries",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mnxn The executable optional fields were listed here. I'll go through it again to see why they weren't highlighted in your tests

@tmattio
Copy link
Collaborator

tmattio commented Oct 19, 2021

I used this dune docs(https://dune.readthedocs.io/en/stable/dune-files.html#dune) which I assumed is the official doc for referencing of the stanzas and It didn't contain lint

Feel free to open an issue on dune (https://github.com/ocaml/dune) if you notice undocumented fields @SaySayo.

@SaySayo
Copy link
Contributor Author

SaySayo commented Oct 19, 2021

If it's not one of those, then don't include the contentName field, it's optional.

Noted. I'll make the necessary changes.

@SaySayo
Copy link
Contributor Author

SaySayo commented Oct 19, 2021

  • Overuse of variable.other.declaration.dune. I only used this scope name when something is being declared. In this example, I would only expect public_name and name to have the variable.other.declaration.dune highlighting.

To be clear, Do you mean js_of_ocaml, mode, pps etc aren't variables and I should remove the variable highlighting on them?

@mnxn
Copy link
Collaborator

mnxn commented Oct 19, 2021

To be clear, Do you mean js_of_ocaml, mode, pps etc aren't variables and I should remove the variable highlighting on them?

Yes, that's right.

syntaxes/dune.json Outdated Show resolved Hide resolved
},
"patterns": [{
"comment": "name/public_name/package/libraries/link_flags/link_deps/modules/root_module/preprocess/preprocessor_deps/modules_without_implementation/optional/enabled_if/promote/foreign_stubs/foreign_archives/forbidden_libraries/embed_in_plugin_libraries",
"begin": "\\([[:space:]]*(name|public_name|package/libraries|link_flags|link_deps|modules|root_module|preprocess|preprocessor_deps|modules_without_implementation|optional|enabled_if|promote|foreign_stubs|foreign_archives|forbidden_libraries|embed_in_plugin_libraries)\\b",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the / in package/libraries is a typo here. It should be package|libraries.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also name|public_name should be separated into it's own rule with "contentName": "variable.other.declaration.dune" the same way as in a library.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@mnxn mnxn Oct 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pps in preprocess needs to be highlighted the same as a library:
image

},
{
"comment": "executable/executables",
"begin": "\\([[:space:]]*(executables*)\\b",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The * makes the rule match executable followed by any number of s's.

It should be:

Suggested change
"begin": "\\([[:space:]]*(executables*)\\b",
"begin": "\\([[:space:]]*(executable|executables)\\b",

Also executables needs to support names and public_names: https://dune.readthedocs.io/en/stable/dune-files.html#executables

syntaxes/dune.json Outdated Show resolved Hide resolved
syntaxes/dune.json Outdated Show resolved Hide resolved
syntaxes/dune.json Outdated Show resolved Hide resolved
@rgrinberg
Copy link
Contributor

@SaySayo do you plan to work on this PR?

@SaySayo
Copy link
Contributor Author

SaySayo commented Nov 21, 2021

Yes I do. I made the changes @mnxn requested and I'm waiting on a review.

@mnxn
Copy link
Collaborator

mnxn commented Nov 25, 2021

Sorry for not looking at this earlier.

I tested this syntax with some example dune files from the dune repo and there are still many unrecognized fields:

Examples

image

image

image

image

image

I think there is still a lot of work left until this syntax is complete. The core issue is that there are too many unrelated fields in certain rules: like this line for example. Some of the fields can have extra options or specific input, so it doesn't make sense to combine them all.

What could make this easier to work on is an example dune file that covers most of the dune syntax. That way you would just need to scroll through that file to see what is being highlighted correctly or not. Unfortunately, I haven't found anything like that so far.

I don't want to merge this PR until the syntax is complete. You are free to keep working on this if you want, but I can't guarantee to keep up with code reviews. I've had much less time for reviews recently and this is a very big PR.

@SaySayo
Copy link
Contributor Author

SaySayo commented Nov 25, 2021

I'll keep working on this PR till it fixes all the issues you mentioned, might take me a couple weeks as I have less time to work on it. I'll ping you when I think its fully ready for a review so as to reduce the amount of times you have to run a review on this PR. In the meantime I'll convert this PR to a draft since it's not ready to be merged while I continue to work on it.

@SaySayo SaySayo marked this pull request as draft November 25, 2021 09:45
@mnxn
Copy link
Collaborator

mnxn commented Nov 25, 2021

Sounds good. Thanks.

@tmattio
Copy link
Collaborator

tmattio commented Dec 7, 2021

@mnxn We're currently reviewing the PR with @SaySayo and are not sure how to address your comment about the unrecognized fields.

You previously mentioned:

Overuse of variable.other.declaration.dune. I only used this scope name when something is being declared. In this example, I would only expect public_name and name to have the variable.other.declaration.dune highlighting.

And advised that some fields should not be highlighted.

In your last comment, though, you're mentioning that

I tested this syntax with some example dune files from the dune repo and there are still many unrecognized fields:

IIUC, these were previously highlighted, but @SaySayo removed it after your comment. What would you recommend we do? Should we create a new scope for these? Do you have any guidelines you're following to decide what is a variable.other.declaration.dune and what is not?

Personally, I think that's fine if all the fields are highlighted, but we'll follow your recommendation here.

@mnxn
Copy link
Collaborator

mnxn commented Dec 7, 2021

Sorry, I will try to use more specific language.

From now on I will refer to field names and field values. In the snippet (a b), a is the field name and b is the field value.

What I previously mentioned was that only the field values for public_name and name should use variable.other.declaration.dune. What I forgot to say back that then is that field values for the plurals, public_names and names, should also be variable.other.declaration.dune.

So only field values for public_name, public_names, name, and names should use variable.other.declaration.dune.

My most recent screenshots were mostly to point out the missing field name highlighting. We should aim to highlight all valid field names in the appropriate contexts.

I'll go over the specific changes in those screenshots I would expect. This time I will use the built-in Dark+ theme.

  1. 1
    i. names should be highlighted with keyword.language.dune
    ii. foo should be highlighted with variable.other.declaration.dune
    iii. libraries should be highlighted with keyword.language.dune

  2. 2
    i. gh637 should be highlighted with variable.other.declaration.dune
    ii. package should be highlighted with keyword.language.dune
    iii. libraries should be highlighted with keyword.language.dune
    iv. deps should be highlighted with keyword.language.dune

  3. 3
    i. language should be highlighted with keyword.language.dune
    ii. names should be highlighted with keyword.language.dune

  4. 4
    i. with-stdout-to should be highlighted with entity.name.function.action.dune
    ii. run should be highlighted with entity.name.function.action.dune

  5. 5
    i. backend should be highlighted with keyword.language.dune
    ii. executable should be highlighted with keyword.language.dune
    iii. flags should be highlighted with keyword.language.dune

@SaySayo
Copy link
Contributor Author

SaySayo commented Dec 8, 2021

Hello @mnxn I updated the dune syntax to address all the things you mentioned. Works well locally. Please review when you can and let me know if there's any required changes. Thank you!

@tmattio
Copy link
Collaborator

tmattio commented Dec 8, 2021

@mnxn Thanks a lot for the very detailed and comprehensive answer, it's very helpful 🙂

@SaySayo I'd like to test the PR with some more dune files to see if we can spot other issues before asking @mnxn to review again if that's ok with you. I'll ping here if everything looks good after testing.

@SaySayo
Copy link
Contributor Author

SaySayo commented Dec 8, 2021

Yes that's fine @tmattio. Thank you for your time!

@SaySayo SaySayo closed this Jan 12, 2022
@SaySayo SaySayo deleted the sayo_branch branch January 12, 2022 13:05
@SaySayo SaySayo restored the sayo_branch branch January 15, 2022 17:47
@SaySayo SaySayo reopened this Jan 15, 2022
@SaySayo SaySayo marked this pull request as ready for review January 19, 2022 21:50
@tmattio
Copy link
Collaborator

tmattio commented Jan 26, 2022

@mnxn I completed an initial review of the PR and I believe it is ready for you to review as well.

I noticed some issues that should be addressed:

  • We are forgetting to include #general in some places, which breaks the syntax highlighting for comments in some stanzas, among other things
  • the env stanza fields are not highlighted
  • include_subdirs values are not highlighted
  • The variable highlighting is too general, for instance, the extension .exe is highlighted in %{exe:my_test_program.exe}.

However, fixing these shouldn't require massive changes, so it's not conflicting with additional reviews.

Copy link
Collaborator

@mnxn mnxn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay in review.

This looks great! It's a huge improvement over the current syntax. Thank you for all your hard work!

Before merging, the .DS_Store file needs to be removed and the branch needs to be rebased to fix the CHANGES.md conflict.

@mnxn
Copy link
Collaborator

mnxn commented Feb 1, 2022

The variable highlighting is too general

@tmattio:
The variable highlighting is actually the same across syntaxes for dune, dune-project, and dune-workspace. I think it should be fixed in another PR so this PR stays isolated.

@SaySayo SaySayo force-pushed the sayo_branch branch 2 times, most recently from 930a815 to ca44d22 Compare February 1, 2022 20:24
@tmattio tmattio merged commit 042ed95 into ocamllabs:master Feb 1, 2022
@tmattio
Copy link
Collaborator

tmattio commented Feb 1, 2022

This is a huge undertaking, thank you so much for all your work on this @SaySayo. Congratulations on getting the PR merged 🎉

Thanks a lot for all your time, patience, and support to get this ready to merge @mnxn. Truly appreciate it ❤️

@SaySayo
Copy link
Contributor Author

SaySayo commented Feb 1, 2022

I'm so excited to see the changes finally merged! Glad I could make a difference. Thank you so much for your extremely patient reviews and solving through all the blockers with me @tmattio @mnxn @gs0510. I really appreciate it 🙂🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants