diff --git a/src/fixits.c b/src/fixits.c index 5ffd7935..3a8bf481 100644 --- a/src/fixits.c +++ b/src/fixits.c @@ -69,8 +69,8 @@ fixit_print (fixit const *f, FILE *out) { fprintf (out, "fix-it:%s:{%d:%d-%d:%d}:%s\n", quotearg_n_style (1, c_quoting_style, f->location.start.file), - f->location.start.line, f->location.start.column, - f->location.end.line, f->location.end.column, + f->location.start.line, f->location.start.byte, + f->location.end.line, f->location.end.byte, quotearg_n_style (2, c_quoting_style, f->fix)); } @@ -136,19 +136,29 @@ fixits_run (void) } putc (c, out); } + /* Look for the right offset. */ - while (offset < f->location.start.column) + bool need_eol = false; + while (offset < f->location.start.byte) { int c = getc (in); if (c == EOF) break; ++offset; - putc (c, out); + if (c == '\n') + /* The position we are asked for is beyond the actual + line: pad with spaces, and remember we need a \n. */ + need_eol = true; + putc (need_eol ? ' ' : c, out); } /* Paste the fix instead. */ fputs (f->fix, out); + /* Maybe install the eol afterwards. */ + if (need_eol) + putc ('\n', out); + /* Skip the bad input. */ while (line < f->location.end.line) { @@ -161,16 +171,17 @@ fixits_run (void) offset = 1; } } - while (offset < f->location.end.column) + while (offset < f->location.end.byte) { int c = getc (in); if (c == EOF) break; ++offset; } + /* If erasing the content of a full line, also remove the end-of-line. */ - if (f->fix[0] == 0 && f->location.start.column == 1) + if (f->fix[0] == 0 && f->location.start.byte == 1) { int c = getc (in); if (c == EOF) diff --git a/tests/input.at b/tests/input.at index 822521f5..883056a4 100644 --- a/tests/input.at +++ b/tests/input.at @@ -2509,8 +2509,8 @@ AT_DATA_GRAMMAR([[input.y]], %file-prefix = "bar" -%fixed-output_files -%fixed_output-files + %fixed-output_files + %fixed_output-files %fixed-output-files %name-prefix= "foo" %no-default_prec @@ -2538,13 +2538,13 @@ fix-it:"input.y":{13:1-13:15}:"%file-prefix" input.y:14.1-16.5: warning: duplicate directive: '%file-prefix\n =' [-Wother] input.y:13.1-20: previous declaration fix-it:"input.y":{14:1-16:6}:"" -input.y:17.1-19: warning: deprecated directive: '%fixed-output_files', use '%fixed-output-files' [-Wdeprecated] -fix-it:"input.y":{17:1-17:20}:"%fixed-output-files" -input.y:18.1-19: warning: duplicate directive: '%fixed_output-files' [-Wother] -input.y:17.1-19: previous declaration -fix-it:"input.y":{18:1-18:20}:"" +input.y:17.9-27: warning: deprecated directive: '%fixed-output_files', use '%fixed-output-files' [-Wdeprecated] +fix-it:"input.y":{17:2-17:21}:"%fixed-output-files" +input.y:18.9-27: warning: duplicate directive: '%fixed_output-files' [-Wother] +input.y:17.9-27: previous declaration +fix-it:"input.y":{18:9-18:28}:"" input.y:19.1-19: warning: duplicate directive: '%fixed-output-files' [-Wother] -input.y:17.1-19: previous declaration +input.y:17.9-27: previous declaration fix-it:"input.y":{19:1-19:20}:"" input.y:20.1-19: warning: deprecated directive: '%name-prefix= "foo"', use '%define api.prefix {foo}' [-Wdeprecated] fix-it:"input.y":{20:1-20:20}:"%define api.prefix {foo}" @@ -2604,7 +2604,8 @@ AT_CHECK([cat input.y], [], %define parse.error verbose %expect-rr 0 %file-prefix "foo" -%fixed-output-files + %fixed-output-files + @&t@ %define api.prefix {foo} %no-default-prec %no-default-prec