-
Notifications
You must be signed in to change notification settings - Fork 92
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
Rewrite Syntax for ST4 #130
Conversation
This commit completely rewrites LESS.sublime-syntax as extension of ST's default CSS.sublime-syntax using latest syntax engine features. 1. CSS.sublime-syntax is vendored for backward compatibility reasons for all ST builds not shipping sublimehq/Packages#3717 Note: Once a ST build with the PR merged is released, an appropriate release of this package should be added with vendored CSS removed, so it can benefit from future improvements of ST's CSS. 2. Default CSS syntax tests are vendored as syntax_test_css.less to verify all existing CSS expressions are still scoped correctly. Those invalid-syntax tests have been removed, which behave different caused by LESS. 3. Symbol Lists and Symbol Index is refactored to reflect syntax changes and apply some functionality from base CSS. 4. Folding rules for ST's syntax based folding are added 5. Syntax specific settings are added to adjust word separators so `-` is included into identifiers. Benchmark: - real world CSS file with 10.000 lines of code before: 478ms after: 30ms diff: -94% - syntax_test_less.less from previous revision before: 36ms after: 8ms diff: -78%
Alright, when we're going to ship, we can pre-fix tag stuff. |
How do you feel about mixins? This is one area where I find LESS annoying (as a language): any class can be used as a mixin by "calling it". So this is effectively no longer a selector, but a function call. |
I am aware of that, but found it of little value to give it a special scope. We'd need to extend the A mixin definition can also look very much like a normal class Without definitions not sure if mixin calls are worth the effort then. The primary use case would be to drive goto definition, symbol list, goto reference. I'd be otherwise fine to highlight them very much the same like selectors in a first step. The same is with mixins in values. For simplicity reasons I just scoped them |
That's is by definition impossible: any normal classes can be used as a mixin. It's only on the usage of that mixin that you can differentiate. And when a mixin is used it always has the
Without a definition you can't do "find usages", so in that sense it adds no value. Is it worth it to perhaps get a different color so you can find your mixins between all the properties and selectors? Well I guess the entire idea behind the syntax in the first place is that it looks the same. So scoping them the same is totally acceptable. For me personally at least :) |
Ok, I'm just trying really hard to find holes, that I come up with such niche things is a testament to the quality of your work here. One final thing before I call it a week (I'll have a deeper look at some later time): In this situation it can't figure out that I'm writing a property, so I don't get the right suggestions. If I add another blank line before the media query, or when I add the property value and a |
LESS-sublime/Syntaxes/LESS.sublime-syntax Lines 150 to 154 in 5dfee6c
Otherwise an incomplete selector is assumed. I'd need to look into whether and how it is possible to improve that edge case. |
Well color isn’t a valid element and a custom element needs two words and a dash IIRC, but even then to make something work you’d need to maintain a list… and we already agree that that’s not a good idea. Other than that, testing with some larger code sets and hunting for edge cases, I defer to you for the scope naming… and it looks really solid already. |
HTML also supports "foreign tags", which are any form of valid identifier. A good example are SVG tags. But anything else is fine, too. I guess CSS therefore should be able to highlight them as well. Thus the "custom element needs two words and a dash" rule is unfortunately not sufficient. I think catching valid CSS at-rules may be something which can easily be added to bailout from property values early, as known at-rules can't be variables and there are not too many. I aggree that this pseudo-class vs. property issue is very tricky, espececially if no hard coded lists of tokens are to be maintained. In general CSS's completions try hard to add the semicolon after Scope names are mainly just taken from core CSS. I am not too happy with all of them, but I hesitate to change them because it might break many legacy color schemes. I am looking into adding some more tests about it. |
Maintain compatibility with ST4107-4125. We could also use builtin regexp, but this would mean to adjust syntax tests depending on ST builds.
Support for mixins was added and property vs. selector detection slightly improved. Further improvements are probably possible, but that may take some time for investigation and may be done in a future PR as well. This PR als vendors ST4149's RegExp syntax to maintain compatibility with ST4107-4126 without adjusting syntax tests etc. I've got an st4149 branch as well which drops both CSS and RegExp. |
This commit fixes a wrong assumption of `;` denoting mixin definitions.
Exclude them from normal goto definition / goto reference functionality.
This commit... 1. introduces a `less-values` context to avoid messing with `less-group-body`. 2. Fixes detection of mixin calls of detached rulesets.
This commit ... 1. scopes mixin parameters of parametrized mixins `variable.parameter` 2. scopes parameter lists `meta.selector.parameters meta.group` 3. adjusts selector's symbol list definition This way scoping/highlighting is adjusted to how parameter/arguments lists of function definitions vs. function calls are scoped.
1. more specific selectors with regards to exclude `punctuation` 2. add mixins to reference index to enable Goto Reference feature 3. add parametrized mixin parameters to symbol index to enable Goto Definition feature
This commit uses same contexts for both property-level and value-level mixins.
Both property-level mixins and values are terminated by the same tokens. By also including comments, another edge case in detached rulesets is fixed where mixins were scoped `meta.selector.css` before.
Seems better placed next to less-expressions
Syntax after incomplete mixin brackets may break until end of document without a 2nd-level bailout.
Alright, looking good… let’s do it like this:
|
All prepared. Repo moved, you added as maintainer, tags added retarget PR filed. |
This PR completely rewrites LESS.sublime-syntax as extension of ST's default CSS.sublime-syntax using latest syntax engine features.
CSS.sublime-syntax is vendored for backward compatibility reasons for all ST builds not shipping [CSS] Make CSS a good base syntax for extensions sublimehq/Packages#3717
Default CSS syntax tests are vendored as syntax_test_css.less to verify all existing CSS expressions are still scoped correctly.
Only those invalid-syntax tests have been removed, which behave different caused by LESS.
Symbol Lists and Symbol Index is refactored to reflect syntax changes and apply some functionality from base CSS.
Folding rules for ST's syntax based folding are added
Syntax specific settings are added to adjust word separators so
-
is included into identifiers.Benchmark:
Requirements:
This PR is currently compatible with ST 4126+.
If it is intented to be released with ST4107 Regexp.sublime-syntax needs to be vendored, too.