diff --git a/src/command_line.cc b/src/command_line.cc index a9f647e9..5932a0af 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -44,7 +44,7 @@ void PushBack(NonElidedVector* result, optional location result->push_back(*location); } -QueryableFile* FindFile(QueryableDatabase* db, const std::string& filename, QueryFileId* file_id) { +QueryFile* FindFile(QueryDatabase* db, const std::string& filename, QueryFileId* file_id) { auto it = db->usr_to_symbol.find(filename); if (it != db->usr_to_symbol.end()) { *file_id = QueryFileId(it->second.idx); @@ -56,7 +56,7 @@ QueryableFile* FindFile(QueryableDatabase* db, const std::string& filename, Quer return nullptr; } -QueryableFile* FindFile(QueryableDatabase* db, const std::string& filename) { +QueryFile* FindFile(QueryDatabase* db, const std::string& filename) { // TODO: consider calling NormalizePath here. It might add too much latency though. auto it = db->usr_to_symbol.find(filename); if (it != db->usr_to_symbol.end()) @@ -66,50 +66,32 @@ QueryableFile* FindFile(QueryableDatabase* db, const std::string& filename) { return nullptr; } -QueryableFile* GetQueryable(QueryableDatabase* db, const QueryFileId& id) { +QueryFile* GetQuery(QueryDatabase* db, const QueryFileId& id) { return &db->files[id.id]; } -QueryableTypeDef* GetQueryable(QueryableDatabase* db, const QueryTypeId& id) { +QueryType* GetQuery(QueryDatabase* db, const QueryTypeId& id) { return &db->types[id.id]; } -QueryableFuncDef* GetQueryable(QueryableDatabase* db, const QueryFuncId& id) { +QueryFunc* GetQuery(QueryDatabase* db, const QueryFuncId& id) { return &db->funcs[id.id]; } -QueryableVarDef* GetQueryable(QueryableDatabase* db, const QueryVarId& id) { +QueryVar* GetQuery(QueryDatabase* db, const QueryVarId& id) { return &db->vars[id.id]; } -#if false -optional GetDeclarationOfSymbol(QueryableDatabase* db, const SymbolIdx& symbol) { - switch (symbol.kind) { - case SymbolKind::Type: - return db->types[symbol.idx].def.definition_spelling; - case SymbolKind::Func: - return db->funcs[symbol.idx].; - case SymbolKind::Var: - return db->vars[symbol.idx].uses; - case SymbolKind::File: - case SymbolKind::Invalid: { - assert(false && "unexpected"); - break; - } - } - return {}; -} -#endif -optional GetDefinitionSpellingOfSymbol(QueryableDatabase* db, const QueryTypeId& id) { - return GetQueryable(db, id)->def.definition_spelling; +optional GetDefinitionSpellingOfSymbol(QueryDatabase* db, const QueryTypeId& id) { + return GetQuery(db, id)->def.definition_spelling; } -optional GetDefinitionSpellingOfSymbol(QueryableDatabase* db, const QueryFuncId& id) { - return GetQueryable(db, id)->def.definition_spelling; +optional GetDefinitionSpellingOfSymbol(QueryDatabase* db, const QueryFuncId& id) { + return GetQuery(db, id)->def.definition_spelling; } -optional GetDefinitionSpellingOfSymbol(QueryableDatabase* db, const QueryVarId& id) { - return GetQueryable(db, id)->def.definition_spelling; +optional GetDefinitionSpellingOfSymbol(QueryDatabase* db, const QueryVarId& id) { + return GetQuery(db, id)->def.definition_spelling; } -optional GetDefinitionSpellingOfSymbol(QueryableDatabase* db, const SymbolIdx& symbol) { +optional GetDefinitionSpellingOfSymbol(QueryDatabase* db, const SymbolIdx& symbol) { switch (symbol.kind) { case SymbolKind::Type: return db->types[symbol.idx].def.definition_spelling; @@ -127,7 +109,7 @@ optional GetDefinitionSpellingOfSymbol(QueryableDatabase* db, } -std::string GetHoverForSymbol(QueryableDatabase* db, const SymbolIdx& symbol) { +std::string GetHoverForSymbol(QueryDatabase* db, const SymbolIdx& symbol) { switch (symbol.kind) { case SymbolKind::Type: return db->types[symbol.idx].def.detailed_name; @@ -144,38 +126,38 @@ std::string GetHoverForSymbol(QueryableDatabase* db, const SymbolIdx& symbol) { return ""; } -std::vector ToQueryableLocation(QueryableDatabase* db, const std::vector& refs) { - std::vector locs; +std::vector ToQueryLocation(QueryDatabase* db, const std::vector& refs) { + std::vector locs; locs.reserve(refs.size()); for (const QueryFuncRef& ref : refs) locs.push_back(ref.loc); return locs; } -std::vector ToQueryableLocation(QueryableDatabase* db, const std::vector& ids) { - std::vector locs; +std::vector ToQueryLocation(QueryDatabase* db, const std::vector& ids) { + std::vector locs; locs.reserve(ids.size()); for (const QueryTypeId& id : ids) { - optional loc = GetDefinitionSpellingOfSymbol(db, id); + optional loc = GetDefinitionSpellingOfSymbol(db, id); if (loc) locs.push_back(loc.value()); } return locs; } -std::vector ToQueryableLocation(QueryableDatabase* db, const std::vector& ids) { - std::vector locs; +std::vector ToQueryLocation(QueryDatabase* db, const std::vector& ids) { + std::vector locs; locs.reserve(ids.size()); for (const QueryFuncId& id : ids) { - optional loc = GetDefinitionSpellingOfSymbol(db, id); + optional loc = GetDefinitionSpellingOfSymbol(db, id); if (loc) locs.push_back(loc.value()); } return locs; } -std::vector ToQueryableLocation(QueryableDatabase* db, const std::vector& ids) { - std::vector locs; +std::vector ToQueryLocation(QueryDatabase* db, const std::vector& ids) { + std::vector locs; locs.reserve(ids.size()); for (const QueryVarId& id : ids) { - optional loc = GetDefinitionSpellingOfSymbol(db, id); + optional loc = GetDefinitionSpellingOfSymbol(db, id); if (loc) locs.push_back(loc.value()); } @@ -184,14 +166,14 @@ std::vector ToQueryableLocation(QueryableDatabase* db, const -std::vector GetUsesOfSymbol(QueryableDatabase* db, const SymbolIdx& symbol) { +std::vector GetUsesOfSymbol(QueryDatabase* db, const SymbolIdx& symbol) { switch (symbol.kind) { case SymbolKind::Type: return db->types[symbol.idx].uses; case SymbolKind::Func: { // TODO: the vector allocation could be avoided. - const QueryableFuncDef& func = db->funcs[symbol.idx]; - std::vector result = ToQueryableLocation(db, func.callers); + const QueryFunc& func = db->funcs[symbol.idx]; + std::vector result = ToQueryLocation(db, func.callers); AddRange(&result, func.declarations); if (func.def.definition_spelling) result.push_back(*func.def.definition_spelling); @@ -208,20 +190,20 @@ std::vector GetUsesOfSymbol(QueryableDatabase* db, const Symb return {}; } -optional GetDefinitionExtentOfSymbol(QueryableDatabase* db, const QueryTypeId& id) { - return GetQueryable(db, id)->def.definition_extent; +optional GetDefinitionExtentOfSymbol(QueryDatabase* db, const QueryTypeId& id) { + return GetQuery(db, id)->def.definition_extent; } -optional GetDefinitionExtentOfSymbol(QueryableDatabase* db, const QueryFuncId& id) { - return GetQueryable(db, id)->def.definition_extent; +optional GetDefinitionExtentOfSymbol(QueryDatabase* db, const QueryFuncId& id) { + return GetQuery(db, id)->def.definition_extent; } -optional GetDefinitionExtentOfSymbol(QueryableDatabase* db, const QueryVarId& id) { - return GetQueryable(db, id)->def.definition_extent; +optional GetDefinitionExtentOfSymbol(QueryDatabase* db, const QueryVarId& id) { + return GetQuery(db, id)->def.definition_extent; } -optional GetDefinitionExtentOfSymbol(QueryableDatabase* db, const SymbolIdx& symbol) { +optional GetDefinitionExtentOfSymbol(QueryDatabase* db, const SymbolIdx& symbol) { switch (symbol.kind) { case SymbolKind::File: // TODO: If line 1 is deleted the file won't show up in, ie, workspace symbol search results. - return QueryableLocation(QueryFileId(symbol.idx), Range(false /*is_interesting*/, Position(1, 1), Position(1, 1))); + return QueryLocation(QueryFileId(symbol.idx), Range(false /*is_interesting*/, Position(1, 1), Position(1, 1))); case SymbolKind::Type: return db->types[symbol.idx].def.definition_extent; case SymbolKind::Func: @@ -236,14 +218,14 @@ optional GetDefinitionExtentOfSymbol(QueryableDatabase* db, c return nullopt; } -std::vector GetDeclarationsOfSymbolForGotoDefinition(QueryableDatabase* db, const SymbolIdx& symbol) { +std::vector GetDeclarationsOfSymbolForGotoDefinition(QueryDatabase* db, const SymbolIdx& symbol) { switch (symbol.kind) { case SymbolKind::Type: { // Returning the definition spelling of a type is a hack (and is why the // function has the postfix `ForGotoDefintion`, but it lets the user // jump to the start of a type if clicking goto-definition on the same // type from within the type definition. - optional declaration = db->types[symbol.idx].def.definition_spelling; + optional declaration = db->types[symbol.idx].def.definition_spelling; if (declaration) return { *declaration }; break; @@ -251,7 +233,7 @@ std::vector GetDeclarationsOfSymbolForGotoDefinition(Queryabl case SymbolKind::Func: return db->funcs[symbol.idx].declarations; case SymbolKind::Var: { - optional declaration = db->vars[symbol.idx].def.declaration; + optional declaration = db->vars[symbol.idx].def.declaration; if (declaration) return { *declaration }; break; @@ -261,41 +243,41 @@ std::vector GetDeclarationsOfSymbolForGotoDefinition(Queryabl return {}; } -optional GetBaseDefinitionOrDeclarationSpelling(QueryableDatabase* db, QueryableFuncDef& func) { +optional GetBaseDefinitionOrDeclarationSpelling(QueryDatabase* db, QueryFunc& func) { if (!func.def.base) return nullopt; - QueryableFuncDef& base = db->funcs[func.def.base->id]; + QueryFunc& base = db->funcs[func.def.base->id]; auto def = base.def.definition_spelling; if (!def && !base.declarations.empty()) def = base.declarations[0]; return def; } -std::vector GetCallersForAllBaseFunctions(QueryableDatabase* db, QueryableFuncDef& root) { +std::vector GetCallersForAllBaseFunctions(QueryDatabase* db, QueryFunc& root) { std::vector callers; optional func_id = root.def.base; while (func_id) { - QueryableFuncDef& def = db->funcs[func_id->id]; - AddRange(&callers, def.callers); - func_id = def.def.base; + QueryFunc& func = db->funcs[func_id->id]; + AddRange(&callers, func.callers); + func_id = func.def.base; } return callers; } -std::vector GetCallersForAllDerivedFunctions(QueryableDatabase* db, QueryableFuncDef& root) { +std::vector GetCallersForAllDerivedFunctions(QueryDatabase* db, QueryFunc& root) { std::vector callers; std::queue queue; PushRange(&queue, root.derived); while (!queue.empty()) { - QueryableFuncDef& def = db->funcs[queue.front().id]; + QueryFunc& func = db->funcs[queue.front().id]; queue.pop(); - PushRange(&queue, def.derived); + PushRange(&queue, func.derived); - AddRange(&callers, def.callers); + AddRange(&callers, func.callers); } return callers; @@ -317,17 +299,17 @@ optional GetLsRange(WorkingFile* working_file, const Range& location) { lsPosition(working_file->GetBufferLineFromDiskLine(location.end.line) - 1, location.end.column - 1)); } -lsDocumentUri GetLsDocumentUri(QueryableDatabase* db, QueryFileId file_id, std::string* path) { - *path = db->files[file_id.id].def.usr; +lsDocumentUri GetLsDocumentUri(QueryDatabase* db, QueryFileId file_id, std::string* path) { + *path = db->files[file_id.id].def.path; return lsDocumentUri::FromPath(*path); } -lsDocumentUri GetLsDocumentUri(QueryableDatabase* db, QueryFileId file_id) { - std::string path = db->files[file_id.id].def.usr; +lsDocumentUri GetLsDocumentUri(QueryDatabase* db, QueryFileId file_id) { + std::string path = db->files[file_id.id].def.path; return lsDocumentUri::FromPath(path); } -optional GetLsLocation(QueryableDatabase* db, WorkingFiles* working_files, const QueryableLocation& location) { +optional GetLsLocation(QueryDatabase* db, WorkingFiles* working_files, const QueryLocation& location) { std::string path; lsDocumentUri uri = GetLsDocumentUri(db, location.path, &path); optional range = GetLsRange(working_files->GetFileByFilename(path), location.range); @@ -337,29 +319,29 @@ optional GetLsLocation(QueryableDatabase* db, WorkingFiles* working_ } // Returns a symbol. The symbol will have *NOT* have a location assigned. -lsSymbolInformation GetSymbolInfo(QueryableDatabase* db, WorkingFiles* working_files, SymbolIdx symbol) { +lsSymbolInformation GetSymbolInfo(QueryDatabase* db, WorkingFiles* working_files, SymbolIdx symbol) { lsSymbolInformation info; switch (symbol.kind) { case SymbolKind::File: { - QueryableFile* def = symbol.ResolveFile(db); - info.name = def->def.usr; + QueryFile* file = symbol.ResolveFile(db); + info.name = file->def.path; info.kind = lsSymbolKind::File; break; } case SymbolKind::Type: { - QueryableTypeDef* def = symbol.ResolveType(db); - info.name = def->def.detailed_name; + QueryType* type = symbol.ResolveType(db); + info.name = type->def.detailed_name; info.kind = lsSymbolKind::Class; break; } case SymbolKind::Func: { - QueryableFuncDef* def = symbol.ResolveFunc(db); + QueryFunc* func = symbol.ResolveFunc(db); - info.name = def->def.detailed_name; - if (def->def.declaring_type.has_value()) { + info.name = func->def.detailed_name; + if (func->def.declaring_type.has_value()) { info.kind = lsSymbolKind::Method; - info.containerName = db->types[def->def.declaring_type->id].def.detailed_name; + info.containerName = db->types[func->def.declaring_type->id].def.detailed_name; } else { info.kind = lsSymbolKind::Function; @@ -367,8 +349,8 @@ lsSymbolInformation GetSymbolInfo(QueryableDatabase* db, WorkingFiles* working_f break; } case SymbolKind::Var: { - QueryableVarDef* def = symbol.ResolveVar(db); - info.name += def->def.detailed_name; + QueryVar* var = symbol.ResolveVar(db); + info.name += var->def.detailed_name; info.kind = lsSymbolKind::Variable; break; } @@ -383,15 +365,15 @@ lsSymbolInformation GetSymbolInfo(QueryableDatabase* db, WorkingFiles* working_f struct CommonCodeLensParams { std::vector* result; - QueryableDatabase* db; + QueryDatabase* db; WorkingFiles* working_files; WorkingFile* working_file; }; void AddCodeLens( CommonCodeLensParams* common, - QueryableLocation loc, - const std::vector& uses, + QueryLocation loc, + const std::vector& uses, const char* singular, const char* plural, bool exclude_loc = false, @@ -408,7 +390,7 @@ void AddCodeLens( // Add unique uses. std::unordered_set unique_uses; - for (const QueryableLocation& use : uses) { + for (const QueryLocation& use : uses) { if (exclude_loc && use == loc) continue; if (only_interesting && !use.range.interesting) @@ -433,7 +415,7 @@ void AddCodeLens( common->result->push_back(code_lens); } -lsWorkspaceEdit BuildWorkspaceEdit(QueryableDatabase* db, WorkingFiles* working_files, const std::vector& locations, const std::string& new_text) { +lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db, WorkingFiles* working_files, const std::vector& locations, const std::string& new_text) { std::unordered_map path_to_edit; for (auto& location : locations) { @@ -444,7 +426,7 @@ lsWorkspaceEdit BuildWorkspaceEdit(QueryableDatabase* db, WorkingFiles* working_ if (path_to_edit.find(location.path) == path_to_edit.end()) { path_to_edit[location.path] = lsTextDocumentEdit(); - const std::string& path = db->files[location.path.id].def.usr; + const std::string& path = db->files[location.path.id].def.path; path_to_edit[location.path].textDocument.uri = lsDocumentUri::FromPath(path); WorkingFile* working_file = working_files->GetFileByFilename(path); @@ -465,7 +447,7 @@ lsWorkspaceEdit BuildWorkspaceEdit(QueryableDatabase* db, WorkingFiles* working_ return edit; } -std::vector FindSymbolsAtLocation(QueryableFile* file, lsPosition position) { +std::vector FindSymbolsAtLocation(QueryFile* file, lsPosition position) { std::vector symbols; symbols.reserve(1); @@ -815,7 +797,7 @@ void IndexMain( void QueryDbMainLoop( - QueryableDatabase* db, + QueryDatabase* db, IpcMessageQueue* language_client, Index_DoIndexQueue* queue_do_index, Index_DoIdMapQueue* queue_do_id_map, @@ -906,7 +888,7 @@ void QueryDbMainLoop( auto msg = static_cast(message.get()); QueryFileId file_id; - QueryableFile* file = FindFile(db, msg->params.textDocument.uri.GetPath(), &file_id); + QueryFile* file = FindFile(db, msg->params.textDocument.uri.GetPath(), &file_id); if (!file) { std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl; break; @@ -916,7 +898,7 @@ void QueryDbMainLoop( for (const SymbolRef& ref : FindSymbolsAtLocation(file, msg->params.position)) { // Found symbol. Return references to rename. - std::vector uses = GetUsesOfSymbol(db, ref.idx); + std::vector uses = GetUsesOfSymbol(db, ref.idx); response.result = BuildWorkspaceEdit(db, working_files, uses, msg->params.newName); break; } @@ -945,7 +927,7 @@ void QueryDbMainLoop( auto msg = static_cast(message.get()); QueryFileId file_id; - QueryableFile* file = FindFile(db, msg->params.textDocument.uri.GetPath(), &file_id); + QueryFile* file = FindFile(db, msg->params.textDocument.uri.GetPath(), &file_id); if (!file) { std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl; break; @@ -965,12 +947,12 @@ void QueryDbMainLoop( // - start at spelling but end at extent for better mouse tooltip // - goto declaration while in definition of recursive type - optional def_loc = GetDefinitionSpellingOfSymbol(db, ref.idx); + optional def_loc = GetDefinitionSpellingOfSymbol(db, ref.idx); // We use spelling start and extent end because this causes vscode to // highlight the entire definition when previewing / hoving with the // mouse. - optional def_extent = GetDefinitionExtentOfSymbol(db, ref.idx); + optional def_extent = GetDefinitionExtentOfSymbol(db, ref.idx); if (def_loc && def_extent) def_loc->range.end = def_extent->range.end; @@ -982,7 +964,7 @@ void QueryDbMainLoop( def_loc->range.Contains(target_line, target_column))) { // Goto declaration. - std::vector declarations = GetDeclarationsOfSymbolForGotoDefinition(db, ref.idx); + std::vector declarations = GetDeclarationsOfSymbolForGotoDefinition(db, ref.idx); for (auto declaration : declarations) { optional ls_declaration = GetLsLocation(db, working_files, declaration); if (ls_declaration) @@ -1008,7 +990,7 @@ void QueryDbMainLoop( auto msg = static_cast(message.get()); QueryFileId file_id; - QueryableFile* file = FindFile(db, msg->params.textDocument.uri.GetPath(), &file_id); + QueryFile* file = FindFile(db, msg->params.textDocument.uri.GetPath(), &file_id); if (!file) { std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl; break; @@ -1018,9 +1000,9 @@ void QueryDbMainLoop( for (const SymbolRef& ref : FindSymbolsAtLocation(file, msg->params.position)) { // Found symbol. Return references to highlight. - std::vector uses = GetUsesOfSymbol(db, ref.idx); + std::vector uses = GetUsesOfSymbol(db, ref.idx); response.result.reserve(uses.size()); - for (const QueryableLocation& use : uses) { + for (const QueryLocation& use : uses) { if (use.path != file_id) continue; @@ -1043,7 +1025,7 @@ void QueryDbMainLoop( case IpcId::TextDocumentHover: { auto msg = static_cast(message.get()); - QueryableFile* file = FindFile(db, msg->params.textDocument.uri.GetPath()); + QueryFile* file = FindFile(db, msg->params.textDocument.uri.GetPath()); if (!file) { std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl; break; @@ -1053,7 +1035,7 @@ void QueryDbMainLoop( for (const SymbolRef& ref : FindSymbolsAtLocation(file, msg->params.position)) { // Found symbol. Return hover. - optional ls_range = GetLsRange(working_files->GetFileByFilename(file->def.usr), ref.loc.range); + optional ls_range = GetLsRange(working_files->GetFileByFilename(file->def.path), ref.loc.range); if (!ls_range) continue; @@ -1069,7 +1051,7 @@ void QueryDbMainLoop( case IpcId::TextDocumentReferences: { auto msg = static_cast(message.get()); - QueryableFile* file = FindFile(db, msg->params.textDocument.uri.GetPath()); + QueryFile* file = FindFile(db, msg->params.textDocument.uri.GetPath()); if (!file) { std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl; break; @@ -1079,16 +1061,16 @@ void QueryDbMainLoop( response.id = msg->id; for (const SymbolRef& ref : FindSymbolsAtLocation(file, msg->params.position)) { - optional excluded_declaration; + optional excluded_declaration; if (!msg->params.context.includeDeclaration) { std::cerr << "Excluding declaration in references" << std::endl; excluded_declaration = GetDefinitionSpellingOfSymbol(db, ref.idx); } // Found symbol. Return references. - std::vector uses = GetUsesOfSymbol(db, ref.idx); + std::vector uses = GetUsesOfSymbol(db, ref.idx); response.result.reserve(uses.size()); - for (const QueryableLocation& use : uses) { + for (const QueryLocation& use : uses) { if (excluded_declaration.has_value() && use == *excluded_declaration) continue; @@ -1109,7 +1091,7 @@ void QueryDbMainLoop( Out_TextDocumentDocumentSymbol response; response.id = msg->id; - QueryableFile* file = FindFile(db, msg->params.textDocument.uri.GetPath()); + QueryFile* file = FindFile(db, msg->params.textDocument.uri.GetPath()); if (!file) { std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl; break; @@ -1137,7 +1119,7 @@ void QueryDbMainLoop( lsDocumentUri file_as_uri = msg->params.textDocument.uri; - QueryableFile* file = FindFile(db, file_as_uri.GetPath()); + QueryFile* file = FindFile(db, file_as_uri.GetPath()); if (!file) { std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl; break; @@ -1146,7 +1128,7 @@ void QueryDbMainLoop( common.result = &response.result; common.db = db; common.working_files = working_files; - common.working_file = working_files->GetFileByFilename(file->def.usr); + common.working_file = working_files->GetFileByFilename(file->def.path); for (SymbolRef ref : file->def.outline) { // NOTE: We OffsetColumn so that the code lens always show up in a @@ -1155,15 +1137,15 @@ void QueryDbMainLoop( SymbolIdx symbol = ref.idx; switch (symbol.kind) { case SymbolKind::Type: { - QueryableTypeDef& def = db->types[symbol.idx]; - AddCodeLens(&common, ref.loc.OffsetStartColumn(0), def.uses, "ref", "refs"); - AddCodeLens(&common, ref.loc.OffsetStartColumn(1), def.uses, "iref", "irefs", false /*exclude_loc*/, true /*only_interesting*/); - AddCodeLens(&common, ref.loc.OffsetStartColumn(2), ToQueryableLocation(db, def.derived), "derived", "derived"); - AddCodeLens(&common, ref.loc.OffsetStartColumn(3), ToQueryableLocation(db, def.instantiations), "instantiation", "instantiations"); + QueryType& type = db->types[symbol.idx]; + AddCodeLens(&common, ref.loc.OffsetStartColumn(0), type.uses, "ref", "refs"); + AddCodeLens(&common, ref.loc.OffsetStartColumn(1), type.uses, "iref", "irefs", false /*exclude_loc*/, true /*only_interesting*/); + AddCodeLens(&common, ref.loc.OffsetStartColumn(2), ToQueryLocation(db, type.derived), "derived", "derived"); + AddCodeLens(&common, ref.loc.OffsetStartColumn(3), ToQueryLocation(db, type.instantiations), "instantiation", "instantiations"); break; } case SymbolKind::Func: { - QueryableFuncDef& func = db->funcs[symbol.idx]; + QueryFunc& func = db->funcs[symbol.idx]; int offset = 0; @@ -1172,20 +1154,20 @@ void QueryDbMainLoop( std::vector derived_callers = GetCallersForAllDerivedFunctions(db, func); if (base_callers.empty() && derived_callers.empty()) { // set exclude_loc to true to force the code lens to show up - AddCodeLens(&common, ref.loc.OffsetStartColumn(offset++), ToQueryableLocation(db, func.callers), "call", "calls", true /*exclude_loc*/); + AddCodeLens(&common, ref.loc.OffsetStartColumn(offset++), ToQueryLocation(db, func.callers), "call", "calls", true /*exclude_loc*/); } else { - AddCodeLens(&common, ref.loc.OffsetStartColumn(offset++), ToQueryableLocation(db, func.callers), "direct call", "direct calls"); + AddCodeLens(&common, ref.loc.OffsetStartColumn(offset++), ToQueryLocation(db, func.callers), "direct call", "direct calls"); if (!base_callers.empty()) - AddCodeLens(&common, ref.loc.OffsetStartColumn(offset++), ToQueryableLocation(db, base_callers), "base call", "base calls"); + AddCodeLens(&common, ref.loc.OffsetStartColumn(offset++), ToQueryLocation(db, base_callers), "base call", "base calls"); if (!derived_callers.empty()) - AddCodeLens(&common, ref.loc.OffsetStartColumn(offset++), ToQueryableLocation(db, derived_callers), "derived call", "derived calls"); + AddCodeLens(&common, ref.loc.OffsetStartColumn(offset++), ToQueryLocation(db, derived_callers), "derived call", "derived calls"); } - AddCodeLens(&common, ref.loc.OffsetStartColumn(offset++), ToQueryableLocation(db, func.derived), "derived", "derived"); + AddCodeLens(&common, ref.loc.OffsetStartColumn(offset++), ToQueryLocation(db, func.derived), "derived", "derived"); // "Base" - optional base_loc = GetBaseDefinitionOrDeclarationSpelling(db, func); + optional base_loc = GetBaseDefinitionOrDeclarationSpelling(db, func); if (base_loc) { optional ls_base = GetLsLocation(db, working_files, *base_loc); if (ls_base) { @@ -1207,8 +1189,8 @@ void QueryDbMainLoop( break; } case SymbolKind::Var: { - QueryableVarDef& def = db->vars[symbol.idx]; - AddCodeLens(&common, ref.loc.OffsetStartColumn(0), def.uses, "ref", "refs", true /*exclude_loc*/, false /*only_interesting*/); + QueryVar& var = db->vars[symbol.idx]; + AddCodeLens(&common, ref.loc.OffsetStartColumn(0), var.uses, "ref", "refs", true /*exclude_loc*/, false /*only_interesting*/); break; } case SymbolKind::File: @@ -1242,7 +1224,7 @@ void QueryDbMainLoop( if (db->detailed_names[i].find(query) != std::string::npos) { lsSymbolInformation info = GetSymbolInfo(db, working_files, db->symbols[i]); - optional location = GetDefinitionExtentOfSymbol(db, db->symbols[i]); + optional location = GetDefinitionExtentOfSymbol(db, db->symbols[i]); if (!location) { auto decls = GetDeclarationsOfSymbolForGotoDefinition(db, db->symbols[i]); if (decls.empty()) @@ -1330,7 +1312,7 @@ void QueryDbMain() { } // Run query db main loop. - QueryableDatabase db; + QueryDatabase db; while (true) { QueryDbMainLoop(&db, ipc.get(), &queue_do_index, &queue_do_id_map, &queue_on_id_mapped, &queue_on_indexed, &project, &working_files, &completion_manager); std::this_thread::sleep_for(std::chrono::milliseconds(10)); diff --git a/src/query.cc b/src/query.cc index c9d1c567..0998d574 100644 --- a/src/query.cc +++ b/src/query.cc @@ -16,9 +16,9 @@ namespace { -QueryableTypeDef::DefUpdate ToQuery(const IdMap& id_map, const IndexedTypeDef::Def& type) { +QueryType::DefUpdate ToQuery(const IdMap& id_map, const IndexedTypeDef::Def& type) { assert(!type.short_name.empty()); - QueryableTypeDef::DefUpdate result(type.usr); + QueryType::DefUpdate result(type.usr); result.short_name = type.short_name; result.detailed_name = type.detailed_name; result.definition_spelling = id_map.ToQuery(type.definition_spelling); @@ -31,9 +31,9 @@ QueryableTypeDef::DefUpdate ToQuery(const IdMap& id_map, const IndexedTypeDef::D return result; } -QueryableFuncDef::DefUpdate ToQuery(const IdMap& id_map, const IndexedFuncDef::Def& func) { +QueryFunc::DefUpdate ToQuery(const IdMap& id_map, const IndexedFuncDef::Def& func) { assert(!func.short_name.empty()); - QueryableFuncDef::DefUpdate result(func.usr); + QueryFunc::DefUpdate result(func.usr); result.short_name = func.short_name; result.detailed_name = func.detailed_name; result.definition_spelling = id_map.ToQuery(func.definition_spelling); @@ -45,9 +45,9 @@ QueryableFuncDef::DefUpdate ToQuery(const IdMap& id_map, const IndexedFuncDef::D return result; } -QueryableVarDef::DefUpdate ToQuery(const IdMap& id_map, const IndexedVarDef::Def& var) { +QueryVar::DefUpdate ToQuery(const IdMap& id_map, const IndexedVarDef::Def& var) { assert(!var.short_name.empty()); - QueryableVarDef::DefUpdate result(var.usr); + QueryVar::DefUpdate result(var.usr); result.short_name = var.short_name; result.detailed_name = var.detailed_name; result.declaration = id_map.ToQuery(var.declaration); @@ -71,9 +71,9 @@ QueryableVarDef::DefUpdate ToQuery(const IdMap& id_map, const IndexedVarDef::Def -QueryableFile::Def BuildFileDef(const IdMap& id_map, const IndexedFile& indexed) { - QueryableFile::Def def; - def.usr = indexed.path; +QueryFile::Def BuildFileDef(const IdMap& id_map, const IndexedFile& indexed) { + QueryFile::Def def; + def.path = indexed.path; auto add_outline = [&def, &id_map](SymbolIdx idx, Range range) { def.outline.push_back(SymbolRef(idx, id_map.ToQuery(range))); @@ -134,19 +134,19 @@ QueryableFile::Def BuildFileDef(const IdMap& id_map, const IndexedFile& indexed) -QueryableFile* SymbolIdx::ResolveFile(QueryableDatabase* db) const { +QueryFile* SymbolIdx::ResolveFile(QueryDatabase* db) const { assert(kind == SymbolKind::File); return &db->files[idx]; } -QueryableTypeDef* SymbolIdx::ResolveType(QueryableDatabase* db) const { +QueryType* SymbolIdx::ResolveType(QueryDatabase* db) const { assert(kind == SymbolKind::Type); return &db->types[idx]; } -QueryableFuncDef* SymbolIdx::ResolveFunc(QueryableDatabase* db) const { +QueryFunc* SymbolIdx::ResolveFunc(QueryDatabase* db) const { assert(kind == SymbolKind::Func); return &db->funcs[idx]; } -QueryableVarDef* SymbolIdx::ResolveVar(QueryableDatabase* db) const { +QueryVar* SymbolIdx::ResolveVar(QueryDatabase* db) const { assert(kind == SymbolKind::Var); return &db->vars[idx]; } @@ -263,20 +263,20 @@ void CompareGroups( // TODO: consider having separate lookup maps so they are smaller (maybe // lookups will go faster). // TODO: Figure out where the invalid SymbolKinds are coming from. -QueryFileId GetQueryFileIdFromUsr(QueryableDatabase* query_db, const Usr& usr) { - auto it = query_db->usr_to_symbol.find(usr); +QueryFileId GetQueryFileIdFromPath(QueryDatabase* query_db, const std::string& path) { + auto it = query_db->usr_to_symbol.find(path); if (it != query_db->usr_to_symbol.end() && it->second.kind != SymbolKind::Invalid) { assert(it->second.kind == SymbolKind::File); return QueryFileId(it->second.idx); } size_t idx = query_db->files.size(); - query_db->usr_to_symbol[usr] = SymbolIdx(SymbolKind::File, idx); - query_db->files.push_back(QueryableFile(usr)); + query_db->usr_to_symbol[path] = SymbolIdx(SymbolKind::File, idx); + query_db->files.push_back(QueryFile(path)); return QueryFileId(idx); } -QueryTypeId GetQueryTypeIdFromUsr(QueryableDatabase* query_db, const Usr& usr) { +QueryTypeId GetQueryTypeIdFromUsr(QueryDatabase* query_db, const Usr& usr) { auto it = query_db->usr_to_symbol.find(usr); if (it != query_db->usr_to_symbol.end() && it->second.kind != SymbolKind::Invalid) { assert(it->second.kind == SymbolKind::Type); @@ -285,11 +285,11 @@ QueryTypeId GetQueryTypeIdFromUsr(QueryableDatabase* query_db, const Usr& usr) { size_t idx = query_db->types.size(); query_db->usr_to_symbol[usr] = SymbolIdx(SymbolKind::Type, idx); - query_db->types.push_back(QueryableTypeDef(usr)); + query_db->types.push_back(QueryType(usr)); return QueryTypeId(idx); } -QueryFuncId GetQueryFuncIdFromUsr(QueryableDatabase* query_db, const Usr& usr) { +QueryFuncId GetQueryFuncIdFromUsr(QueryDatabase* query_db, const Usr& usr) { auto it = query_db->usr_to_symbol.find(usr); if (it != query_db->usr_to_symbol.end() && it->second.kind != SymbolKind::Invalid) { assert(it->second.kind == SymbolKind::Func); @@ -298,11 +298,11 @@ QueryFuncId GetQueryFuncIdFromUsr(QueryableDatabase* query_db, const Usr& usr) { size_t idx = query_db->funcs.size(); query_db->usr_to_symbol[usr] = SymbolIdx(SymbolKind::Func, idx); - query_db->funcs.push_back(QueryableFuncDef(usr)); + query_db->funcs.push_back(QueryFunc(usr)); return QueryFuncId(idx); } -QueryVarId GetQueryVarIdFromUsr(QueryableDatabase* query_db, const Usr& usr) { +QueryVarId GetQueryVarIdFromUsr(QueryDatabase* query_db, const Usr& usr) { auto it = query_db->usr_to_symbol.find(usr); if (it != query_db->usr_to_symbol.end() && it->second.kind != SymbolKind::Invalid) { assert(it->second.kind == SymbolKind::Var); @@ -311,13 +311,13 @@ QueryVarId GetQueryVarIdFromUsr(QueryableDatabase* query_db, const Usr& usr) { size_t idx = query_db->vars.size(); query_db->usr_to_symbol[usr] = SymbolIdx(SymbolKind::Var, idx); - query_db->vars.push_back(QueryableVarDef(usr)); + query_db->vars.push_back(QueryVar(usr)); return QueryVarId(idx); } -IdMap::IdMap(QueryableDatabase* query_db, const IdCache& local_ids) +IdMap::IdMap(QueryDatabase* query_db, const IdCache& local_ids) : local_ids(local_ids) { - primary_file = GetQueryFileIdFromUsr(query_db, local_ids.primary_file); + primary_file = GetQueryFileIdFromPath(query_db, local_ids.primary_file); cached_type_ids_.set_empty_key(-1); cached_type_ids_.resize(local_ids.type_id_to_usr.size()); @@ -335,8 +335,8 @@ IdMap::IdMap(QueryableDatabase* query_db, const IdCache& local_ids) cached_var_ids_[entry.first.id] = GetQueryVarIdFromUsr(query_db, entry.second).id; } -QueryableLocation IdMap::ToQuery(Range range) const { - return QueryableLocation(primary_file, range); +QueryLocation IdMap::ToQuery(Range range) const { + return QueryLocation(primary_file, range); } QueryTypeId IdMap::ToQuery(IndexTypeId id) const { @@ -356,7 +356,7 @@ QueryFuncRef IdMap::ToQuery(IndexFuncRef ref) const { return QueryFuncRef(ToQuery(ref.id_), ToQuery(ref.loc)); } -optional IdMap::ToQuery(optional range) const { +optional IdMap::ToQuery(optional range) const { if (!range) return nullopt; return ToQuery(range.value()); @@ -390,8 +390,8 @@ std::vector ToQueryTransform(const IdMap& id_map, const std::vector& in result.push_back(id_map.ToQuery(in)); return result; } -std::vector IdMap::ToQuery(std::vector ranges) const { - return ToQueryTransform(*this, ranges); +std::vector IdMap::ToQuery(std::vector ranges) const { + return ToQueryTransform(*this, ranges); } std::vector IdMap::ToQuery(std::vector ids) const { return ToQueryTransform(*this, ids); @@ -472,21 +472,21 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, const IdMap& current_id_m if (!type->def.short_name.empty()) types_def_update.push_back(ToQuery(current_id_map, type->def)); if (!type->derived.empty()) - types_derived.push_back(QueryableTypeDef::DerivedUpdate(current_id_map.ToQuery(type->id), current_id_map.ToQuery(type->derived))); + types_derived.push_back(QueryType::DerivedUpdate(current_id_map.ToQuery(type->id), current_id_map.ToQuery(type->derived))); if (!type->instantiations.empty()) - types_instantiations.push_back(QueryableTypeDef::InstantiationsUpdate(current_id_map.ToQuery(type->id), current_id_map.ToQuery(type->instantiations))); + types_instantiations.push_back(QueryType::InstantiationsUpdate(current_id_map.ToQuery(type->id), current_id_map.ToQuery(type->instantiations))); if (!type->uses.empty()) - types_uses.push_back(QueryableTypeDef::UsesUpdate(current_id_map.ToQuery(type->id), current_id_map.ToQuery(type->uses))); + types_uses.push_back(QueryType::UsesUpdate(current_id_map.ToQuery(type->id), current_id_map.ToQuery(type->uses))); }, /*onFound:*/[this, &previous_id_map, ¤t_id_map](IndexedTypeDef* previous_def, IndexedTypeDef* current_def) { - optional previous_remapped_def = ToQuery(previous_id_map, previous_def->def); - optional current_remapped_def = ToQuery(current_id_map, current_def->def); + optional previous_remapped_def = ToQuery(previous_id_map, previous_def->def); + optional current_remapped_def = ToQuery(current_id_map, current_def->def); if (current_remapped_def && previous_remapped_def != current_remapped_def) types_def_update.push_back(*current_remapped_def); PROCESS_UPDATE_DIFF(QueryTypeId, types_derived, derived, QueryTypeId); PROCESS_UPDATE_DIFF(QueryTypeId, types_instantiations, instantiations, QueryVarId); - PROCESS_UPDATE_DIFF(QueryTypeId, types_uses, uses, QueryableLocation); + PROCESS_UPDATE_DIFF(QueryTypeId, types_uses, uses, QueryLocation); }); // Functions @@ -498,19 +498,19 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, const IdMap& current_id_m if (!func->def.short_name.empty()) funcs_def_update.push_back(ToQuery(current_id_map, func->def)); if (!func->declarations.empty()) - funcs_declarations.push_back(QueryableFuncDef::DeclarationsUpdate(current_id_map.ToQuery(func->id), current_id_map.ToQuery(func->declarations))); + funcs_declarations.push_back(QueryFunc::DeclarationsUpdate(current_id_map.ToQuery(func->id), current_id_map.ToQuery(func->declarations))); if (!func->derived.empty()) - funcs_derived.push_back(QueryableFuncDef::DerivedUpdate(current_id_map.ToQuery(func->id), current_id_map.ToQuery(func->derived))); + funcs_derived.push_back(QueryFunc::DerivedUpdate(current_id_map.ToQuery(func->id), current_id_map.ToQuery(func->derived))); if (!func->callers.empty()) - funcs_callers.push_back(QueryableFuncDef::CallersUpdate(current_id_map.ToQuery(func->id), current_id_map.ToQuery(func->callers))); + funcs_callers.push_back(QueryFunc::CallersUpdate(current_id_map.ToQuery(func->id), current_id_map.ToQuery(func->callers))); }, /*onFound:*/[this, &previous_id_map, ¤t_id_map](IndexedFuncDef* previous_def, IndexedFuncDef* current_def) { - optional previous_remapped_def = ToQuery(previous_id_map, previous_def->def); - optional current_remapped_def = ToQuery(current_id_map, current_def->def); + optional previous_remapped_def = ToQuery(previous_id_map, previous_def->def); + optional current_remapped_def = ToQuery(current_id_map, current_def->def); if (current_remapped_def && previous_remapped_def != current_remapped_def) funcs_def_update.push_back(*current_remapped_def); - PROCESS_UPDATE_DIFF(QueryFuncId, funcs_declarations, declarations, QueryableLocation); + PROCESS_UPDATE_DIFF(QueryFuncId, funcs_declarations, declarations, QueryLocation); PROCESS_UPDATE_DIFF(QueryFuncId, funcs_derived, derived, QueryFuncId); PROCESS_UPDATE_DIFF(QueryFuncId, funcs_callers, callers, QueryFuncRef); }); @@ -524,15 +524,15 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, const IdMap& current_id_m if (!var->def.short_name.empty()) vars_def_update.push_back(ToQuery(current_id_map, var->def)); if (!var->uses.empty()) - vars_uses.push_back(QueryableVarDef::UsesUpdate(current_id_map.ToQuery(var->id), current_id_map.ToQuery(var->uses))); + vars_uses.push_back(QueryVar::UsesUpdate(current_id_map.ToQuery(var->id), current_id_map.ToQuery(var->uses))); }, /*onFound:*/[this, &previous_id_map, ¤t_id_map](IndexedVarDef* previous_def, IndexedVarDef* current_def) { - optional previous_remapped_def = ToQuery(previous_id_map, previous_def->def); - optional current_remapped_def = ToQuery(current_id_map, current_def->def); + optional previous_remapped_def = ToQuery(previous_id_map, previous_def->def); + optional current_remapped_def = ToQuery(current_id_map, current_def->def); if (current_remapped_def && previous_remapped_def != current_remapped_def) vars_def_update.push_back(*current_remapped_def); - PROCESS_UPDATE_DIFF(QueryVarId, vars_uses, uses, QueryableLocation); + PROCESS_UPDATE_DIFF(QueryVarId, vars_uses, uses, QueryLocation); }); #undef PROCESS_UPDATE_DIFF @@ -588,7 +588,7 @@ void IndexUpdate::Merge(const IndexUpdate& update) { -void SetDetailedNameForWorkspaceSearch(QueryableDatabase* db, size_t* qualified_name_index, SymbolKind kind, size_t symbol_index, const std::string& name) { +void SetDetailedNameForWorkspaceSearch(QueryDatabase* db, size_t* qualified_name_index, SymbolKind kind, size_t symbol_index, const std::string& name) { if (*qualified_name_index == -1) { db->detailed_names.push_back(name); db->symbols.push_back(SymbolIdx(kind, symbol_index)); @@ -602,7 +602,7 @@ void SetDetailedNameForWorkspaceSearch(QueryableDatabase* db, size_t* qualified_ -void QueryableDatabase::RemoveUsrs(const std::vector& to_remove) { +void QueryDatabase::RemoveUsrs(const std::vector& to_remove) { // TODO: Removing usrs is tricky because it means we will have to rebuild idx locations. I'm thinking we just nullify // the entry instead of actually removing the data. The index could be massive. for (Usr usr : to_remove) @@ -610,18 +610,18 @@ void QueryableDatabase::RemoveUsrs(const std::vector& to_remove) { // TODO: also remove from qualified_names? } -void QueryableDatabase::ImportOrUpdate(const std::vector& updates) { +void QueryDatabase::ImportOrUpdate(const std::vector& updates) { for (auto& def : updates) { - auto it = usr_to_symbol.find(def.usr); + auto it = usr_to_symbol.find(def.path); assert(it != usr_to_symbol.end()); - QueryableFile& existing = files[it->second.idx]; + QueryFile& existing = files[it->second.idx]; existing.def = def; //SetQualifiedNameForWorkspaceSearch(this, &existing.qualified_name_idx, SymbolKind::File, it->second.idx, def.qualified_name); } } -void QueryableDatabase::ImportOrUpdate(const std::vector& updates) { +void QueryDatabase::ImportOrUpdate(const std::vector& updates) { for (auto& def : updates) { if (def.detailed_name.empty()) continue; @@ -629,7 +629,7 @@ void QueryableDatabase::ImportOrUpdate(const std::vectorsecond.idx]; + QueryType& existing = types[it->second.idx]; if (existing.def.definition_spelling && !def.definition_spelling) continue; @@ -638,7 +638,7 @@ void QueryableDatabase::ImportOrUpdate(const std::vector& updates) { +void QueryDatabase::ImportOrUpdate(const std::vector& updates) { for (auto& def : updates) { if (def.detailed_name.empty()) continue; @@ -646,7 +646,7 @@ void QueryableDatabase::ImportOrUpdate(const std::vectorsecond.idx]; + QueryFunc& existing = funcs[it->second.idx]; if (existing.def.definition_spelling && !def.definition_spelling) continue; @@ -655,7 +655,7 @@ void QueryableDatabase::ImportOrUpdate(const std::vector& updates) { +void QueryDatabase::ImportOrUpdate(const std::vector& updates) { for (auto& def : updates) { if (def.detailed_name.empty()) continue; @@ -663,7 +663,7 @@ void QueryableDatabase::ImportOrUpdate(const std::vectorsecond.idx]; + QueryVar& existing = vars[it->second.idx]; if (existing.def.definition_spelling && !def.definition_spelling) continue; @@ -673,7 +673,7 @@ void QueryableDatabase::ImportOrUpdate(const std::vectorupdate_var_name) { \ auto* def = &storage_name[merge_update.id.id]; \ diff --git a/src/query.h b/src/query.h index c28292bf..b2de1299 100644 --- a/src/query.h +++ b/src/query.h @@ -7,15 +7,16 @@ using Usr = std::string; -struct QueryableFile; -struct QueryableTypeDef; -struct QueryableFuncDef; -struct QueryableVarDef; +struct QueryFile; +struct QueryType; +struct QueryFunc; +struct QueryVar; +struct QueryDatabase; -using QueryFileId = Id; -using QueryTypeId = Id; -using QueryFuncId = Id; -using QueryVarId = Id; +using QueryFileId = Id; +using QueryTypeId = Id; +using QueryFuncId = Id; +using QueryVarId = Id; @@ -29,39 +30,33 @@ struct IdMap; // TODO: in types, store refs separately from irefs. Then we can drop // 'interesting' from location when that is cleaned up. -struct QueryableLocation { +struct QueryLocation { QueryFileId path; Range range; - QueryableLocation(QueryFileId path, Range range) + QueryLocation(QueryFileId path, Range range) : path(path), range(range) {} - QueryableLocation OffsetStartColumn(int offset) const { - QueryableLocation result = *this; + QueryLocation OffsetStartColumn(int offset) const { + QueryLocation result = *this; result.range.start.column += offset; return result; } - bool operator==(const QueryableLocation& other) const { + bool operator==(const QueryLocation& other) const { // Note: We ignore |is_interesting|. return path == other.path && range == other.range; } - bool operator!=(const QueryableLocation& other) const { return !(*this == other); } - bool operator<(const QueryableLocation& o) const { + bool operator!=(const QueryLocation& other) const { return !(*this == other); } + bool operator<(const QueryLocation& o) const { return path < o.path && range < o.range; } }; -struct QueryableFile; -struct QueryableTypeDef; -struct QueryableFuncDef; -struct QueryableVarDef; -struct QueryableDatabase; - enum class SymbolKind { Invalid, File, Type, Func, Var }; struct SymbolIdx { SymbolKind kind; @@ -78,17 +73,17 @@ struct SymbolIdx { return kind < that.kind || idx < that.idx; } - QueryableFile* ResolveFile(QueryableDatabase* db) const; - QueryableTypeDef* ResolveType(QueryableDatabase* db) const; - QueryableFuncDef* ResolveFunc(QueryableDatabase* db) const; - QueryableVarDef* ResolveVar(QueryableDatabase* db) const; + QueryFile* ResolveFile(QueryDatabase* db) const; + QueryType* ResolveType(QueryDatabase* db) const; + QueryFunc* ResolveFunc(QueryDatabase* db) const; + QueryVar* ResolveVar(QueryDatabase* db) const; }; struct SymbolRef { SymbolIdx idx; - QueryableLocation loc; + QueryLocation loc; - SymbolRef(SymbolIdx idx, QueryableLocation loc) : idx(idx), loc(loc) {} + SymbolRef(SymbolIdx idx, QueryLocation loc) : idx(idx), loc(loc) {} bool operator==(const SymbolRef& that) const { return idx == that.idx && loc == that.loc; @@ -109,9 +104,9 @@ struct QueryFuncRef { } QueryFuncId id_; - QueryableLocation loc; + QueryLocation loc; - QueryFuncRef(QueryFuncId id, QueryableLocation loc) : id_(id), loc(loc) {} + QueryFuncRef(QueryFuncId id, QueryLocation loc) : id_(id), loc(loc) {} bool operator==(const QueryFuncRef& that) const { return id_ == that.id_ && loc == that.loc; @@ -146,9 +141,9 @@ struct MergeableUpdate { : id(id), to_add(to_add), to_remove(to_remove) {} }; -struct QueryableFile { +struct QueryFile { struct Def { - Usr usr; + std::string path; // Outline of the file (ie, for code lens). std::vector outline; // Every symbol found in the file (ie, for goto definition) @@ -160,49 +155,49 @@ struct QueryableFile { DefUpdate def; size_t detailed_name_idx = -1; - QueryableFile(const Usr& usr) { def.usr = usr; } + QueryFile(const std::string& path) { def.path = path; } }; -struct QueryableTypeDef { - using DefUpdate = TypeDefDefinitionData; +struct QueryType { + using DefUpdate = TypeDefDefinitionData; using DerivedUpdate = MergeableUpdate; using InstantiationsUpdate = MergeableUpdate; - using UsesUpdate = MergeableUpdate; + using UsesUpdate = MergeableUpdate; DefUpdate def; std::vector derived; std::vector instantiations; - std::vector uses; + std::vector uses; size_t detailed_name_idx = -1; - QueryableTypeDef(const Usr& usr) : def(usr) {} + QueryType(const Usr& usr) : def(usr) {} }; -struct QueryableFuncDef { - using DefUpdate = FuncDefDefinitionData; - using DeclarationsUpdate = MergeableUpdate; +struct QueryFunc { + using DefUpdate = FuncDefDefinitionData; + using DeclarationsUpdate = MergeableUpdate; using DerivedUpdate = MergeableUpdate; using CallersUpdate = MergeableUpdate; DefUpdate def; - std::vector declarations; + std::vector declarations; std::vector derived; std::vector callers; size_t detailed_name_idx = -1; - QueryableFuncDef(const Usr& usr) : def(usr) {} - QueryableFuncDef(const DefUpdate& def) : def(def) {} + QueryFunc(const Usr& usr) : def(usr) {} + QueryFunc(const DefUpdate& def) : def(def) {} }; -struct QueryableVarDef { - using DefUpdate = VarDefDefinitionData; - using UsesUpdate = MergeableUpdate; +struct QueryVar { + using DefUpdate = VarDefDefinitionData; + using UsesUpdate = MergeableUpdate; DefUpdate def; - std::vector uses; + std::vector uses; size_t detailed_name_idx = -1; - QueryableVarDef(const Usr& usr) : def(usr) {} + QueryVar(const Usr& usr) : def(usr) {} }; struct IndexUpdate { @@ -216,26 +211,26 @@ struct IndexUpdate { // File updates. std::vector files_removed; - std::vector files_def_update; + std::vector files_def_update; // Type updates. std::vector types_removed; - std::vector types_def_update; - std::vector types_derived; - std::vector types_instantiations; - std::vector types_uses; + std::vector types_def_update; + std::vector types_derived; + std::vector types_instantiations; + std::vector types_uses; // Function updates. std::vector funcs_removed; - std::vector funcs_def_update; - std::vector funcs_declarations; - std::vector funcs_derived; - std::vector funcs_callers; + std::vector funcs_def_update; + std::vector funcs_declarations; + std::vector funcs_derived; + std::vector funcs_callers; // Variable updates. std::vector vars_removed; - std::vector vars_def_update; - std::vector vars_uses; + std::vector vars_def_update; + std::vector vars_uses; private: // Creates an index update assuming that |previous| is already @@ -247,22 +242,22 @@ struct IndexUpdate { // The query database is heavily optimized for fast queries. It is stored // in-memory. -struct QueryableDatabase { +struct QueryDatabase { // Indicies between lookup vectors are related to symbols, ie, index 5 in // |detailed_names| matches index 5 in |symbols|. std::vector detailed_names; std::vector symbols; // Raw data storage. - std::vector files; // File path is stored as a Usr. - std::vector types; - std::vector funcs; - std::vector vars; + std::vector files; // File path is stored as a Usr. + std::vector types; + std::vector funcs; + std::vector vars; // Lookup symbol based on a usr. google::dense_hash_map usr_to_symbol; - QueryableDatabase() { + QueryDatabase() { usr_to_symbol.set_empty_key(""); } //std::unordered_map usr_to_symbol; @@ -271,10 +266,10 @@ struct QueryableDatabase { void ApplyIndexUpdate(IndexUpdate* update); void RemoveUsrs(const std::vector& to_remove); - void ImportOrUpdate(const std::vector& updates); - void ImportOrUpdate(const std::vector& updates); - void ImportOrUpdate(const std::vector& updates); - void ImportOrUpdate(const std::vector& updates); + void ImportOrUpdate(const std::vector& updates); + void ImportOrUpdate(const std::vector& updates); + void ImportOrUpdate(const std::vector& updates); + void ImportOrUpdate(const std::vector& updates); }; @@ -291,19 +286,19 @@ struct IdMap { const IdCache& local_ids; QueryFileId primary_file; - IdMap(QueryableDatabase* query_db, const IdCache& local_ids); + IdMap(QueryDatabase* query_db, const IdCache& local_ids); - QueryableLocation ToQuery(Range range) const; + QueryLocation ToQuery(Range range) const; QueryTypeId ToQuery(IndexTypeId id) const; QueryFuncId ToQuery(IndexFuncId id) const; QueryVarId ToQuery(IndexVarId id) const; QueryFuncRef ToQuery(IndexFuncRef ref) const; - optional ToQuery(optional range) const; + optional ToQuery(optional range) const; optional ToQuery(optional id) const; optional ToQuery(optional id) const; optional ToQuery(optional id) const; optional ToQuery(optional ref) const; - std::vector ToQuery(std::vector ranges) const; + std::vector ToQuery(std::vector ranges) const; std::vector ToQuery(std::vector ids) const; std::vector ToQuery(std::vector ids) const; std::vector ToQuery(std::vector ids) const;