[clang] [clang-tools-extra] [clangd] Fix: exclude insertions at end of CursorPlaceholder in formatting (PR #87746)

via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 6 06:43:53 PDT 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 d4cd65ecf2546e509f43363f96364c976f49b9da 03fe6bec808cb968c35f1bad7432ea6155ed0115 -- clang-tools-extra/clangd/Format.cpp clang-tools-extra/clangd/unittests/FormatTests.cpp clang/include/clang/Tooling/Core/Replacement.h clang/lib/Tooling/Core/Replacement.cpp
``````````

</details>

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

``````````diff
diff --git a/clang-tools-extra/clangd/unittests/FormatTests.cpp b/clang-tools-extra/clangd/unittests/FormatTests.cpp
index 22c19fefc6..72e662a070 100644
--- a/clang-tools-extra/clangd/unittests/FormatTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FormatTests.cpp
@@ -317,7 +317,7 @@ vector<int> x = {1, 2, 3}^
 
 TEST(FormatIncremental, InsertBraces) {
   format::FormatStyle Style =
-    format::getGoogleStyle(format::FormatStyle::LK_Cpp);
+      format::getGoogleStyle(format::FormatStyle::LK_Cpp);
   Style.InsertBraces = true;
   expectAfterNewline(R"cpp(
 int main() {
diff --git a/clang/include/clang/Tooling/Core/Replacement.h b/clang/include/clang/Tooling/Core/Replacement.h
index 69fe5186df..d2b79e4ab0 100644
--- a/clang/include/clang/Tooling/Core/Replacement.h
+++ b/clang/include/clang/Tooling/Core/Replacement.h
@@ -271,7 +271,8 @@ public:
   // If \p includeInsAtPos is true and there is an insertion at Offset in the
   // current replacements, \p Offset will be shifted to Offset + Length in
   // inserted text. Otherwise, the insertion at Offset will not be counted in.
-  unsigned getShiftedCodePosition(unsigned Position, bool includeInsAtPos = true) const;
+  unsigned getShiftedCodePosition(unsigned Position,
+                                  bool includeInsAtPos = true) const;
 
   unsigned size() const { return Replaces.size(); }
 
diff --git a/clang/lib/Tooling/Core/Replacement.cpp b/clang/lib/Tooling/Core/Replacement.cpp
index 95a3b62f47..07d3e4e587 100644
--- a/clang/lib/Tooling/Core/Replacement.cpp
+++ b/clang/lib/Tooling/Core/Replacement.cpp
@@ -549,8 +549,8 @@ unsigned Replacements::getShiftedCodePosition(unsigned Position,
   unsigned Offset = 0;
   for (const auto &R : Replaces) {
     unsigned End = R.getOffset() + R.getLength();
-    if (End <= Position
-        && (includeInsAtPos || (End < Position || R.getLength() > 0))) {
+    if (End <= Position &&
+        (includeInsAtPos || (End < Position || R.getLength() > 0))) {
       Offset += R.getReplacementText().size() - R.getLength();
       continue;
     }

``````````

</details>


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


More information about the cfe-commits mailing list