[Lldb-commits] [lldb] [lldb] Add tree-sitter based Rust syntax highlighting (PR #181282)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue Feb 17 09:05:29 PST 2026


================
@@ -436,4 +442,124 @@ TEST_F(HighlighterTest, SwiftClosures) {
   EXPECT_EQ(" <k>let</k> closure = { (x: <k>Int</k>) in return x * 2 }",
             highlightSwift(" let closure = { (x: Int) in return x * 2 }", s));
 }
+
+static std::string
+highlightRust(llvm::StringRef code, HighlightStyle style,
+              std::optional<size_t> cursor = std::optional<size_t>()) {
+  HighlighterManager mgr;
+  const Highlighter &h =
+      mgr.getHighlighterFor(lldb::eLanguageTypeRust, "main.rs");
+  return h.Highlight(style, code, cursor);
+}
+
+TEST_F(HighlighterTest, RustComments) {
+  HighlightStyle s;
+  s.comment.Set("<cc>", "</cc>");
+
+  EXPECT_EQ(" <cc>// I'm feeling lucky today</cc>",
+            highlightRust(" // I'm feeling lucky today", s));
+  EXPECT_EQ(" <cc>/* This is a\nmultiline comment */</cc>",
+            highlightRust(" /* This is a\nmultiline comment */", s));
+  EXPECT_EQ(" <cc>/* nested /* comment */ works */</cc>",
+            highlightRust(" /* nested /* comment */ works */", s));
+  EXPECT_EQ(" <cc>/// Documentation comment</cc>",
+            highlightRust(" /// Documentation comment", s));
+  EXPECT_EQ(" <cc>//! Inner doc comment</cc>",
+            highlightRust(" //! Inner doc comment", s));
+}
----------------
JDevlieghere wrote:

That's a good summary!

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


More information about the lldb-commits mailing list