Better bases/derived and initializer

This commit is contained in:
Fangrui Song 2018-07-16 23:22:34 -07:00
parent d6ce5e6768
commit 389418f546
3 changed files with 31 additions and 39 deletions

View File

@ -329,7 +329,7 @@ public:
ls_items[j].insertTextFormat == lsInsertTextFormat::Snippet) ls_items[j].insertTextFormat == lsInsertTextFormat::Snippet)
ls_items[j].insertText += "$0"; ls_items[j].insertText += "$0";
ls_items[j].priority_ = GetCompletionPriority( ls_items[j].priority_ = GetCompletionPriority(
*CCS, Results[i].CursorKind, ls_items[i].filterText); *CCS, Results[i].CursorKind, ls_items[j].filterText);
} }
} else { } else {
bool do_insert = true; bool do_insert = true;

View File

@ -489,7 +489,7 @@ public:
const LangOptions& Lang = Ctx->getLangOpts(); const LangOptions& Lang = Ctx->getLangOpts();
SourceRange R = init->getSourceRange(); SourceRange R = init->getSourceRange();
SourceLocation L = D->getLocation(); SourceLocation L = D->getLocation();
if (!SM.isBeforeInTranslationUnit(L, R.getBegin())) if (L.isMacroID() || !SM.isBeforeInTranslationUnit(L, R.getBegin()))
return; return;
StringRef Buf = GetSourceInRange(SM, Lang, R); StringRef Buf = GetSourceInRange(SM, Lang, R);
Twine T = Buf.count('\n') <= kInitializerMaxLines - 1 Twine T = Buf.count('\n') <= kInitializerMaxLines - 1
@ -726,14 +726,23 @@ public:
switch (D->getKind()) { switch (D->getKind()) {
case Decl::Namespace: case Decl::Namespace:
type->def.kind = lsSymbolKind::Namespace; type->def.kind = lsSymbolKind::Namespace;
if (OrigD->isFirstDecl()) {
auto *ND = cast<NamespaceDecl>(OrigD);
auto *ND1 = cast<Decl>(ND->getParent());
if (isa<NamespaceDecl>(ND1)) {
Usr usr1 = GetUsr(ND1);
type->def.bases.push_back(usr1);
db->ToType(usr1).derived.push_back(usr);
}
}
break; break;
case Decl::NamespaceAlias: { case Decl::NamespaceAlias: {
type->def.kind = lsSymbolKind::TypeAlias; type->def.kind = lsSymbolKind::TypeAlias;
auto* NAD = cast<NamespaceAliasDecl>(D); auto *NAD = cast<NamespaceAliasDecl>(D);
if (const NamespaceDecl* ND = NAD->getNamespace()) { if (const NamespaceDecl *ND = NAD->getNamespace()) {
Usr usr1 = GetUsr(ND); Usr usr1 = GetUsr(ND);
if (db->usr2type.count(usr1))
type->def.alias_of = usr1; type->def.alias_of = usr1;
(void)db->ToType(usr1);
} }
break; break;
} }
@ -783,11 +792,8 @@ public:
} }
if (BaseD) { if (BaseD) {
Usr usr1 = GetUsr(BaseD); Usr usr1 = GetUsr(BaseD);
auto it = db->usr2type.find(usr1);
if (it != db->usr2type.end()) {
type->def.bases.push_back(usr1); type->def.bases.push_back(usr1);
it->second.derived.push_back(usr); db->ToType(usr1).derived.push_back(usr);
}
} }
} }
} }
@ -828,11 +834,8 @@ public:
D1 = RD->getInstantiatedFromMemberClass(); D1 = RD->getInstantiatedFromMemberClass();
if (D1) { if (D1) {
Usr usr1 = GetUsr(D1); Usr usr1 = GetUsr(D1);
auto it = db->usr2type.find(usr1);
if (it != db->usr2type.end()) {
type->def.bases.push_back(usr1); type->def.bases.push_back(usr1);
it->second.derived.push_back(usr); db->ToType(usr1).derived.push_back(usr);
}
} }
} }
} }
@ -868,11 +871,8 @@ public:
Ctx->getOverriddenMethods(ND, OverDecls); Ctx->getOverriddenMethods(ND, OverDecls);
for (const auto* ND1 : OverDecls) { for (const auto* ND1 : OverDecls) {
Usr usr1 = GetUsr(ND1); Usr usr1 = GetUsr(ND1);
auto it = db->usr2func.find(usr1);
if (it != db->usr2func.end()) {
func->def.bases.push_back(usr1); func->def.bases.push_back(usr1);
it->second.derived.push_back(usr); db->ToFunc(usr1).derived.push_back(usr);
}
} }
} }
} }
@ -1064,26 +1064,18 @@ std::string IndexFile::ToString() {
return ccls::Serialize(SerializeFormat::Json, *this); return ccls::Serialize(SerializeFormat::Json, *this);
} }
void Uniquify(std::vector<Usr>& usrs) { MAKE_HASHABLE(Use, t.range, t.file_id)
std::unordered_set<Usr> 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);
}
void Uniquify(std::vector<Use>& uses) { template <typename T>
std::unordered_set<Range> seen; void Uniquify(std::vector<T>& a) {
std::unordered_set<T> seen;
size_t n = 0; size_t n = 0;
for (size_t i = 0; i < uses.size(); i++) { for (size_t i = 0; i < a.size(); i++)
if (seen.insert(uses[i].range).second) if (seen.insert(a[i]).second)
uses[n++] = uses[i]; a[n++] = a[i];
} a.resize(n);
uses.resize(n);
} }
namespace ccls::idx { namespace ccls::idx {
std::vector<std::unique_ptr<IndexFile>> Index( std::vector<std::unique_ptr<IndexFile>> Index(
VFS* vfs, VFS* vfs,

View File

@ -154,7 +154,7 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
continue; continue;
} }
if (!sys::fs::exists(HeaderOpts.ResourceDir) && HeaderOpts.UseBuiltinIncludes) // if (!sys::fs::exists(HeaderOpts.ResourceDir) && HeaderOpts.UseBuiltinIncludes)
args.push_back("-resource-dir=" + g_config->clang.resourceDir); args.push_back("-resource-dir=" + g_config->clang.resourceDir);
if (CI->getFileSystemOpts().WorkingDir.empty()) if (CI->getFileSystemOpts().WorkingDir.empty())
args.push_back("-working-directory=" + entry.directory); args.push_back("-working-directory=" + entry.directory);