Highlight redirection target as valid if it contains a to-be-defined variable

If a variable is undefined, but it looks like it will be defined by the
current command line, assume the user knows what they are doing.
This should cover most real-world occurrences.

Closes #6654
This commit is contained in:
Johannes Altmanninger
2021-02-01 07:08:05 +01:00
parent e16a1d7065
commit fffcdf8792
3 changed files with 82 additions and 0 deletions

View File

@@ -5085,6 +5085,43 @@ static void test_highlighting() {
{L"param2", highlight_role_t::param},
});
highlight_tests.push_back({
{L"for", highlight_role_t::keyword},
{L"x", highlight_role_t::param},
{L"in", highlight_role_t::keyword},
{L"set-by-for-1", highlight_role_t::param},
{L"set-by-for-2", highlight_role_t::param},
{L";", highlight_role_t::statement_terminator},
{L"echo", highlight_role_t::command},
{L">", highlight_role_t::redirection},
{L"$x", highlight_role_t::redirection},
{L";", highlight_role_t::statement_terminator},
{L"end", highlight_role_t::keyword},
});
highlight_tests.push_back({
{L"set", highlight_role_t::command},
{L"x", highlight_role_t::param},
{L"set-by-set", highlight_role_t::param},
{L";", highlight_role_t::statement_terminator},
{L"echo", highlight_role_t::command},
{L">", highlight_role_t::redirection},
{L"$x", highlight_role_t::redirection},
{L"2>", highlight_role_t::redirection},
{L"$totally_not_x", highlight_role_t::error},
{L"<", highlight_role_t::redirection},
{L"$x_but_its_an_impostor", highlight_role_t::error},
});
highlight_tests.push_back({
{L"x", highlight_role_t::param, ns},
{L"=", highlight_role_t::operat, ns},
{L"set-by-variable-override", highlight_role_t::param, ns},
{L"echo", highlight_role_t::command},
{L">", highlight_role_t::redirection},
{L"$x", highlight_role_t::redirection},
});
highlight_tests.push_back({
{L"end", highlight_role_t::error},
{L";", highlight_role_t::statement_terminator},