Repository navigation
feat: style the braces of ${VAR} as part of the env var - #1036
Open
WynandVStaden wants to merge 1 commit into
Open
WynandVStaden wants to merge 1 commit into
WynandVStaden wants to merge 1 commit into
Conversation
Follow-up to HalFrgrd#1030. When ${ and } hold a variable name and nothing else they are part of the variable, like the $ of $VAR, so they now take the env-var colour (or the unrecognised colour) instead of the rainbow bracket colour. The braces of forms like ${ARR[0]} and ${VAR:-default} enclose more than the name and stay bracket-coloured.
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.
Follow-up to #1030, as asked in #1030 (comment) by @MartenBE (issue #1029): colour the
${and}of${VAR}as part of the variable.Change
DParser): when${is followed by a plain variable name and then directly by}, the${and}tokens are markedis_env_vartoo, the same way the$of$VARalready is.token_to_style): the env-var colour is now checked before the rainbow bracket colour, so those two tokens take the colour of the variable. They follow the name: recognised or unrecognised.${and}${HOME},"${USER}"${UNRECOGNISED}${ARR[0]},${HOME:-/tmp},${#PATH}In the last row the braces enclose more than the name, so I left them as delimiters. No other delimiter carries
is_env_var, so the reordering intoken_to_styleonly affects these two tokens. The highlight of a matching pair under the cursor still comes first.Tests
test_param_expansion_name_is_env_varnow checks which delimiters are marked.test_brace_delimited_env_var_stylingchecks the colour of the delimiters for a recognised and an unrecognised variable.test_brace_delimiters_around_more_than_a_name_stay_bracketsfor${HOME:-/tmp}.The first two fail with the new parser lines disabled.
Run on Ubuntu 24.04, rustc 1.99.0:
cargo test --lib: 885 passed, 0 failed, 1 ignored (884 onmaster)cargo fmt --all -- --check: cleancargo clippy --workspace --all-features -- -D warnings: cleanNot done: the Docker integration tests, and I did not look at the colours in a terminal; the styling is covered by the unit tests only.
This is a choice about looks, so if you prefer the braces to stay rainbow-coloured, feel free to close it.