diff --git a/index_tests/types/anonymous_struct.cc b/index_tests/types/anonymous_struct.cc index 5a70a817..b52a6ff7 100644 --- a/index_tests/types/anonymous_struct.cc +++ b/index_tests/types/anonymous_struct.cc @@ -65,6 +65,15 @@ OUTPUT: "types": [], "funcs": [], "vars": [{ + "L": 3348817847649945564, + "R": -1 + }, { + "L": 4821094820988543895, + "R": -1 + }, { + "L": 15292551660437765731, + "R": -1 + }, { "L": 1963212417280098348, "R": 0 }], diff --git a/src/clang_tu.cc b/src/clang_tu.cc index 8b5b1450..563adbec 100644 --- a/src/clang_tu.cc +++ b/src/clang_tu.cc @@ -401,12 +401,9 @@ std::unique_ptr ClangTranslationUnit::Create( std::unique_ptr ClangTranslationUnit::Reparse( std::unique_ptr tu, std::vector& unsaved) { - int error_code; - { - error_code = clang_reparseTranslationUnit( - tu->cx_tu, (unsigned)unsaved.size(), unsaved.data(), - clang_defaultReparseOptions(tu->cx_tu)); - } + int error_code = clang_reparseTranslationUnit( + tu->cx_tu, (unsigned)unsaved.size(), unsaved.data(), + clang_defaultReparseOptions(tu->cx_tu)); if (error_code != CXError_Success && tu->cx_tu) EmitDiagnostics("", {}, tu->cx_tu); diff --git a/src/indexer.cc b/src/indexer.cc index 1e5720b9..229e671b 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -1655,16 +1655,23 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { case CXIdxEntity_Typedef: case CXIdxEntity_CXXTypeAlias: { - // Note we want to fetch the first TypeRef. Running - // ResolveCursorType(decl->cursor) would return - // the type of the typedef/using, not the type of the referenced type. - IndexType* alias_of = AddDeclTypeUsages( - db, cursor, nullptr, decl->semanticContainer, decl->lexicalContainer); - IndexType& type = db->ToType(HashUsr(decl->entityInfo->USR)); - - if (alias_of) - type.def.alias_of = alias_of->usr; + CXType Type = clang_getCursorType(decl->entityInfo->cursor); + CXType CanonType = clang_getCanonicalType(Type);; + if (clang_equalTypes(Type, CanonType) == 0) { + Usr type_usr = ClangType(CanonType).get_usr_hash(); + if (db->usr2type.count(type_usr)) { + type.def.alias_of = type_usr; + } else { + // Note we want to fetch the first TypeRef. Running + // ResolveCursorType(decl->cursor) would return + // the type of the typedef/using, not the type of the referenced type. + IndexType* alias_of = AddDeclTypeUsages( + db, cursor, nullptr, decl->semanticContainer, decl->lexicalContainer); + if (alias_of) + type.def.alias_of = alias_of->usr; + } + } Range spell = cursor.get_spell(); Range extent = cursor.get_extent(); @@ -1709,17 +1716,11 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { IndexType& type = db->ToType(HashUsr(decl->entityInfo->USR)); - // TODO: Eventually run with this if. Right now I want to iron out bugs - // this may shadow. - // TODO: For type section, verify if this ever runs for non definitions? - // if (!decl->isRedeclaration) { - SetTypeName(type, cursor, decl->semanticContainer, decl->entityInfo->name, param); type.def.kind = GetSymbolKind(decl->entityInfo->kind); if (g_config->index.comments) type.def.comments = Intern(cursor.get_comments()); - // } if (decl->isDefinition) { type.def.spell = SetUse(db, spell, sem_parent, Role::Definition); @@ -1781,12 +1782,6 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { } } - // type_def->alias_of - // type_def->funcs - // type_def->types - // type_def->uses - // type_def->vars - // Add type-level inheritance information. CXIdxCXXClassDeclInfo const* class_info = clang_index_getCXXClassDeclInfo(decl); diff --git a/src/pipeline.cc b/src/pipeline.cc index 13cef395..d511b1c3 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -94,17 +94,9 @@ bool FileNeedsParse(int64_t write_time, } // Command-line arguments changed. - auto is_file = [](const std::string& arg) { - return EndsWithAny(arg, {".h", ".c", ".cc", ".cpp", ".hpp", ".m", ".mm"}); - }; if (opt_previous_index) { auto& prev_args = opt_previous_index->args; - bool same = prev_args.size() == args.size(); - for (size_t i = 0; i < args.size() && same; ++i) { - same = prev_args[i] == args[i] || - (is_file(prev_args[i]) && is_file(args[i])); - } - if (!same) { + if (prev_args != args) { LOG_S(INFO) << "args changed for " << path << (from ? " (via " + *from + ")" : std::string()); return true; } @@ -483,11 +475,10 @@ void MainLoop() { Main_OnIndexed(&db, &semantic_cache, &working_files, &*update); } - // Cleanup and free any unused memory. - FreeUnusedMemory(); - - if (!did_work) + if (!did_work) { + FreeUnusedMemory(); main_waiter->Wait(on_indexed, on_request); + } } } diff --git a/src/project.cc b/src/project.cc index 4c7bf737..db65eb68 100644 --- a/src/project.cc +++ b/src/project.cc @@ -48,7 +48,7 @@ struct CompileCommandsEntry { return path; SmallString<256> Ret; sys::path::append(Ret, directory, path); - return Ret.str(); + return NormalizePath(Ret.str()); } }; MAKE_REFLECT_STRUCT(CompileCommandsEntry, directory, file, command, args);