Skip to content

Commit

Permalink
[include-fixer] Make search handle fully qualified names correctly.
Browse files Browse the repository at this point in the history
If a search string starts with "::" we don't want to return any results
for suffixes of that string.

Differential Revision: http://reviews.llvm.org/D20424

llvm-svn: 270055
  • Loading branch information
d0k committed May 19, 2016
1 parent 469db6a commit 9b15b6f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions clang-tools-extra/include-fixer/SymbolIndexManager.cpp
Expand Up @@ -24,6 +24,12 @@ SymbolIndexManager::search(llvm::StringRef Identifier) const {
llvm::SmallVector<llvm::StringRef, 8> Names;
Identifier.split(Names, "::");

bool IsFullyQualified = false;
if (Identifier.startswith("::")) {
Names.erase(Names.begin()); // Drop first (empty) element.
IsFullyQualified = true;
}

// As long as we don't find a result keep stripping name parts from the end.
// This is to support nested classes which aren't recorded in the database.
// Eventually we will either hit a class (namespaces aren't in the database
Expand Down Expand Up @@ -61,6 +67,11 @@ SymbolIndexManager::search(llvm::StringRef Identifier) const {
}
}

// If the name was qualified we only want to add results if we evaluated
// all contexts.
if (IsFullyQualified)
IsMatched &= (SymbolContext == Symbol.getContexts().end());

// FIXME: Support full match. At this point, we only find symbols in
// database which end with the same contexts with the identifier.
if (IsMatched && IdentiferContext == Names.rend()) {
Expand Down
Expand Up @@ -103,6 +103,12 @@ TEST(IncludeFixer, Typo) {
// too.
EXPECT_EQ("#include <string>\n\nstring foo;\n",
runIncludeFixer("string foo;\n"));

// Fully qualified name.
EXPECT_EQ("#include <string>\n\n::std::string foo;\n",
runIncludeFixer("::std::string foo;\n"));
// Should not match std::string.
EXPECT_EQ("::string foo;\n", runIncludeFixer("::string foo;\n"));
}

TEST(IncludeFixer, IncompleteType) {
Expand Down

0 comments on commit 9b15b6f

Please sign in to comment.