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(Context)) + if (isa(Context)) { Info.AccessibleScopes.push_back(""); // global namespace - else if (isa(Context)) - Info.AccessibleScopes.push_back(printNamespaceScope(*Context)); + } else if (isa(Context)) { + auto S = printNamespaceScope(*Context); + if (!S.empty()) + Info.AccessibleScopes.push_back(std::move(S)); + } } return Info; }; 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(