From c5ae521d36a0cd05b5df7ddd2e03ab23b68e8270 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Tue, 9 Oct 2018 22:29:51 -0700 Subject: [PATCH] Namespace: improve indexer and don't trace bases in $ccls/member --- src/indexer.cc | 13 +++++++++++-- src/messages/ccls_member.cc | 16 +++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/indexer.cc b/src/indexer.cc index e4356146..34137630 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -734,8 +734,17 @@ public: // spell, extent, comments use OrigD while most others use adjusted |D|. const Decl *OrigD = ASTNode.OrigD; - const DeclContext *SemDC = OrigD->getDeclContext(); - const DeclContext *LexDC = ASTNode.ContainerDC; + const DeclContext *SemDC = OrigD->getDeclContext()->getRedeclContext(); + const DeclContext *LexDC = ASTNode.ContainerDC->getRedeclContext(); + { + const NamespaceDecl *ND; + while ((ND = dyn_cast(cast(SemDC))) && + ND->isAnonymousNamespace()) + SemDC = ND->getDeclContext()->getRedeclContext(); + while ((ND = dyn_cast(cast(LexDC))) && + ND->isAnonymousNamespace()) + LexDC = ND->getDeclContext()->getRedeclContext(); + } Role role = static_cast(Roles); db->language = LanguageId((int)db->language | (int)GetDeclLanguage(D)); diff --git a/src/messages/ccls_member.cc b/src/messages/ccls_member.cc index 47241aad..b5ae481b 100644 --- a/src/messages/ccls_member.cc +++ b/src/messages/ccls_member.cc @@ -145,14 +145,16 @@ bool Expand(MessageHandler *m, Out_CclsMember::Entry *entry, type = stack.back(); stack.pop_back(); const auto *def = type->AnyDef(); - if (!def) continue; - for (Usr usr : def->bases) { - auto &type1 = m->db->Type(usr); - if (type1.def.size()) { - seen.insert(type1.usr); - stack.push_back(&type1); + if (!def) + continue; + if (def->kind != lsSymbolKind::Namespace) + for (Usr usr : def->bases) { + auto &type1 = m->db->Type(usr); + if (type1.def.size()) { + seen.insert(type1.usr); + stack.push_back(&type1); + } } - } if (def->alias_of) { const QueryType::Def *def1 = m->db->Type(def->alias_of).AnyDef(); Out_CclsMember::Entry entry1;