[PATCH] D63759: [clangd] Don't rename the namespace.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 25 04:31:45 PDT 2019
hokein updated this revision to Diff 206412.
hokein marked 3 inline comments as done.
hokein added a comment.
Address review comments.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63759/new/
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 "symbol is not a supported kind (e.g. namespace)";
}
llvm_unreachable("unhandled reason kind");
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63759.206412.patch
Type: text/x-patch
Size: 3159 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190625/8dd7662c/attachment-0001.bin>
More information about the cfe-commits
mailing list