mirror of
https://github.com/fish-shell/fish-shell
synced 2025-02-15 05:28:41 +00:00
Correct syntax highlighting for variables spanning multiple lines
A variable may be broken across multiple lines with a backslash, for example: > echo $FISH_\ VERSION Teach syntax highlighting about this line breaking. Fixes #8444
This commit is contained in:
parent
3773baf1f3
commit
a47f498516
2 changed files with 17 additions and 2 deletions
|
@ -5525,6 +5525,13 @@ static void test_highlighting() {
|
|||
{L"=", highlight_role_t::operat, ns},
|
||||
});
|
||||
|
||||
// Highlighting works across escaped line breaks (#8444).
|
||||
highlight_tests.push_back({
|
||||
{L"echo", highlight_role_t::command},
|
||||
{L"$FISH_\\\n", highlight_role_t::operat},
|
||||
{L"VERSION", highlight_role_t::operat, ns},
|
||||
});
|
||||
|
||||
auto &vars = parser_t::principal_parser().vars();
|
||||
// Verify variables and wildcards in commands using /bin/cat.
|
||||
vars.set(L"VARIABLE_IN_COMMAND", ENV_LOCAL, {L"a"});
|
||||
|
|
|
@ -489,8 +489,16 @@ static size_t color_variable(const wchar_t *in, size_t in_len,
|
|||
}
|
||||
|
||||
// Handle a sequence of variable characters.
|
||||
while (valid_var_name_char(in[idx])) {
|
||||
colors[idx++] = highlight_role_t::operat;
|
||||
// It may contain an escaped newline - see #8444.
|
||||
for (;;) {
|
||||
if (valid_var_name_char(in[idx])) {
|
||||
colors[idx++] = highlight_role_t::operat;
|
||||
} else if (in[idx] == L'\\' && in[idx + 1] == L'\n') {
|
||||
colors[idx++] = highlight_role_t::operat;
|
||||
colors[idx++] = highlight_role_t::operat;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle a slice, up to dollar_count of them. Note that we currently don't do any validation of
|
||||
|
|
Loading…
Add table
Reference in a new issue