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

Conversation

@caleb531
Copy link
Contributor

Requirements

  • Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
  • All new code requires tests to ensure against regressions

Description of the Change

This PR tokenizes single (paren-less) parameters for arrow functions. The first-mate source.js grammar already did this, while the current tree-sitter grammar does not. Consider the following screenshots:

Current tree-sitter grammar:
1-before

Tree-sitter grammar with this PR applied:
2-after

Current first-mate grammar:
3-firstmate

Alternate Designs

A different selector could be used or the precedence of the grammar rule could be adjusted, if need be. Although this seems to work without any repercussions.

Benefits

More consistent coloring for arrow function parameters, whether or not you use parens.

Possible Drawbacks

I suppose if the selector chosen tokenizes more than it should, but I tried to keep it simple enough that it shouldn't be a concern.

Applicable Issues

N/A

@rsese
Copy link

rsese commented Jul 16, 2019

Thanks again @caleb531, someone will take a look as soon as they can ✌️

@rsese rsese added the triaged label Jul 16, 2019
@rsese
Copy link

rsese commented Jul 18, 2019

Failure looks unrelated, we restarted it but same error.

@jasonrudolph
Copy link
Contributor

👋 Hi @caleb531: Thanks for this! 🙇 I tested this out locally, and I do see that this pull request causes the arrow function parameters to have a new scope, but I don't see any change to the syntax highlighting. It's possible that I'm doing something wrong, so I'll show you what I'm seeing, and you can let me know if I'm missing something. 😅

Note: All of the examples below are using Atom 1.42.0-nightly1 and the monokai syntax theme.

With Tree-Sitter parsers disabled

Screen Shot 2019-08-14 at 5 35 26 PM

With Tree-Sitter parsers enabled

Screen Shot 2019-08-14 at 5 36 46 PM

With Tree-Sitter parsers enabled using the changes from this pull request

Screen Shot 2019-08-14 at 5 36 16 PM


I see that the formal-parameter scope gets applied, but I'm not sure if syntax themes are using that scope or not. Instead of applying the formal-parameter scope, should we instead apply the same scopes used in the TextMate grammar (i.e., meta-method-call meta.arguments meta.function.arrow meta.parameters variable.parameter.function)?

@caleb531
Copy link
Contributor Author

@jasonrudolph Ha, that's because it turns out I have the following styles in my styles.less:

atom-text-editor:not([mini]) .syntax--source.syntax--js .syntax--formal-parameter.syntax--identifier {
   color: @orange;
}

My apologies about that. But I agree, variable.parameter.function would be the way to go (as this scope is already used in the Python tree-sitter grammar, and the color of those parameters is already orange for monokai, as it should be)

@jasonrudolph
Copy link
Contributor

But I agree, variable.parameter.function would be the way to go...

@caleb531: Cool. Wanna make that change?

@caleb531
Copy link
Contributor Author

caleb531 commented Aug 17, 2019

@jasonrudolph Just pushed the rebased changes! The scope is now variable.parameter.function.

@jasonrudolph jasonrudolph self-assigned this Aug 28, 2019
@jasonrudolph
Copy link
Contributor

Just pushed the rebased changes!

Thanks, @caleb531! 🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants