Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Improve mixin scopes#82

Merged
winstliu merged 12 commits intoatom:masterfrom
dsifford:dsifford-function-params-fix
Oct 25, 2017
Merged

Improve mixin scopes#82
winstliu merged 12 commits intoatom:masterfrom
dsifford:dsifford-function-params-fix

Conversation

@dsifford
Copy link
Contributor

@dsifford dsifford commented Oct 4, 2017

Work In Progress

Description of the Change

See #81

Todo

  • add .bracket.round to the punctuation classes (punctuation.definition.parameters.end.bracket.round.less)
  • revert back to key-value from operator.assignment for colon separating parameter name and default value
  • fix missing .meta.mixin.less scopes in numeric default parameters.
  • lots and lots of tests

Resolves #81

@winstliu
Copy link
Contributor

winstliu commented Oct 4, 2017

FYI I will be gone starting tomorrow until the 16th. So please feel free to create PRs for the other issues you wanted to tackle and I will try to review them after I get back.

'patterns': [
{
'match': ':'
'name': 'punctuation.separator.key-value.less'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@50Wliu Should this be punctuation.separator.key-value.css? Or is it incorrectly set here: https://github.com/atom/language-less/pull/82/files#diff-14c55924b6cf1fe75bf40519b9cddaccR317?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be kept as .less.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I change the other occurrence then?

Copy link
Contributor

Choose a reason for hiding this comment

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

The other one can be kept as .css because that one is the same in CSS, whereas for this one there is no function equivalent in CSS.

It's a bit confusing and is pretty ad-hoc. Hopefully in the future the endings can be standardized.

@dsifford
Copy link
Contributor Author

dsifford commented Oct 5, 2017

@50Wliu Got all the current tests passing. I'll hold off on going any further for now until I can get confirmation from you that the structure looks acceptable.

Enjoy your vacation!

# http://lesscss.org/features/#mixin-guards-feature-guard-comparison-operators
'match': '\\btrue\\b'
'name': 'constant.language.boolean.less'

Copy link
Contributor

Choose a reason for hiding this comment

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

No blank newlines


'mixins':
'name': 'meta.mixin.less'
'begin': '(\\.[_a-zA-Z][a-zA-Z0-9_-]*)(?= *\\()'
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about giving the . its own punctuation scope? Also, please use \\s* instead of <space>* for extra clarity.

Copy link
Contributor Author

@dsifford dsifford Oct 16, 2017

Choose a reason for hiding this comment

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

Re: giving . it's own scope. Good idea. What would that be called?

Re: using \\s* vs *, I agree that's clearer, but the issue is that the space must be horizontal only. Is there a PCRE horizontal whitespace option? IIRC, I think that might be \\h?

Edit: Or is \\s only horizontal? Now I'm confusing myself. 🙈

Copy link
Contributor

Choose a reason for hiding this comment

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

You're correct that \\s includes vertical whitespace (like \n and \v), but in practice it doesn't really matter because matches are restricted to single lines only.

I would think that . should be scoped as punctuation.definition.mixin.less.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see.. Good to know.

Re: punctuation.definition.mixin.less -- Sounds good to me.

'beginCaptures':
'0':
'name': 'meta.definition.mixin.less entity.name.mixin.less'
'end': '(?<=\\})'
Copy link
Contributor

Choose a reason for hiding this comment

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

{ and } don't need to be escaped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch


'mixin_guards':
'name': 'meta.guard.less'
'begin': '(?:(when|and|when +not|and +not) *|(,) *)+(\\()'
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here: use \\s.

'name': 'punctuation.separator.list.comma.css'
'3':
'name': 'meta.brace.round.css'
'end': '(\\))'
Copy link
Contributor

Choose a reason for hiding this comment

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

The outside capture can be removed, since we're only using the 0th capture.

@winstliu
Copy link
Contributor

Can you please revert the spec structure to how it was originally?

@dsifford
Copy link
Contributor Author

@50Wliu Welcome back!

Thanks for looking this over. I'll address these issues soon.

Re: crappy looking tests -- that was just temporary until you had time to get your eyes on it because I was being lazy 😝. I'll definitely fix that!

@dsifford
Copy link
Contributor Author

@50Wliu Should be ready for review now. Let me know if I missed something.

expect(tokens[41]).toEqual value: '@', scopes: ['source.css.less', 'meta.mixin.less', 'meta.parameters.less', 'variable.parameter.less', 'punctuation.definition.variable.less']
expect(tokens[42]).toEqual value: 'c', scopes: ['source.css.less', 'meta.mixin.less', 'meta.parameters.less', 'variable.parameter.less']
expect(tokens[43]).toEqual value: ')', scopes: ['source.css.less', 'meta.mixin.less', 'meta.parameters.less', 'punctuation.definition.parameters.end.bracket.round.less']
expect(tokens[44].scopes).not.toContain 'meta.parameters.less'
Copy link
Contributor

Choose a reason for hiding this comment

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

Try to avoid the .not qualifier when writing language tests, because scopes can and do change often. Then if the new meta.parameters.less is added back this test will still pass. While more verbose, it's more useful to write out the exact scope list (i.e. just like tokens[43]).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. Fixed.

'match': '\\btrue\\b'
'name': 'constant.language.boolean.less'
'variables':
'match': '(@|\\-\\-)[\\w-]+(?=\\s*)'
Copy link
Contributor

Choose a reason for hiding this comment

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

This lookahead seems rather useless since it can potentially match nothing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Not sure what I was thinking there...

'name': 'variable.parameter.less'
'1':
'name': 'punctuation.definition.variable.less'
'end': '(,)(?=\\s*@)'
Copy link
Contributor

Choose a reason for hiding this comment

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

The , doesn't need to have capture parentheses around it because the rest of the match is a lookahead. You can safely target the 0th capture.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be good to go now.

@winstliu winstliu merged commit 2802ab2 into atom:master Oct 25, 2017
@winstliu
Copy link
Contributor

winstliu commented Oct 28, 2017

@dsifford Sorry to bother you again, but here's another regression I'm seeing:

.markdown-preview[data-use-github-style] {
  .markdown-body(); // comment this out to fix everything

  padding: 30px; // padding is property-value
  font-size: 16px; // entity.name.tag.custom
  color: #333; // support.type.property-name.media
  background-color: #fff; // entity.name.tag.custom
  overflow: scroll; // no scope

  a {
    color: #337ab7;
  }
}

@winstliu
Copy link
Contributor

winstliu commented Nov 1, 2017

Reverted for the time being.

@dsifford
Copy link
Contributor Author

dsifford commented Nov 1, 2017

Sorry... this got buried in my notifications. I'll try to look at this this weekend

@winstliu
Copy link
Contributor

winstliu commented Nov 1, 2017

Yeah no problem! I'm hoping that I'll have time to investigate as well.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request for contribution: Improve mixin parameter scopes

2 participants