Repository navigation
ast --flatten leaves out the braces, => and , of a match block #19086
Description
Bug report form
- I have done a basic search of the issue tracker to find any existing issues that are similar.
- I have checked that my version is at least the latest stable release available via my installation method.
Describe the bug
ast --flatten emits no tokens for the {, }, =>, and , of a match block.
Lists, records, and tables emit a token of their own shape for each gap between their items.
Blocks and closures do the same for the gaps before and after their contents.
Expr::MatchBlock only flattens each pattern and expression:
nushell/crates/nu-parser/src/flatten.rs
Lines 404 to 409 in ac000bb
| Expr::MatchBlock(matches) => { | |
| for (pattern, expr) in matches { | |
| flatten_pattern_into(pattern, output); | |
| flatten_expression_into(working_set, expr, output); | |
| } | |
| } |
When the match block sits inside a closure, its closing } ends up in the closure's gap token instead, while its opening { appears in no token at all.
The REPL highlighter colors text by these tokens and leaves the rest unstyled, so in def f [] { match 1 { _ => 2 } } the match block's { stays plain while its } takes the shape_closure color.
How to reproduce
ast --flatten 'match 1 { 1 => { "a" }, _ => "b" }' | select content shape| content | shape |
|---|---|
| match | shape_internalcall |
| 1 | shape_int |
| 1 | shape_match_pattern |
| { | shape_block |
| "a" | shape_string |
| } | shape_block |
| _ | shape_nothing |
| "b" | shape_string |
ast --flatten 'def f [] { match 1 { _ => 2 } }' | select content shape| content | shape |
|---|---|
| def | shape_internalcall |
| f | shape_string |
| [] | shape_signature |
| { | shape_closure |
| match | shape_internalcall |
| 1 | shape_int |
| _ | shape_nothing |
| 2 | shape_int |
| } } | shape_closure |
For comparison, a list keeps its delimiters:
ast --flatten '[1, 2]' | select content shape| content | shape |
|---|---|
| [ | shape_list |
| 1 | shape_int |
| , | shape_list |
| 2 | shape_int |
| ] | shape_list |
Expected behavior
The {, }, =>, and , of a match block appear as tokens, as the delimiters of a list or a record do.
Configuration
| key | value |
|---|---|
| version | 0.115.1 |
| major | 0 |
| minor | 115 |
| patch | 1 |
| branch | |
| commit_hash | |
| build_os | linux-x86_64 |
| build_target | x86_64-unknown-linux-gnu |
| rust_version | rustc 1.97.1 (8bab26f4f 2026-07-14) (built from a source tarball) |
| cargo_version | cargo 1.97.0 (c980f4866 2026-06-30) |
| build_time | 1980-01-01 00:00:00 +00:00 |
| build_rust_channel | release |
| allocator | standard |
| features | default, helix, lsp, mcp, network, plugin, rustls-tls, sqlite, trash-support |
| installed_plugins | gstat 0.115.1, query 0.115.1 |
| experimental_options | example=false, dc-glob=false, reorder-cell-paths=true, pipefail=true, enforce-runtime-annotations=true, native-clip=false, cell-path-types=false, background-completions=true |
Activity
[-]ast --flatten leaves out the braces, => and , of a match block[/-][+]ast --flatten leaves out the delimiters and guards of a match block[/+][-]ast --flatten leaves out the delimiters and guards of a match block[/-][+]ast --flatten leaves out the braces, => and , of a match block[/+]mst-mkt commentedon Sep 25, 2026
I missed #12923 when searching, and this may be a duplicate of it.
It was closed as not planned, but it didn't mention that this also affects the REPL highlighting.
The match block's
{is left unstyled, while its}takes the closure's color:Closing #12923 was a deliberate decision, so I'll leave it to you whether this is enough to revisit that decision or whether this should be closed the same way.
Sorry for the noise.
fdncred commentedon Sep 26, 2026
I'd accept a PR if it wasn't too intrusive.