[PATCH] D105039: [clangd] Add a flag to disable formatting of tweak edits

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 28 09:12:25 PDT 2021


kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Some tweaks might edit file types not supported by clang-format. This
patch gives them a way to signal that they do not require formatting.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105039

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/refactor/Tweak.h


Index: clang-tools-extra/clangd/refactor/Tweak.h
===================================================================
--- clang-tools-extra/clangd/refactor/Tweak.h
+++ clang-tools-extra/clangd/refactor/Tweak.h
@@ -78,6 +78,9 @@
     /// A message to be displayed to the user.
     llvm::Optional<std::string> ShowMessage;
     FileEdits ApplyEdits;
+    /// Whether the edits should be formatted before presenting to the client.
+    /// Note that it applies to all files.
+    bool FormatEdits = true;
 
     static Effect showMessage(StringRef S) {
       Effect E;
Index: clang-tools-extra/clangd/ClangdServer.cpp
===================================================================
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -637,8 +637,8 @@
       Effect = T.takeError();
     }
     assert(Effect.hasValue() && "Expected at least one selection");
-    if (*Effect) {
-      // Tweaks don't apply clang-format, do that centrally here.
+    if (*Effect && (*Effect)->FormatEdits) {
+      // Format tweaks that require it centrally here.
       for (auto &It : (*Effect)->ApplyEdits) {
         Edit &E = It.second;
         format::FormatStyle Style =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105039.354923.patch
Type: text/x-patch
Size: 1207 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210628/0082397f/attachment.bin>


More information about the cfe-commits mailing list