[clang-tools-extra] [clangd] Implement simple folding for preprocessor branches (PR #140959)

via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 5 23:56:41 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 cpp,h -- clang-tools-extra/clangd/SemanticSelection.cpp clang-tools-extra/clangd/support/DirectiveTree.cpp clang-tools-extra/clangd/support/DirectiveTree.h clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
``````````

</details>

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

``````````diff
diff --git a/clang-tools-extra/clangd/SemanticSelection.cpp b/clang-tools-extra/clangd/SemanticSelection.cpp
index 33b829c77..199694c46 100644
--- a/clang-tools-extra/clangd/SemanticSelection.cpp
+++ b/clang-tools-extra/clangd/SemanticSelection.cpp
@@ -175,7 +175,7 @@ llvm::Expected<std::vector<FoldingRange>> getFoldingRanges(ParsedAST &AST) {
   return collectFoldingRanges(SyntaxTree, TM);
 }
 
-// FIXME( usaxena95): Collect includes and other code regions (e.g. 
+// FIXME( usaxena95): Collect includes and other code regions (e.g.
 // public/private/protected sections of classes, control flow statement bodies).
 // Related issue: https://github.com/clangd/clangd/issues/310
 llvm::Expected<std::vector<FoldingRange>>
diff --git a/clang-tools-extra/clangd/support/DirectiveTree.cpp b/clang-tools-extra/clangd/support/DirectiveTree.cpp
index 89cfa6a36..503a83272 100644
--- a/clang-tools-extra/clangd/support/DirectiveTree.cpp
+++ b/clang-tools-extra/clangd/support/DirectiveTree.cpp
@@ -387,8 +387,8 @@ public:
     }
 
     if (C.End.Kind != tok::pp_not_keyword) {
-        Range = {Last, C.End.Tokens.Begin};
-        Ranges.push_back(Range);
+      Range = {Last, C.End.Tokens.Begin};
+      Ranges.push_back(Range);
     }
 
     for (const auto &B : C.Branches)

``````````

</details>


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


More information about the cfe-commits mailing list