[clang] [llvm] [clang][Diagnostics] Add CLANG_HIGHLIGHT_COLORS= to configure syntax highlighting in diagnostics (#82945) (PR #83060)

via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 26 13:28:26 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 83feb846482f0100cb29d460d3d8de2690fc32ad 81b1327c3b5104b0c053fd1ee8e8773925efb8dd -- clang/lib/Frontend/TextDiagnostic.cpp llvm/include/llvm/Support/raw_ostream.h llvm/lib/Support/raw_ostream.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/Frontend/TextDiagnostic.cpp b/clang/lib/Frontend/TextDiagnostic.cpp
index 3fc528c39c..0da6fbca27 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -1187,7 +1187,7 @@ highlightLines(StringRef FileData, unsigned StartLineNumber,
   auto appendStyle =
       [PP, &LangOpts](SmallVector<TextDiagnostic::StyleRange> &Vec,
                       const Token &T, unsigned Start, unsigned Length) -> void {
-    auto setColor = [&](auto && color) {
+    auto setColor = [&](auto &&color) {
       if (color)
         Vec.emplace_back(Start, Start + Length, *color);
     };
diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
index 61cb6d09ab..c46a00e930 100644
--- a/llvm/include/llvm/Support/raw_ostream.h
+++ b/llvm/include/llvm/Support/raw_ostream.h
@@ -133,7 +133,8 @@ public:
   static constexpr Colors SAVEDCOLOR = Colors::SAVEDCOLOR;
   static constexpr Colors RESET = Colors::RESET;
 
-  static std::optional<Colors> parse_color(const std::string_view &name) noexcept;
+  static std::optional<Colors>
+  parse_color(const std::string_view &name) noexcept;
 
   explicit raw_ostream(bool unbuffered = false,
                        OStreamKind K = OStreamKind::OK_OStream)
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index 27031c962f..db57500255 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -24,10 +24,10 @@
 #include "llvm/Support/NativeFormatting.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
-#include <string_view>
 #include <algorithm>
 #include <cerrno>
 #include <cstdio>
+#include <string_view>
 #include <sys/stat.h>
 
 // <fcntl.h> may provide O_BINARY.
@@ -76,38 +76,39 @@ constexpr raw_ostream::Colors raw_ostream::WHITE;
 constexpr raw_ostream::Colors raw_ostream::SAVEDCOLOR;
 constexpr raw_ostream::Colors raw_ostream::RESET;
 
-std::optional<raw_ostream::Colors> raw_ostream::parse_color(const std::string_view &name) noexcept {
-  if(name == "black"sv)
+std::optional<raw_ostream::Colors>
+raw_ostream::parse_color(const std::string_view &name) noexcept {
+  if (name == "black"sv)
     return Colors::BLACK;
-  else if(name == "red"sv)
+  else if (name == "red"sv)
     return Colors::RED;
-  else if(name == "green"sv)
+  else if (name == "green"sv)
     return Colors::GREEN;
-  else if(name == "yellow"sv)
+  else if (name == "yellow"sv)
     return Colors::YELLOW;
-  else if(name == "blue"sv)
+  else if (name == "blue"sv)
     return Colors::BLUE;
-  else if(name == "magenta"sv)
+  else if (name == "magenta"sv)
     return Colors::MAGENTA;
-  else if(name == "cyan"sv)
+  else if (name == "cyan"sv)
     return Colors::CYAN;
-  else if(name == "white"sv)
+  else if (name == "white"sv)
     return Colors::WHITE;
-  else if(name == "bright-black"sv)
+  else if (name == "bright-black"sv)
     return Colors::BRIGHT_BLACK;
-  else if(name == "bright-red"sv)
+  else if (name == "bright-red"sv)
     return Colors::BRIGHT_RED;
-  else if(name == "bright-green"sv)
+  else if (name == "bright-green"sv)
     return Colors::BRIGHT_GREEN;
-  else if(name == "bright-yellow"sv)
+  else if (name == "bright-yellow"sv)
     return Colors::BRIGHT_YELLOW;
-  else if(name == "bright-blue"sv)
+  else if (name == "bright-blue"sv)
     return Colors::BRIGHT_BLUE;
-  else if(name == "bright-magenta"sv)
+  else if (name == "bright-magenta"sv)
     return Colors::BRIGHT_MAGENTA;
-  else if(name == "bright-cyan"sv)
+  else if (name == "bright-cyan"sv)
     return Colors::BRIGHT_CYAN;
-  else if(name == "bright-white"sv)
+  else if (name == "bright-white"sv)
     return Colors::BRIGHT_WHITE;
   else
     return std::nullopt;

``````````

</details>


https://github.com/llvm/llvm-project/pull/83060


More information about the cfe-commits mailing list