[PATCH] D97983: [clangd] strictly respect formatting range
Quentin Chateau via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 4 14:49:02 PST 2021
qchateau updated this revision to Diff 328314.
qchateau added a comment.
fix tests
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D97983/new/
https://reviews.llvm.org/D97983
Files:
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/test/formatting.test
Index: clang-tools-extra/clangd/test/formatting.test
===================================================================
--- clang-tools-extra/clangd/test/formatting.test
+++ clang-tools-extra/clangd/test/formatting.test
@@ -8,19 +8,6 @@
# CHECK-NEXT: "jsonrpc": "2.0",
# CHECK-NEXT: "result": [
# CHECK-NEXT: {
-# CHECK-NEXT: "newText": "\n ",
-# CHECK-NEXT: "range": {
-# CHECK-NEXT: "end": {
-# CHECK-NEXT: "character": 4,
-# CHECK-NEXT: "line": 1
-# CHECK-NEXT: },
-# CHECK-NEXT: "start": {
-# CHECK-NEXT: "character": 19,
-# CHECK-NEXT: "line": 0
-# CHECK-NEXT: }
-# CHECK-NEXT: }
-# CHECK-NEXT: },
-# CHECK-NEXT: {
# CHECK-NEXT: "newText": " ",
# CHECK-NEXT: "range": {
# CHECK-NEXT: "end": {
@@ -45,19 +32,6 @@
# CHECK-NEXT: "line": 1
# CHECK-NEXT: }
# CHECK-NEXT: }
-# CHECK-NEXT: },
-# CHECK-NEXT: {
-# CHECK-NEXT: "newText": "\n ",
-# CHECK-NEXT: "range": {
-# CHECK-NEXT: "end": {
-# CHECK-NEXT: "character": 4,
-# CHECK-NEXT: "line": 2
-# CHECK-NEXT: },
-# CHECK-NEXT: "start": {
-# CHECK-NEXT: "character": 12,
-# CHECK-NEXT: "line": 1
-# CHECK-NEXT: }
-# CHECK-NEXT: }
# CHECK-NEXT: }
# CHECK-NEXT: ]
---
Index: clang-tools-extra/clangd/ClangdServer.cpp
===================================================================
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -423,10 +423,24 @@
if (!Changed)
return CB(Changed.takeError());
- CB(IncludeReplaces.merge(format::reformat(
+ auto Replacements = IncludeReplaces.merge(format::reformat(
Style, *Changed,
tooling::calculateRangesAfterReplacements(IncludeReplaces, Ranges),
- File)));
+ File));
+ clang::tooling::Replacements ReplacementsInRange;
+ for (const auto &Repl : Replacements) {
+ tooling::Range ReplRange{
+ Repl.getOffset(),
+ std::max<unsigned int>(Repl.getLength(),
+ Repl.getReplacementText().size()),
+ };
+ if (ReplRange.overlapsWith(Ranges.front())) {
+ if (auto Err = ReplacementsInRange.add(Repl)) {
+ CB(std::move(Err));
+ }
+ }
+ }
+ CB(ReplacementsInRange);
};
WorkScheduler->runQuick("Format", File, std::move(Action));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97983.328314.patch
Type: text/x-patch
Size: 2455 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210304/169aaa42/attachment.bin>
More information about the cfe-commits
mailing list