fish_indent: Correct certain comment indenting
Prior to this change, when emitting gap text (comments, newlines, etc), fish_indent would use the indentation of the text at the end of the gap. But this has the wrong result for this case: begin command # comment end as the comment would get the indent of the 'end'. Instead use the indent computed for the gap text itself. Addresses one case of #7252.
This commit is contained in:
parent
86b02278b6
commit
e2a26b2fdf
@ -470,12 +470,19 @@ struct pretty_printer_t {
|
||||
// Emit the gap text before a source range.
|
||||
void emit_gap_text_before(source_range_t r, gap_flags_t flags) {
|
||||
assert(r.start <= source.size() && "source out of bounds");
|
||||
uint32_t start = r.start;
|
||||
if (start < indents.size()) current_indent = indents.at(start);
|
||||
|
||||
// Find the gap text which ends at start.
|
||||
source_range_t range = gap_text_to(start);
|
||||
source_range_t range = gap_text_to(r.start);
|
||||
if (range.length > 0) {
|
||||
// Set the indent from the beginning of this gap text.
|
||||
// For example:
|
||||
// begin
|
||||
// cmd
|
||||
// # comment
|
||||
// end
|
||||
// Here the comment is the gap text before the end, but we want the indent from the
|
||||
// command.
|
||||
if (range.start < indents.size()) current_indent = indents.at(range.start);
|
||||
|
||||
// If this range contained an error, append the gap text without modification.
|
||||
// For example in: echo foo "
|
||||
// We don't want to mess with the quote.
|
||||
|
@ -226,6 +226,28 @@ echo < stdin >>appended yes 2>&1 no > stdout maybe 2>& 4 | cat 2>| cat
|
||||
' | $fish_indent
|
||||
#CHECK: echo <stdin >>appended yes 2>&1 no >stdout maybe 2>&4 | cat 2>| cat
|
||||
|
||||
|
||||
# issue 7252
|
||||
echo -n '
|
||||
begin
|
||||
# comment
|
||||
end
|
||||
' | $fish_indent
|
||||
#CHECK: begin
|
||||
#CHECK: {{ }}# comment
|
||||
#CHECK: end
|
||||
|
||||
echo -n '
|
||||
begin
|
||||
cmd
|
||||
# comment
|
||||
end
|
||||
' | $fish_indent
|
||||
#CHECK: begin
|
||||
#CHECK: {{ }}cmd
|
||||
#CHECK: {{ }}# comment
|
||||
#CHECK: end
|
||||
|
||||
echo -n '
|
||||
i\
|
||||
f true
|
||||
|
Loading…
x
Reference in New Issue
Block a user