[clang-tools-extra] [clangd] Improve Markup Rendering (PR #140498)
via cfe-commits
cfe-commits at lists.llvm.org
Fri May 30 11:15:08 PDT 2025
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 HEAD~1 HEAD --extensions h,cpp -- clang-tools-extra/clangd/Hover.cpp clang-tools-extra/clangd/support/Markup.cpp clang-tools-extra/clangd/support/Markup.h clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp clang-tools-extra/clangd/unittests/HoverTests.cpp clang-tools-extra/clangd/unittests/support/MarkupTests.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang-tools-extra/clangd/support/Markup.cpp b/clang-tools-extra/clangd/support/Markup.cpp
index b1e6252e4..585389176 100644
--- a/clang-tools-extra/clangd/support/Markup.cpp
+++ b/clang-tools-extra/clangd/support/Markup.cpp
@@ -66,11 +66,13 @@ bool looksLikeTag(llvm::StringRef Contents) {
///
/// **FIXME:** handle the case when the client does support HTML rendering in
/// markdown. For this, the LSP server needs to check the
-/// [supportsHtml capability](https://github.com/microsoft/language-server-protocol/issues/1344)
+/// [supportsHtml
+/// capability](https://github.com/microsoft/language-server-protocol/issues/1344)
/// of the client.
///
/// \param C The character to check.
-/// \param After The string that follows \p C . This is used to determine if \p C is
+/// \param After The string that follows \p C . This is used to determine if \p
+/// C is
/// part of a tag or an entity reference.
/// \returns true if \p C should be escaped, false otherwise.
bool needsLeadingEscape(char C, llvm::StringRef After) {
@@ -245,7 +247,8 @@ private:
std::string indentLines(llvm::StringRef Input) {
assert(!Input.ends_with("\n") && "Input should've been trimmed.");
std::string IndentedR;
- // We'll add 2 spaces after each new line which is not followed by another new line.
+ // We'll add 2 spaces after each new line which is not followed by another new
+ // line.
IndentedR.reserve(Input.size() + Input.count('\n') * 2);
for (size_t I = 0; I < Input.size(); ++I) {
char C = Input[I];
@@ -326,7 +329,7 @@ llvm::StringRef Paragraph::chooseMarker(llvm::ArrayRef<llvm::StringRef> Options,
return Options.front();
}
-bool Paragraph::punctuationIndicatesLineBreak(llvm::StringRef Line) const{
+bool Paragraph::punctuationIndicatesLineBreak(llvm::StringRef Line) const {
constexpr llvm::StringLiteral Punctuation = R"txt(.:,;!?)txt";
Line = Line.rtrim();
@@ -515,9 +518,7 @@ Paragraph &Document::addParagraph() {
return *static_cast<Paragraph *>(Children.back().get());
}
-void Document::addRuler() {
- Children.push_back(std::make_unique<Ruler>());
-}
+void Document::addRuler() { Children.push_back(std::make_unique<Ruler>()); }
void Document::addCodeBlock(std::string Code, std::string Language) {
Children.emplace_back(
diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 6df9efe16..8fef5ecc7 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -1095,10 +1095,11 @@ TEST(CompletionTest, Documentation) {
int x = ^
)cpp");
- EXPECT_THAT(Results.Completions,
- Contains(AllOf(
- named("foo"),
- doc("Annotation: custom_annotation\n\nNon-doxygen comment."))));
+ EXPECT_THAT(
+ Results.Completions,
+ Contains(
+ AllOf(named("foo"),
+ doc("Annotation: custom_annotation\n\nNon-doxygen comment."))));
EXPECT_THAT(
Results.Completions,
Contains(AllOf(named("bar"), doc("Doxygen comment.\n\\param int a"))));
diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 0047eed03..ad4574f8a 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3847,7 +3847,7 @@ TEST(Hover, ParseDocumentation) {
"`not parsed`",
}};
- //Case C = Cases[2];
+ // Case C = Cases[2];
for (const auto &C : Cases) {
markup::Document Output;
parseDocumentation(C.Documentation, Output);
diff --git a/clang-tools-extra/clangd/unittests/support/MarkupTests.cpp b/clang-tools-extra/clangd/unittests/support/MarkupTests.cpp
index f1a421199..cef8944e8 100644
--- a/clang-tools-extra/clangd/unittests/support/MarkupTests.cpp
+++ b/clang-tools-extra/clangd/unittests/support/MarkupTests.cpp
@@ -187,7 +187,8 @@ TEST(Paragraph, SeparationOfChunks) {
EXPECT_EQ(P.asPlainText(), "after foobar batno space text");
P.appendSpace().appendCode("code").appendText(".\n newline");
- EXPECT_EQ(P.asMarkdown(), "after `foobar` bat`no` `space` text `code`.\n newline");
+ EXPECT_EQ(P.asMarkdown(),
+ "after `foobar` bat`no` `space` text `code`.\n newline");
EXPECT_EQ(P.asPlainText(), "after foobar batno space text code.\nnewline");
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/140498
More information about the cfe-commits
mailing list