Skip to content
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

Add spread to syntax highlighting #174

Merged
merged 7 commits into from
Feb 21, 2024
Merged

Conversation

texastoland
Copy link
Contributor

@texastoland texastoland commented Feb 16, 2024

Fixes #173.

Generated tokens for:

def cmd [--flag (-f) ...rest] {
  [ ...$rest ]
  { ...$rest }
  all --flag -f ...$rest
}
cmd --flag -f ...$rest
^cmd --flag -f ...$rest
  • def cmd [
    • ...
      1. keyword.control.nushell
      2. meta.function.parameters.nushell
      3. source.nushell
    • rest
      1. variable.parameter.nushell
      2. meta.function.parameters.nushell
      3. source.nushell
  • ] {
    • [
      • ...
        1. keyword.control.nushell
        2. meta.table.nushell
        3. meta.function.body.nushell
        4. source.nushell
      • $rest
        1. variable.other.nushell
        2. meta.table.nushell
        3. meta.function.body.nushell
        4. source.nushell
    • ]
    • {
      • ...
        1. keyword.control.nushell
        2. meta.expression.braced.nushell
        3. meta.function.body.nushell
        4. source.nushell
      • $rest
        1. variable.other.nushell
        2. meta.expression.braced.nushell
        3. meta.function.body.nushell
        4. source.nushell
    • }
    • all - keyword.other.builtin.nushell
      • ...
        1. keyword.control.nushell
        2. meta.command.nushell
        3. meta.function.body.nushell
        4. source.nushell
      • $rest
        1. variable.other.nushell
        2. meta.command.nushell
        3. meta.function.body.nushell
        4. source.nushell
  • cmd - entity.name.type.external.nushell
    • ...
      1. keyword.control.nushell
      2. meta.command.nushell
      3. source.nushell
    • $rest
      1. variable.other.nushell
      2. meta.command.nushell
      3. source.nushell
  • ^ - keyword.operator.nushell
    • cmd ...$rest - same as above

@fdncred
Copy link
Collaborator

fdncred commented Feb 19, 2024

The only thing that I'm not quite sure about is having ...$rest as a custom command parameter instead of ...rest. They resolve to two different things.

...rest is all variable.parameter.nushell
where
...$rest is ... = keyword.control.nushell, $ = meta.function.parameter.nushell, and rest = variable.parameter.nushell

It may be ok like this, it just gives me pause.

Replaces `include` with a capture for the existing regex.
@texastoland
Copy link
Contributor Author

texastoland commented Feb 20, 2024

...rest is all variable.parameter.nushell

@fdncred Fixed. Copied from Discord whether to highlight flags too:

def cmd [ --flag ] {}
#         ^^ highlighted?
cmd --flag
#   ^^ here too

@fdncred
Copy link
Collaborator

fdncred commented Feb 20, 2024

My answer from Disord was I think yes to both since -- and flag mean something different than --flag. Thanks for working on this stuff.

Traps command flags and shortcuts bare string parsing.
Reuses an unused `parameters` expression. Fixes broken word boundary with whitespace lookbehind instead. Also fixes previous `(.+)` (code smell) matching the entire command.
@texastoland
Copy link
Contributor Author

texastoland commented Feb 21, 2024

Ready again. I wasn't happy with my first pass but I discovered an expression that wasn't working before and fixed it. I didn't update the scope list (above) with flag tokens but can if it helps review! LGTM :shipit:

@fdncred
Copy link
Collaborator

fdncred commented Feb 21, 2024

I think it looks good now. Thanks!

@fdncred fdncred merged commit 290cb50 into nushell:main Feb 21, 2024
1 check passed
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.

Spread not highlighted correctly
2 participants