Skip to content

Highlight all soft modifiers #168

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

Merged

Conversation

camilaagw
Copy link
Contributor

Screenshot 2020-12-10 at 18 29 21

@nicolasstucki nicolasstucki linked an issue Dec 10, 2020 that may be closed by this pull request
Copy link
Contributor

@MaximeKjaer MaximeKjaer left a comment

Choose a reason for hiding this comment

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

This looks good! The test cases are very extensive too, so this looks great to me. I only have a minor comment about one test case. If this turns out to be difficult to address, just let me know and we can merge without solving that particular point.

name: 'storage.modifier.other'
},
{
match: '(?<=^|\\s)\\b(transparent|opaque|infix|open|inline)\\b(?=[a-z\\s]*\\b(def|val|var|given|type|class|trait|object|enum)\\b)',
Copy link
Contributor

@MaximeKjaer MaximeKjaer Dec 10, 2020

Choose a reason for hiding this comment

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

Instead of allowing [a-z\\s]* between a soft keyword modifier and a keyword, I think we should aim to only highlight a chain of soft keywords followed by a keyword, something like ((transparent|opaque|infix|open|inline)\\b)+(?=\\b(def|val|var|given|type|class|trait|object|enum)) (might need some adjustment for allowing whitespace). With soft keywords, I think we should try to be as minimal as possible, only highlighting them as keywords if strictly necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that a soft modifier can be followed by a sequence of normal modifiers. [a-z\\s]* skips those modifiers to find the def|val|....

Copy link
Contributor

Choose a reason for hiding this comment

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

The alternative would be to list all modifiers separated by spaces instead of [a-z\\s]*

// ^^^^^^ storage.modifier.other

transparent badkeyword inline override def alternative
// ^^^^^^^^^^^ storage.modifier.other
Copy link
Contributor

Choose a reason for hiding this comment

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

Related to the previous comment: I don't think that we should have a test requiring that transparent is storage.modifier.other in this situation. The general rule of thumb that I've been applying is that when it's invalid Scala, it can be highlighted as anything; we shouldn't require specific highlightings for invalid Scala in our tests, because that could make future refactorings more difficult.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is just a consequence of the [a-z\\s]* above.

Copy link
Contributor

Choose a reason for hiding this comment

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

This might be practical if we have

transparent inilne def alternative

In this case transparent and def are highlighted but not inilne which makes it trivial to find the typo.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, that's actually a quite convincing argument for keeping [a-z\\s]*. In that case, we can merge the PR.

@MaximeKjaer MaximeKjaer merged commit c4c054f into scala:master Dec 11, 2020
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.

Highlight all soft modifiers
3 participants