Skip to content

fix: highlighting a where command with invalid arguments can duplicate text - #16192

Merged
Bahex merged 4 commits into
nushell:mainfrom
Bahex:where-duplicate-text-fix
Jul 22, 2025
Merged

Bahex merged 4 commits into
nushell:mainfrom
Bahex:where-duplicate-text-fix

Conversation

@Bahex

@Bahex Bahex commented Jul 16, 2025 •

Copy link
Copy Markdown
Member

Description

Problem

Parsing a multi span value as RowCondition always produces a RowCondition
expression that covers all the spans.

Which is problematic inside OneOf and can produce multiple expressions with overlapping spans.
Which results in funky highlighting that duplicates text:
image

Solution

Short circuiting on RowCondition while parsing OneOf (OneOf expression that contains RowCondition will always be parsed as RowCondition), prevents that.

Only reason for including SyntaxShape::Closure in the signature (#15697) was for documentation purposes, making it clear help texts that a closure can be used as the argument.

As our current parser is shape directed, simplifying the command signature means simplifies the parsing, so using a RowCondition on its own, and instead making it always look like a union with closure(any) solves the issue without any changes in the parser.

Also, RowCondition always accepts closure values anyway, so its textual representation should indicate that without the need to wrap it in OneOf.

Tests + Formatting

+1 test to catch it if it ever reoccurs

Bahex added 2 commits July 17, 2025 00:15
Parsing a multi span value as RowCondition always produces a
RowCondition expression that covers all the spans. Which is problematic
inside OneOf and can produce multiple expressions with overlapping
spans.

Short circuiting on RowCondition while parsing OneOf prevents this.

Fixes nushell#16129
@github-actions github-actions Bot added the A:parser Issues related to parsing label Jul 16, 2025
@Bahex Bahex added A:syntax-highlighting Bugs or performance issues with the syntax highlighting logic notes:fixes Noted in "Bug fixes" section labels Jul 16, 2025
Comment thread crates/nu-parser/src/parser.rs Resolved
Bahex added 2 commits July 17, 2025 18:05
Only reason for including SyntaxShape::Closure in the signature was to
make it clear in help texts that closures can be used as the argument.

Simplifying the signature simplifies the parsing, so using a
RowCondition on its own and instead making it always look like a union
with `closure(any)` solves the issue without any changes in the parser.

Also, RowCondition will always accept closures anyway, so its textual
representation should always indicate that without the need for OneOf.
@github-actions github-actions Bot removed the A:parser Issues related to parsing label Jul 17, 2025
@Bahex
Bahex requested a review from sholderbach July 19, 2025 17:02
@Bahex
Bahex merged commit 51265b2 into nushell:main Jul 22, 2025
@github-actions github-actions Bot added this to the v0.106.0 milestone Jul 22, 2025
hardfau1t pushed a commit to hardfau1t/nushell that referenced this pull request Aug 25, 2025
…e text (nushell#16192)

- fixes nushell#16129

# Description

## Problem
Parsing a multi span value as RowCondition always produces a RowCondition
expression that covers all the spans.

Which is problematic inside OneOf and can produce multiple expressions with
overlapping spans.
Which results in funky highlighting that duplicates text.

## Solution
Only reason for including `SyntaxShape::Closure` in the signature (nushell#15697) was
for documentation purposes, making it clear in `help` texts that a closure can
be used as the argument.

As our current parser is shape directed, simplifying the command signature
means simplifies the parsing, so using a RowCondition on its own, and instead
making it always look like a union with `closure(any)` solves the issue without
any changes in the parser.

Also, RowCondition always accepts closure values anyway, so its textual
representation should indicate that without the need to wrap it in OneOf.

Co-authored-by: Bahex <[email protected]>
@Bahex
Bahex deleted the where-duplicate-text-fix branch March 22, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:syntax-highlighting Bugs or performance issues with the syntax highlighting logic notes:fixes Noted in "Bug fixes" section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicated text in the command line after where command

3 participants