Skip to content

feat: style the braces of ${VAR} as part of the env var - #1036

Open
WynandVStaden wants to merge 1 commit into
HalFrgrd:masterfrom
WynandVStaden:feat/env-var-braces
Open

WynandVStaden wants to merge 1 commit into
HalFrgrd:masterfrom
WynandVStaden:feat/env-var-braces

Conversation

@WynandVStaden

Copy link
Copy Markdown
Contributor

Follow-up to #1030, as asked in #1030 (comment) by @MartenBE (issue #1029): colour the ${ and } of ${VAR} as part of the variable.

Change

  • Parser (DParser): when ${ is followed by a plain variable name and then directly by }, the ${ and } tokens are marked is_env_var too, the same way the $ of $VAR already is.
  • Styling (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.
Input ${ and }
${HOME}, "${USER}" env-var colour
${UNRECOGNISED} unrecognised env-var colour
${ARR[0]}, ${HOME:-/tmp}, ${#PATH} rainbow bracket colour, as before

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 in token_to_style only affects these two tokens. The highlight of a matching pair under the cursor still comes first.

Tests

  • test_param_expansion_name_is_env_var now checks which delimiters are marked.
  • test_brace_delimited_env_var_styling checks the colour of the delimiters for a recognised and an unrecognised variable.
  • New test_brace_delimiters_around_more_than_a_name_stay_brackets for ${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 on master)
  • cargo fmt --all -- --check: clean
  • cargo clippy --workspace --all-features -- -D warnings: clean

Not 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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant