diff --git a/src/clang_complete.cc b/src/clang_complete.cc index 15b0761e..1fa09840 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -329,7 +329,7 @@ public: ls_items[j].insertTextFormat == lsInsertTextFormat::Snippet) ls_items[j].insertText += "$0"; ls_items[j].priority_ = GetCompletionPriority( - *CCS, Results[i].CursorKind, ls_items[i].filterText); + *CCS, Results[i].CursorKind, ls_items[j].filterText); } } else { bool do_insert = true; diff --git a/src/indexer.cc b/src/indexer.cc index 14bf3123..8afb6eb7 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -489,7 +489,7 @@ public: const LangOptions& Lang = Ctx->getLangOpts(); SourceRange R = init->getSourceRange(); SourceLocation L = D->getLocation(); - if (!SM.isBeforeInTranslationUnit(L, R.getBegin())) + if (L.isMacroID() || !SM.isBeforeInTranslationUnit(L, R.getBegin())) return; StringRef Buf = GetSourceInRange(SM, Lang, R); Twine T = Buf.count('\n') <= kInitializerMaxLines - 1 @@ -726,14 +726,23 @@ public: switch (D->getKind()) { case Decl::Namespace: type->def.kind = lsSymbolKind::Namespace; + if (OrigD->isFirstDecl()) { + auto *ND = cast(OrigD); + auto *ND1 = cast(ND->getParent()); + if (isa(ND1)) { + Usr usr1 = GetUsr(ND1); + type->def.bases.push_back(usr1); + db->ToType(usr1).derived.push_back(usr); + } + } break; case Decl::NamespaceAlias: { type->def.kind = lsSymbolKind::TypeAlias; - auto* NAD = cast(D); - if (const NamespaceDecl* ND = NAD->getNamespace()) { + auto *NAD = cast(D); + if (const NamespaceDecl *ND = NAD->getNamespace()) { Usr usr1 = GetUsr(ND); - if (db->usr2type.count(usr1)) - type->def.alias_of = usr1; + type->def.alias_of = usr1; + (void)db->ToType(usr1); } break; } @@ -783,11 +792,8 @@ public: } if (BaseD) { Usr usr1 = GetUsr(BaseD); - auto it = db->usr2type.find(usr1); - if (it != db->usr2type.end()) { - type->def.bases.push_back(usr1); - it->second.derived.push_back(usr); - } + type->def.bases.push_back(usr1); + db->ToType(usr1).derived.push_back(usr); } } } @@ -828,11 +834,8 @@ public: D1 = RD->getInstantiatedFromMemberClass(); if (D1) { Usr usr1 = GetUsr(D1); - auto it = db->usr2type.find(usr1); - if (it != db->usr2type.end()) { - type->def.bases.push_back(usr1); - it->second.derived.push_back(usr); - } + type->def.bases.push_back(usr1); + db->ToType(usr1).derived.push_back(usr); } } } @@ -868,11 +871,8 @@ public: Ctx->getOverriddenMethods(ND, OverDecls); for (const auto* ND1 : OverDecls) { Usr usr1 = GetUsr(ND1); - auto it = db->usr2func.find(usr1); - if (it != db->usr2func.end()) { - func->def.bases.push_back(usr1); - it->second.derived.push_back(usr); - } + func->def.bases.push_back(usr1); + db->ToFunc(usr1).derived.push_back(usr); } } } @@ -1064,26 +1064,18 @@ std::string IndexFile::ToString() { return ccls::Serialize(SerializeFormat::Json, *this); } -void Uniquify(std::vector& usrs) { - std::unordered_set seen; - size_t n = 0; - for (size_t i = 0; i < usrs.size(); i++) - if (seen.insert(usrs[i]).second) - usrs[n++] = usrs[i]; - usrs.resize(n); -} +MAKE_HASHABLE(Use, t.range, t.file_id) -void Uniquify(std::vector& uses) { - std::unordered_set seen; +template +void Uniquify(std::vector& a) { + std::unordered_set seen; size_t n = 0; - for (size_t i = 0; i < uses.size(); i++) { - if (seen.insert(uses[i].range).second) - uses[n++] = uses[i]; - } - uses.resize(n); + for (size_t i = 0; i < a.size(); i++) + if (seen.insert(a[i]).second) + a[n++] = a[i]; + a.resize(n); } - namespace ccls::idx { std::vector> Index( VFS* vfs, diff --git a/src/project.cc b/src/project.cc index 2777634c..b564b591 100644 --- a/src/project.cc +++ b/src/project.cc @@ -154,8 +154,8 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( continue; } - if (!sys::fs::exists(HeaderOpts.ResourceDir) && HeaderOpts.UseBuiltinIncludes) - args.push_back("-resource-dir=" + g_config->clang.resourceDir); + // if (!sys::fs::exists(HeaderOpts.ResourceDir) && HeaderOpts.UseBuiltinIncludes) + args.push_back("-resource-dir=" + g_config->clang.resourceDir); if (CI->getFileSystemOpts().WorkingDir.empty()) args.push_back("-working-directory=" + entry.directory);