Repository navigation
fix: Syntax highlighting broken for bare string values in records - #237
Merged
Merged
Conversation
fdncred
reviewed
Aug 8, 2026
Contributor
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
resolve #236
Summary
This PR fixes an issue where a bare (unquoted) string used as a record value was highlighted as a command name, causing every subsequent key to lose its key color.
The record key rules in
repository.braced-expressionnow open a region that covers the value, so the value is scanned as a value instead of falling through to thecommandrule.Background Information
matchrules covering onlykey:. The value fell through to{"include": "source.nushell"}and was picked up by thecommandrule, whose region ends at(?=\||\)|\}|;)|$— causing it to run all the way to the closing}and swallow the remaining keys asstring.bare.nushell.(?=[,}])|(?<=[^\s:])(?=\s). Since record entries can be separated by commas, spaces, or newlines, a whitespace boundary must also close the entry. The lookbehind keeps the entry open as long as only the colon has been seen, which allows a value to sit on the line after the colon.#record-valueis#valuewithout#control-keywordsand#operators. A record value is a value, not an expression: Nushell rejects{a: 1 + 2}and interprets{a: if}as the string"if".#rangesis kept for{a: 1..5}, and#spreadmust precede it; otherwise,{a: ...$b}would be split into..and.$b.:,,,|,;,(,),{,},", and', with$or#disallowed as the first character. The pattern also carries a negative lookahead for ISO datetimes, because without it the class would start at the same offset as#datetimeand win the tie, splitting2024-01-01T00:00:00Zinside blocks and closures.string.bare.nushell variable.other.nushellfor the same reason as Syntax highlighting broken for record keys containing brackets #231: a token whose standard type isOtherhas its brackets recognized by bracket pair colorization, which would otherwise show]in{ a]b: 1 }as unmatched.Verification
I compared the scope of every token before and after the change using
vscode-textmate, ignoring the newly addedmeta.record-entry.nushellancestor.example.nu: 22 lines are tokenized differently, all of which correspond to the reported defect.npm run test:grammarpasses without regenerating the snapshot.Known Issue
When a comment is placed between the key and a value on a subsequent line, the value is still highlighted as a command:
{ a: # note foo }The comment is consumed inside the entry, causing the lookbehind to see its last character and close the entry prematurely. Since
mainmis-scopes this case as well, this is not a regression.