diagnostics: add minimum width to left margin for line numbers
commit31087b7e83082e90d339041fde117aa4964db9a1
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 15 Oct 2018 22:16:59 +0000 (15 22:16 +0000)
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 15 Oct 2018 22:16:59 +0000 (15 22:16 +0000)
tree6bbedd1880c0dd6587b4bacdf81e6dd027e1e194
parent5e64efad1fd49b11690f4a193f86550194d0bf6f
diagnostics: add minimum width to left margin for line numbers

This patch adds a minimum width to the left margin used for printing
line numbers.   I set the default to 6.  Hence rather than:

some-filename:9:1: some message
9 | some source text
  | ^~~~~~~~~~~~~~~~
some-filename:10:1: another message
10 | more source text
   | ^~~~~~~~~~~~~~~~

we now print:

some-filename:9:42: some message
    9 | some source text
      | ^~~~~~~~~~~~~~~~
some-filename:10:42: another message
   10 | more source text
      | ^~~~~~~~~~~~~~~~

This implicitly fixes issues with margins failing to line up due
to different lengths of the number when we haven't read the full
file yet and so don't know the highest possible line number, for
line numbers up to 99999.

Doing so adds some whitespace on the left-hand side, for non-huge
files, at least.  I believe that this makes it easier to see where each
diagnostic starts, by visually breaking things up at the leftmost
column; my hope is to make it easier for the eye to see the different
diagnostics as if they were different "paragraphs".

gcc/ChangeLog:
* common.opt (fdiagnostics-minimum-margin-width=): New option.
* diagnostic-show-locus.c (layout::layout): Apply the minimum
margin width.
(layout::start_annotation_line): Only print up to 3 of the
margin character, to avoid touching the left-hand side.
(selftest::test_diagnostic_show_locus_fixit_lines): Update for
minimum margin width, as set by test_diagnostic_context's ctor.
(selftest::test_fixit_insert_containing_newline): Likewise.
(selftest::test_fixit_insert_containing_newline_2): Likewise.
(selftest::test_line_numbers_multiline_range): Clear
dc.min_margin_width.
* diagnostic.c (diagnostic_initialize): Initialize
min_margin_width.
* diagnostic.h (struct diagnostic_context): Add field
"min_margin_width".
* doc/invoke.texi: Add -fdiagnostics-minimum-margin-width=.
* opts.c (common_handle_option): Handle
OPT_fdiagnostics_minimum_margin_width_.
* selftest-diagnostic.c
(selftest::test_diagnostic_context::test_diagnostic_context):
Initialize min_margin_width to 6.
* toplev.c (general_init): Initialize global_dc->min_margin_width.

gcc/testsuite/ChangeLog:
* gcc.dg/missing-header-fixit-3.c: Update expected indentation
to reflect minimum margin width.
* gcc.dg/missing-header-fixit-4.c: Likewise.
* gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c:
Likewise.
* gcc.dg/plugin/diagnostic-test-show-locus-color-line-numbers.c:
Likewise.
* gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers-2.c:
New test.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Add it.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@265178 138bc75d-0d04-0410-961f-82ee72b054a4
16 files changed:
gcc/ChangeLog
gcc/common.opt
gcc/diagnostic-show-locus.c
gcc/diagnostic.c
gcc/diagnostic.h
gcc/doc/invoke.texi
gcc/opts.c
gcc/selftest-diagnostic.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/missing-header-fixit-3.c
gcc/testsuite/gcc.dg/missing-header-fixit-4.c
gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers-2.c [copied from gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-color-line-numbers.c with 56% similarity]
gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c
gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-color-line-numbers.c
gcc/testsuite/gcc.dg/plugin/plugin.exp
gcc/toplev.c