mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-22 04:07:39 +08: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
@ -5525,6 +5525,13 @@ static void test_highlighting() {
|
|||||||
{L"=", highlight_role_t::operat, ns},
|
{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();
|
auto &vars = parser_t::principal_parser().vars();
|
||||||
// Verify variables and wildcards in commands using /bin/cat.
|
// Verify variables and wildcards in commands using /bin/cat.
|
||||||
vars.set(L"VARIABLE_IN_COMMAND", ENV_LOCAL, {L"a"});
|
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.
|
// Handle a sequence of variable characters.
|
||||||
while (valid_var_name_char(in[idx])) {
|
// It may contain an escaped newline - see #8444.
|
||||||
colors[idx++] = highlight_role_t::operat;
|
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
|
// Handle a slice, up to dollar_count of them. Note that we currently don't do any validation of
|
||||||
|
Loading…
x
Reference in New Issue
Block a user