[PATCH] D63759: [clangd] Don't rename the namespace.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 25 03:43:46 PDT 2019


hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.

Also fix a small bug -- the extra argument "-xc++" doesn't overwrite the
language if the argument is present after the file name in the compiler
command.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63759

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp


Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -31,7 +31,7 @@
   Files[FullHeaderName] = HeaderCode;
   Files[ImportThunk] = ThunkContents;
 
-  std::vector<const char *> Cmd = {"clang", FullFilename.c_str()};
+  std::vector<const char *> Cmd = {"clang"};
   // FIXME: this shouldn't need to be conditional, but it breaks a
   // GoToDefinition test for some reason (getMacroArgExpandedLocation fails).
   if (!HeaderCode.empty()) {
@@ -40,6 +40,9 @@
                                       : FullHeaderName.c_str());
   }
   Cmd.insert(Cmd.end(), ExtraArgs.begin(), ExtraArgs.end());
+  // Put the file name at the end -- this allows the extra arg (-xc++) to
+  // override the language setting.
+  Cmd.push_back(FullFilename.c_str());
   ParseInputs Inputs;
   Inputs.CompileCommand.Filename = FullFilename;
   Inputs.CompileCommand.CommandLine = {Cmd.begin(), Cmd.end()};
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -115,6 +115,10 @@
         class Unin^dexable {};
         }
       )cpp",
+
+      R"cpp(// disallow -- namespace symbol isn't supported
+        namespace fo^o {}
+      )cpp",
   };
   const char *CommonHeader = "class Outside {};";
   TestTU OtherFile = TestTU::withCode("Outside s;");
@@ -129,7 +133,8 @@
     TestTU TU = TestTU::withCode(T.code());
     TU.Filename = "test.h";
     TU.HeaderCode = CommonHeader;
-    TU.ExtraArgs.push_back("-xc++");
+    // Parsing the .h file as C++ include.
+    TU.ExtraArgs.push_back("-xobjective-c++-header");
     auto AST = TU.build();
 
     auto Results = renameWithinFile(AST, testPath(TU.Filename), T.point(),
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -93,12 +93,15 @@
   NoIndexProvided,
   NonIndexable,
   UsedOutsideFile,
+  UnsupportedSymbol,
 };
 
 // Check the symbol Decl is renameable (per the index) within the file.
 llvm::Optional<ReasonToReject> renamableWithinFile(const NamedDecl &Decl,
                                                    StringRef MainFile,
                                                    const SymbolIndex *Index) {
+  if (llvm::isa<NamespaceDecl>(&Decl))
+    return ReasonToReject::UnsupportedSymbol;
   auto &ASTCtx = Decl.getASTContext();
   const auto &SM = ASTCtx.getSourceManager();
   bool MainFileIsHeader = ASTCtx.getLangOpts().IsHeaderFile;
@@ -160,6 +163,8 @@
         return "the symbol is used outside main file";
       case NonIndexable:
         return "symbol may be used in other files (not eligible for indexing)";
+      case UnsupportedSymbol:
+        return "not a supported symbol (e.g. namespace)";
       }
       llvm_unreachable("unhandled reason kind");
     };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63759.206402.patch
Type: text/x-patch
Size: 3151 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190625/642429f7/attachment.bin>


More information about the cfe-commits mailing list