On Sat, 2020-11-14 at 14:43 -0500, David Malcolm wrote:
> GCC has had the ability to emit fix-it hints in machine-readable form
> since GCC 7 via -fdiagnostics-parseable-fixits and
> -fdiagnostics-generate-patch.
> 
> The former emits additional specially-formatted lines to stderr; the
> option and its format were directly taken from a pre-existing option
> in clang.
> 
> Ideally this could be used by IDEs so that the user can select
> specific
> fix-it hints and have the IDE apply them to the user's source code
> (perhaps turning them into clickable elements, perhaps with an
> "Apply All" option, etc).  Eclipse CDT has supported this option in
> this way for a few years:
>   https://bugs.eclipse.org/bugs/show_bug.cgi?id=497670
> 
> As a user of Emacs I would like Emacs to support such a feature.
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25987 tracks supporting
> GCC fix-it output in Emacs.  The discussion there identifies some
> issues with the existing option:
> 
> (a) columns in the output are specified as byte-offsets within the
> line (for exact compatibility with the option in clang), whereas
> emacs
> would prefer to consume them as what GCC 11 calls "display columns".
> https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Message-Formatting-Options.html#index-fdiagnostics-column-unit
> 
> (b) injecting a command-line option into the build is a fiddly manual
> step, varying between build systems.  It's far easier for the
> user if Emacs simply sets an environment variable when compiling,
> GCC uses this to enable the option if it recognizes the value, and
> the emacs compilation buffer decodes the additional lines of output
> and adds appropriate widgets.  In some ways it is a workaround for
> not having a language server.  Doing it this way means that for the
> various combinations of older and newer GCC and older and newer Emacs
> that a sufficiently modern combination of both can automatically
> support the rich fix-it UI, whereas other combinations will either
> not provide the envvar, or silently ignore it, gracefully doing
> nothing extra.
> 
> Hence this patch adds a new GCC_EXTRA_DIAGNOSTIC_OUTPUT environment
> variable to GCC which enables output of machine-parseable fix-it
> hints.
> 
> GCC_EXTRA_DIAGNOSTIC_OUTPUT=fixits-v1 is equivalent to the existing
> -fdiagnostics-parseable-fixits option.
> 
> GCC_EXTRA_DIAGNOSTIC_OUTPUT=fixits-v2 is the same, but changes the
> column output mode to "display columns" rather than bytes, as
> required by Emacs.
> 
> One remaining issue raised in that Emacs bug is the encoding of these
> lines, and, indeed, the encoding of GCC's stderr in general:
> currently we emit a mixture of bytes and UTF-8; I believe we emit
> filenames as bytes, diagnostic messages as UTF-8, and quote source
> code
> in the original encoding (PR other/93067 covers converting it to UTF-
> 8 on
> output).  Currently this patch prints octal-escaped bytes for bytes
> within filenames and replacement text that aren't printable (which
> is what -fdiagnostics-parseable-fixits also does).  Doing so at least
> allows the common case of ASCII-encoded sources and filenames to
> work,
> whilst allowing for future formats that address the encoding issues.
> 
> Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
> 
> Thoughts?
> Dave

In the absence of feedback, I've rebased the patch, retested it as
above, and pushed it to master
(as f10960558540636800cf5d3d6355969621fbc17e)

Dave

Reply via email to