-
Notifications
You must be signed in to change notification settings - Fork 352
Proper Lambda Support #358
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
Conversation
" Matches a single keyword argument with no parens | ||
syntax match jsArrowFuncArgs /\(\k\)\+\s\+\(=>\)\@=/ skipwhite contains=jsFuncArgs extend | ||
" Matches a series of arguments surrounded in parens | ||
syntax match jsArrowFuncArgs /(\(\k\|,\|\s\|\n\|\.\)*)\s\+\(=>\)\@=/ skipwhite contains=jsFuncArgs extend |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain these two patterns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used to match the arguments definition for an =>
function.
Currently for normal functions we actually highlight the parenthesis and actual arguments definitions, see this example:
My color theme makes them orange.
To match this for lambdas, it's a bit trickier. We have to use a lookahead to match against the =>
.
I separated it into 2 lines to make the overall regexes easier to understand.
Lambda functions can be both defined like this:
// The first of the syntax match lines matches this case
arg => obj.getter();
And like this:
// The second syntax match line matches for this
(arg) => obj.getter()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! What is \k
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\k
is for a keyword character, :help \\k
for more deets
LGTM |
Tacking this on since it relates to ES6 functions. The generator astericks were breaking the highlighting of function arguments. This should fix generators
This PR is a first pass at properly supporting ES6 lambdas. Currently we only support the
=>
(arrow) itself, and don't actually recognize the rest as a function declaration.This first pass should handle the majority of use cases, although there may be some scenarios I missed.
For reference, this is what syntax highlighting looked like prior to this PR:
And this is how it looks with this PR applied:
I also fixed a bug when defining a generator that would break
jsFuncArgs
highlighting