[include-fixer] Add missing namespace qualifiers after inserting a missing header.
Summary:
This is an initial version of fixing namespace issues by adding missing
namespace qualifiers to an unidentified symbol.
This version only fixes the first discovered unidentified symbol.
In the long run, include-fixer should fix all unidentified symbols
with a same name at one run.
Currently, it works on command-line tool. The vim integration is not
implemented yet.
Reviewers: klimek, bkramer, djasper
Subscribers: bkramer, ioeric, cfe-commits
Differential Revision: http://reviews.llvm.org/D21603
llvm-svn: 274832
diff --git a/clang-tools-extra/include-fixer/SymbolIndexManager.cpp b/clang-tools-extra/include-fixer/SymbolIndexManager.cpp
index ae9faa2..970a612 100644
--- a/clang-tools-extra/include-fixer/SymbolIndexManager.cpp
+++ b/clang-tools-extra/include-fixer/SymbolIndexManager.cpp
@@ -20,7 +20,7 @@
using clang::find_all_symbols::SymbolInfo;
-/// Sorts and uniques SymbolInfos based on the popularity info in SymbolInfo.
+/// Sorts SymbolInfos based on the popularity info in SymbolInfo.
static void rankByPopularity(std::vector<SymbolInfo> &Symbols) {
// First collect occurrences per header file.
llvm::DenseMap<llvm::StringRef, unsigned> HeaderPopularity;
@@ -39,17 +39,9 @@
return APop > BPop;
return A.getFilePath() < B.getFilePath();
});
-
- // Deduplicate based on the file name. They will have the same popularity and
- // we don't want to suggest the same header twice.
- Symbols.erase(std::unique(Symbols.begin(), Symbols.end(),
- [](const SymbolInfo &A, const SymbolInfo &B) {
- return A.getFilePath() == B.getFilePath();
- }),
- Symbols.end());
}
-std::vector<std::string>
+std::vector<find_all_symbols::SymbolInfo>
SymbolIndexManager::search(llvm::StringRef Identifier) const {
// The identifier may be fully qualified, so split it and get all the context
// names.
@@ -127,20 +119,7 @@
}
rankByPopularity(MatchedSymbols);
- std::vector<std::string> Results;
- for (const auto &Symbol : MatchedSymbols) {
- // FIXME: file path should never be in the form of <...> or "...", but
- // the unit test with fixed database use <...> file path, which might
- // need to be changed.
- // FIXME: if the file path is a system header name, we want to use
- // angle brackets.
- std::string FilePath = Symbol.getFilePath().str();
- Results.push_back((FilePath[0] == '"' || FilePath[0] == '<')
- ? FilePath
- : "\"" + FilePath + "\"");
- }
-
- return Results;
+ return MatchedSymbols;
}
} // namespace include_fixer