ioeric updated this revision to Diff 171924. ioeric added a comment. - Clarify documentation for printNamespaceScope
Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53926 Files: clangd/AST.h clangd/CodeComplete.cpp unittests/clangd/CodeCompleteTests.cpp Index: unittests/clangd/CodeCompleteTests.cpp =================================================================== --- unittests/clangd/CodeCompleteTests.cpp +++ unittests/clangd/CodeCompleteTests.cpp @@ -1142,6 +1142,18 @@ UnorderedElementsAre("")))); } +TEST(CompletionTest, NoDuplicatedGlobalScope) { + auto Requests = captureIndexRequests(R"cpp( + namespace { void f(); } + namespace ns { + ^ + } // namespace ns + )cpp"); + + EXPECT_THAT(Requests, ElementsAre(Field(&FuzzyFindRequest::Scopes, + ElementsAre("ns::", "")))); +} + TEST(CompletionTest, NoIndexCompletionsInsideClasses) { auto Completions = completions( R"cpp( Index: clangd/CodeComplete.cpp =================================================================== --- clangd/CodeComplete.cpp +++ clangd/CodeComplete.cpp @@ -560,10 +560,13 @@ auto GetAllAccessibleScopes = [](CodeCompletionContext &CCContext) { SpecifiedScope Info; for (auto *Context : CCContext.getVisitedContexts()) { - if (isa<TranslationUnitDecl>(Context)) + if (isa<TranslationUnitDecl>(Context)) { Info.AccessibleScopes.push_back(""); // global namespace - else if (isa<NamespaceDecl>(Context)) - Info.AccessibleScopes.push_back(printNamespaceScope(*Context)); + } else if (isa<NamespaceDecl>(Context)) { + auto S = printNamespaceScope(*Context); + if (!S.empty()) + Info.AccessibleScopes.push_back(std::move(S)); + } } return Info; }; Index: clangd/AST.h =================================================================== --- clangd/AST.h +++ clangd/AST.h @@ -39,7 +39,9 @@ /// like inline namespaces. std::string printQualifiedName(const NamedDecl &ND); -/// Returns the first enclosing namespace scope starting from \p DC. +/// Returns the first enclosing namespace scope starting from \p DC. This +/// returns "" if there is no enclosing namespace or the enclosing namespace is +/// anonymousor or inline. std::string printNamespaceScope(const DeclContext &DC); /// Gets the symbol ID for a declaration, if possible.
Index: unittests/clangd/CodeCompleteTests.cpp =================================================================== --- unittests/clangd/CodeCompleteTests.cpp +++ unittests/clangd/CodeCompleteTests.cpp @@ -1142,6 +1142,18 @@ UnorderedElementsAre("")))); } +TEST(CompletionTest, NoDuplicatedGlobalScope) { + auto Requests = captureIndexRequests(R"cpp( + namespace { void f(); } + namespace ns { + ^ + } // namespace ns + )cpp"); + + EXPECT_THAT(Requests, ElementsAre(Field(&FuzzyFindRequest::Scopes, + ElementsAre("ns::", "")))); +} + TEST(CompletionTest, NoIndexCompletionsInsideClasses) { auto Completions = completions( R"cpp( Index: clangd/CodeComplete.cpp =================================================================== --- clangd/CodeComplete.cpp +++ clangd/CodeComplete.cpp @@ -560,10 +560,13 @@ auto GetAllAccessibleScopes = [](CodeCompletionContext &CCContext) { SpecifiedScope Info; for (auto *Context : CCContext.getVisitedContexts()) { - if (isa<TranslationUnitDecl>(Context)) + if (isa<TranslationUnitDecl>(Context)) { Info.AccessibleScopes.push_back(""); // global namespace - else if (isa<NamespaceDecl>(Context)) - Info.AccessibleScopes.push_back(printNamespaceScope(*Context)); + } else if (isa<NamespaceDecl>(Context)) { + auto S = printNamespaceScope(*Context); + if (!S.empty()) + Info.AccessibleScopes.push_back(std::move(S)); + } } return Info; }; Index: clangd/AST.h =================================================================== --- clangd/AST.h +++ clangd/AST.h @@ -39,7 +39,9 @@ /// like inline namespaces. std::string printQualifiedName(const NamedDecl &ND); -/// Returns the first enclosing namespace scope starting from \p DC. +/// Returns the first enclosing namespace scope starting from \p DC. This +/// returns "" if there is no enclosing namespace or the enclosing namespace is +/// anonymousor or inline. std::string printNamespaceScope(const DeclContext &DC); /// Gets the symbol ID for a declaration, if possible.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits