tree-sitter / tree-sitter-rust

Rust grammar for tree-sitter
MIT License
350 stars 98 forks source link

Support new let-else blocks #160

Closed MultisampledNight closed 1 year ago

MultisampledNight commented 2 years ago

Rust 1.65 (currently in beta) will include let ... else statements. It'd be nice to have those highlighted in a way that does not cause ERRORs all over the place, but no need to haste, this is a pretty recent feature.

Example

let Some(doge) = meme.into_doge() else {
    return "oh no";
}

The highlighting of the code above broken, with `else` having no color and `return` neither.

Ideally else would be highlighted as a conditional and the normal expression highlighting just continue inside of the block then.

let_declaration [0, 0] - [0, 33]
  "let" [0, 0] - [0, 3]
  pattern: tuple_struct_pattern [0, 4] - [0, 14]
    type: identifier [0, 4] - [0, 8]
    "(" [0, 8] - [0, 9]
    identifier [0, 9] - [0, 13]
    ")" [0, 13] - [0, 14]
  "=" [0, 15] - [0, 16]
  value: call_expression [0, 17] - [0, 33]
    function: field_expression [0, 17] - [0, 31]
      value: identifier [0, 17] - [0, 21]
      "." [0, 21] - [0, 22]
      field: field_identifier [0, 22] - [0, 31]
    arguments: arguments [0, 31] - [0, 33]
      "(" [0, 31] - [0, 32]
      ")" [0, 32] - [0, 33]
  ";" [0, 33] - [0, 33]
ERROR [0, 34] - [1, 10]
  identifier [0, 34] - [0, 38]
  "{" [0, 39] - [0, 40]
  identifier [1, 4] - [1, 10]
expression_statement [1, 11] - [1, 19]
  string_literal [1, 11] - [1, 18]
    """ [1, 11] - [1, 12]
    """ [1, 17] - [1, 18]
  ";" [1, 18] - [1, 19]
ERROR [2, 0] - [2, 1]
  "}" [2, 0] - [2, 1]
MultisampledNight commented 1 year ago

For what it's worth, 1.65 is stable now, but even rustfmt struggles with it.

maxbrunsfeld commented 1 year ago

This is supported on master.