#pragma once #include "query.h" #include "working_files.h" #include Maybe GetDefinitionSpellingOfSymbol(QueryDatabase* db, SymbolIdx sym); Maybe GetDefinitionExtentOfSymbol(QueryDatabase* db, SymbolIdx sym); Maybe GetDeclarationFileForSymbol(QueryDatabase* db, SymbolIdx sym); std::vector ToUses(QueryDatabase* db, const std::vector& ids); std::vector ToUses(QueryDatabase* db, const std::vector& ids); std::vector ToUses(QueryDatabase* db, const std::vector& ids); std::vector GetDeclarationsOfSymbolForGotoDefinition( QueryDatabase* db, SymbolIdx sym); bool HasCallersOnSelfOrBaseOrDerived(QueryDatabase* db, QueryFunc& root); std::vector GetCallersForAllBaseFunctions(QueryDatabase* db, QueryFunc& root); std::vector GetCallersForAllDerivedFunctions(QueryDatabase* db, QueryFunc& root); optional GetLsPosition(WorkingFile* working_file, const Position& position); optional GetLsRange(WorkingFile* working_file, const Range& location); lsDocumentUri GetLsDocumentUri(QueryDatabase* db, QueryFileId file_id, std::string* path); lsDocumentUri GetLsDocumentUri(QueryDatabase* db, QueryFileId file_id); optional GetLsLocation(QueryDatabase* db, WorkingFiles* working_files, Use use); optional GetLsLocationEx(QueryDatabase* db, WorkingFiles* working_files, Use use, bool container); std::vector GetLsLocationExs(QueryDatabase* db, WorkingFiles* working_files, const std::vector& refs, bool container, int limit); // Returns a symbol. The symbol will have *NOT* have a location assigned. optional GetSymbolInfo(QueryDatabase* db, WorkingFiles* working_files, SymbolIdx sym, bool use_short_name); std::vector FindSymbolsAtLocation(WorkingFile* working_file, QueryFile* file, lsPosition position); void EmitDiagnostics(WorkingFiles* working_files, std::string path, std::vector diagnostics); template void WithEntity(QueryDatabase* db, SymbolIdx sym, Fn&& fn) { switch (sym.kind) { case SymbolKind::Invalid: case SymbolKind::File: break; case SymbolKind::Func: fn(db->GetFunc(sym)); break; case SymbolKind::Type: fn(db->GetType(sym)); break; case SymbolKind::Var: fn(db->GetVar(sym)); break; } } template void EachEntityDef(QueryDatabase* db, SymbolIdx sym, Fn&& fn) { WithEntity(db, sym, [&](const auto& entity) { for (auto& def : entity.def) if (!fn(def)) break; }); } template void EachUse(QueryDatabase* db, SymbolIdx sym, bool include_decl, Fn&& fn) { WithEntity(db, sym, [&](const auto& entity) { for (Use use : entity.uses) fn(use); if (include_decl) { for (auto& def : entity.def) if (def.spell) fn(*def.spell); for (Use use : entity.declarations) fn(use); } }); } template void EachDefinedEntity(std::vector& collection, const std::vector>& ids, Fn&& fn) { for (Id x : ids) { Q& obj = collection[x.id]; if (!obj.def.empty()) fn(obj); } }