[PATCH] D151294: [clangd] Remove inline Specifier for DefineOutline Tweak

Brian Gluzman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 25 11:30:27 PDT 2023


bgluzman updated this revision to Diff 525715.
bgluzman added a comment.

address diff comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151294/new/

https://reviews.llvm.org/D151294

Files:
  clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp


Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -131,15 +131,12 @@
   return QualifiedFunc->substr(FuncBegin, FuncEnd - FuncBegin + 1);
 }
 
-// Returns Replacements deleting given keywords from function defintion.
-// Removes matching instances of given token preceeding the function defition.
+// Returns replacements to delete tokens with kind `Kind` in the range
+// `FromRange`. Removes matching instances of given token preceeding the
+// function defition.
 llvm::Expected<tooling::Replacements>
-getDelKeywordReplacements(const FunctionDecl *FD,
-                          const syntax::TokenBuffer &TokBuf,
-                          tok::TokenKind Kind, SourceRange FromRange) {
-  auto &AST = FD->getASTContext();
-  auto &SM = AST.getSourceManager();
-
+deleteTokensWithKind(const syntax::TokenBuffer &TokBuf, tok::TokenKind Kind,
+                     SourceRange FromRange) {
   tooling::Replacements DelKeywordCleanups;
   llvm::Error Errors = llvm::Error::success();
   bool FoundAny = false;
@@ -155,6 +152,7 @@
                 tok::getKeywordSpelling(Kind)));
       break;
     }
+    auto &SM = TokBuf.sourceManager();
     CharSourceRange DelRange =
         syntax::Token::range(SM, Spelling->front(), Spelling->back())
             .toCharRange(SM);
@@ -294,7 +292,7 @@
   DelAttr(FD->getAttr<FinalAttr>());
 
   auto DelKeyword = [&](tok::TokenKind Kind, SourceRange FromRange) {
-    auto DelKeywords = getDelKeywordReplacements(FD, TokBuf, Kind, FromRange);
+    auto DelKeywords = deleteTokensWithKind(TokBuf, Kind, FromRange);
     if (!DelKeywords) {
       Errors = llvm::joinErrors(std::move(Errors), DelKeywords.takeError());
       return;
@@ -485,20 +483,17 @@
     if (!Effect)
       return Effect.takeError();
 
-    tooling::Replacements HeaderUpdates;
-    const tooling::Replacement DeleteFuncBody(
+    tooling::Replacements HeaderUpdates(tooling::Replacement(
         Sel.AST->getSourceManager(),
         CharSourceRange::getTokenRange(*toHalfOpenFileRange(
             SM, Sel.AST->getLangOpts(),
             getDeletionRange(Source, Sel.AST->getTokens()))),
-        ";");
-    if (auto Err = HeaderUpdates.add(DeleteFuncBody))
-      return Err;
+        ";"));
 
     if (Source->isInlineSpecified()) {
-      auto DelInline = getDelKeywordReplacements(
-          Source, Sel.AST->getTokens(), tok::kw_inline,
-          {Source->getBeginLoc(), Source->getLocation()});
+      auto DelInline =
+          deleteTokensWithKind(Sel.AST->getTokens(), tok::kw_inline,
+                               {Source->getBeginLoc(), Source->getLocation()});
       if (!DelInline)
         return DelInline.takeError();
       HeaderUpdates = HeaderUpdates.merge(*DelInline);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151294.525715.patch
Type: text/x-patch
Size: 2930 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230525/aef380ab/attachment.bin>


More information about the cfe-commits mailing list