Tons of renames (generally, Queryable -> Query, QueryableTypeDef -> QueryType, QueryableFuncDef -> QueryFunc, QueryableVarDef -> QueryVar)

This commit is contained in:
Jacob Dufault 2017-04-14 22:41:35 -07:00
parent 4135186ae2
commit 5109d27b87
3 changed files with 233 additions and 256 deletions

View File

@ -44,7 +44,7 @@ void PushBack(NonElidedVector<lsLocation>* result, optional<lsLocation> location
result->push_back(*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); auto it = db->usr_to_symbol.find(filename);
if (it != db->usr_to_symbol.end()) { if (it != db->usr_to_symbol.end()) {
*file_id = QueryFileId(it->second.idx); *file_id = QueryFileId(it->second.idx);
@ -56,7 +56,7 @@ QueryableFile* FindFile(QueryableDatabase* db, const std::string& filename, Quer
return nullptr; 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. // TODO: consider calling NormalizePath here. It might add too much latency though.
auto it = db->usr_to_symbol.find(filename); auto it = db->usr_to_symbol.find(filename);
if (it != db->usr_to_symbol.end()) if (it != db->usr_to_symbol.end())
@ -66,50 +66,32 @@ QueryableFile* FindFile(QueryableDatabase* db, const std::string& filename) {
return nullptr; return nullptr;
} }
QueryableFile* GetQueryable(QueryableDatabase* db, const QueryFileId& id) { QueryFile* GetQuery(QueryDatabase* db, const QueryFileId& id) {
return &db->files[id.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]; return &db->types[id.id];
} }
QueryableFuncDef* GetQueryable(QueryableDatabase* db, const QueryFuncId& id) { QueryFunc* GetQuery(QueryDatabase* db, const QueryFuncId& id) {
return &db->funcs[id.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]; return &db->vars[id.id];
} }
#if false
optional<QueryableLocation> 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<QueryableLocation> GetDefinitionSpellingOfSymbol(QueryableDatabase* db, const QueryTypeId& id) { optional<QueryLocation> GetDefinitionSpellingOfSymbol(QueryDatabase* db, const QueryTypeId& id) {
return GetQueryable(db, id)->def.definition_spelling; return GetQuery(db, id)->def.definition_spelling;
} }
optional<QueryableLocation> GetDefinitionSpellingOfSymbol(QueryableDatabase* db, const QueryFuncId& id) { optional<QueryLocation> GetDefinitionSpellingOfSymbol(QueryDatabase* db, const QueryFuncId& id) {
return GetQueryable(db, id)->def.definition_spelling; return GetQuery(db, id)->def.definition_spelling;
} }
optional<QueryableLocation> GetDefinitionSpellingOfSymbol(QueryableDatabase* db, const QueryVarId& id) { optional<QueryLocation> GetDefinitionSpellingOfSymbol(QueryDatabase* db, const QueryVarId& id) {
return GetQueryable(db, id)->def.definition_spelling; return GetQuery(db, id)->def.definition_spelling;
} }
optional<QueryableLocation> GetDefinitionSpellingOfSymbol(QueryableDatabase* db, const SymbolIdx& symbol) { optional<QueryLocation> GetDefinitionSpellingOfSymbol(QueryDatabase* db, const SymbolIdx& symbol) {
switch (symbol.kind) { switch (symbol.kind) {
case SymbolKind::Type: case SymbolKind::Type:
return db->types[symbol.idx].def.definition_spelling; return db->types[symbol.idx].def.definition_spelling;
@ -127,7 +109,7 @@ optional<QueryableLocation> GetDefinitionSpellingOfSymbol(QueryableDatabase* db,
} }
std::string GetHoverForSymbol(QueryableDatabase* db, const SymbolIdx& symbol) { std::string GetHoverForSymbol(QueryDatabase* db, const SymbolIdx& symbol) {
switch (symbol.kind) { switch (symbol.kind) {
case SymbolKind::Type: case SymbolKind::Type:
return db->types[symbol.idx].def.detailed_name; return db->types[symbol.idx].def.detailed_name;
@ -144,38 +126,38 @@ std::string GetHoverForSymbol(QueryableDatabase* db, const SymbolIdx& symbol) {
return ""; return "";
} }
std::vector<QueryableLocation> ToQueryableLocation(QueryableDatabase* db, const std::vector<QueryFuncRef>& refs) { std::vector<QueryLocation> ToQueryLocation(QueryDatabase* db, const std::vector<QueryFuncRef>& refs) {
std::vector<QueryableLocation> locs; std::vector<QueryLocation> locs;
locs.reserve(refs.size()); locs.reserve(refs.size());
for (const QueryFuncRef& ref : refs) for (const QueryFuncRef& ref : refs)
locs.push_back(ref.loc); locs.push_back(ref.loc);
return locs; return locs;
} }
std::vector<QueryableLocation> ToQueryableLocation(QueryableDatabase* db, const std::vector<QueryTypeId>& ids) { std::vector<QueryLocation> ToQueryLocation(QueryDatabase* db, const std::vector<QueryTypeId>& ids) {
std::vector<QueryableLocation> locs; std::vector<QueryLocation> locs;
locs.reserve(ids.size()); locs.reserve(ids.size());
for (const QueryTypeId& id : ids) { for (const QueryTypeId& id : ids) {
optional<QueryableLocation> loc = GetDefinitionSpellingOfSymbol(db, id); optional<QueryLocation> loc = GetDefinitionSpellingOfSymbol(db, id);
if (loc) if (loc)
locs.push_back(loc.value()); locs.push_back(loc.value());
} }
return locs; return locs;
} }
std::vector<QueryableLocation> ToQueryableLocation(QueryableDatabase* db, const std::vector<QueryFuncId>& ids) { std::vector<QueryLocation> ToQueryLocation(QueryDatabase* db, const std::vector<QueryFuncId>& ids) {
std::vector<QueryableLocation> locs; std::vector<QueryLocation> locs;
locs.reserve(ids.size()); locs.reserve(ids.size());
for (const QueryFuncId& id : ids) { for (const QueryFuncId& id : ids) {
optional<QueryableLocation> loc = GetDefinitionSpellingOfSymbol(db, id); optional<QueryLocation> loc = GetDefinitionSpellingOfSymbol(db, id);
if (loc) if (loc)
locs.push_back(loc.value()); locs.push_back(loc.value());
} }
return locs; return locs;
} }
std::vector<QueryableLocation> ToQueryableLocation(QueryableDatabase* db, const std::vector<QueryVarId>& ids) { std::vector<QueryLocation> ToQueryLocation(QueryDatabase* db, const std::vector<QueryVarId>& ids) {
std::vector<QueryableLocation> locs; std::vector<QueryLocation> locs;
locs.reserve(ids.size()); locs.reserve(ids.size());
for (const QueryVarId& id : ids) { for (const QueryVarId& id : ids) {
optional<QueryableLocation> loc = GetDefinitionSpellingOfSymbol(db, id); optional<QueryLocation> loc = GetDefinitionSpellingOfSymbol(db, id);
if (loc) if (loc)
locs.push_back(loc.value()); locs.push_back(loc.value());
} }
@ -184,14 +166,14 @@ std::vector<QueryableLocation> ToQueryableLocation(QueryableDatabase* db, const
std::vector<QueryableLocation> GetUsesOfSymbol(QueryableDatabase* db, const SymbolIdx& symbol) { std::vector<QueryLocation> GetUsesOfSymbol(QueryDatabase* db, const SymbolIdx& symbol) {
switch (symbol.kind) { switch (symbol.kind) {
case SymbolKind::Type: case SymbolKind::Type:
return db->types[symbol.idx].uses; return db->types[symbol.idx].uses;
case SymbolKind::Func: { case SymbolKind::Func: {
// TODO: the vector allocation could be avoided. // TODO: the vector allocation could be avoided.
const QueryableFuncDef& func = db->funcs[symbol.idx]; const QueryFunc& func = db->funcs[symbol.idx];
std::vector<QueryableLocation> result = ToQueryableLocation(db, func.callers); std::vector<QueryLocation> result = ToQueryLocation(db, func.callers);
AddRange(&result, func.declarations); AddRange(&result, func.declarations);
if (func.def.definition_spelling) if (func.def.definition_spelling)
result.push_back(*func.def.definition_spelling); result.push_back(*func.def.definition_spelling);
@ -208,20 +190,20 @@ std::vector<QueryableLocation> GetUsesOfSymbol(QueryableDatabase* db, const Symb
return {}; return {};
} }
optional<QueryableLocation> GetDefinitionExtentOfSymbol(QueryableDatabase* db, const QueryTypeId& id) { optional<QueryLocation> GetDefinitionExtentOfSymbol(QueryDatabase* db, const QueryTypeId& id) {
return GetQueryable(db, id)->def.definition_extent; return GetQuery(db, id)->def.definition_extent;
} }
optional<QueryableLocation> GetDefinitionExtentOfSymbol(QueryableDatabase* db, const QueryFuncId& id) { optional<QueryLocation> GetDefinitionExtentOfSymbol(QueryDatabase* db, const QueryFuncId& id) {
return GetQueryable(db, id)->def.definition_extent; return GetQuery(db, id)->def.definition_extent;
} }
optional<QueryableLocation> GetDefinitionExtentOfSymbol(QueryableDatabase* db, const QueryVarId& id) { optional<QueryLocation> GetDefinitionExtentOfSymbol(QueryDatabase* db, const QueryVarId& id) {
return GetQueryable(db, id)->def.definition_extent; return GetQuery(db, id)->def.definition_extent;
} }
optional<QueryableLocation> GetDefinitionExtentOfSymbol(QueryableDatabase* db, const SymbolIdx& symbol) { optional<QueryLocation> GetDefinitionExtentOfSymbol(QueryDatabase* db, const SymbolIdx& symbol) {
switch (symbol.kind) { switch (symbol.kind) {
case SymbolKind::File: case SymbolKind::File:
// TODO: If line 1 is deleted the file won't show up in, ie, workspace symbol search results. // 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: case SymbolKind::Type:
return db->types[symbol.idx].def.definition_extent; return db->types[symbol.idx].def.definition_extent;
case SymbolKind::Func: case SymbolKind::Func:
@ -236,14 +218,14 @@ optional<QueryableLocation> GetDefinitionExtentOfSymbol(QueryableDatabase* db, c
return nullopt; return nullopt;
} }
std::vector<QueryableLocation> GetDeclarationsOfSymbolForGotoDefinition(QueryableDatabase* db, const SymbolIdx& symbol) { std::vector<QueryLocation> GetDeclarationsOfSymbolForGotoDefinition(QueryDatabase* db, const SymbolIdx& symbol) {
switch (symbol.kind) { switch (symbol.kind) {
case SymbolKind::Type: { case SymbolKind::Type: {
// Returning the definition spelling of a type is a hack (and is why the // Returning the definition spelling of a type is a hack (and is why the
// function has the postfix `ForGotoDefintion`, but it lets the user // function has the postfix `ForGotoDefintion`, but it lets the user
// jump to the start of a type if clicking goto-definition on the same // jump to the start of a type if clicking goto-definition on the same
// type from within the type definition. // type from within the type definition.
optional<QueryableLocation> declaration = db->types[symbol.idx].def.definition_spelling; optional<QueryLocation> declaration = db->types[symbol.idx].def.definition_spelling;
if (declaration) if (declaration)
return { *declaration }; return { *declaration };
break; break;
@ -251,7 +233,7 @@ std::vector<QueryableLocation> GetDeclarationsOfSymbolForGotoDefinition(Queryabl
case SymbolKind::Func: case SymbolKind::Func:
return db->funcs[symbol.idx].declarations; return db->funcs[symbol.idx].declarations;
case SymbolKind::Var: { case SymbolKind::Var: {
optional<QueryableLocation> declaration = db->vars[symbol.idx].def.declaration; optional<QueryLocation> declaration = db->vars[symbol.idx].def.declaration;
if (declaration) if (declaration)
return { *declaration }; return { *declaration };
break; break;
@ -261,41 +243,41 @@ std::vector<QueryableLocation> GetDeclarationsOfSymbolForGotoDefinition(Queryabl
return {}; return {};
} }
optional<QueryableLocation> GetBaseDefinitionOrDeclarationSpelling(QueryableDatabase* db, QueryableFuncDef& func) { optional<QueryLocation> GetBaseDefinitionOrDeclarationSpelling(QueryDatabase* db, QueryFunc& func) {
if (!func.def.base) if (!func.def.base)
return nullopt; return nullopt;
QueryableFuncDef& base = db->funcs[func.def.base->id]; QueryFunc& base = db->funcs[func.def.base->id];
auto def = base.def.definition_spelling; auto def = base.def.definition_spelling;
if (!def && !base.declarations.empty()) if (!def && !base.declarations.empty())
def = base.declarations[0]; def = base.declarations[0];
return def; return def;
} }
std::vector<QueryFuncRef> GetCallersForAllBaseFunctions(QueryableDatabase* db, QueryableFuncDef& root) { std::vector<QueryFuncRef> GetCallersForAllBaseFunctions(QueryDatabase* db, QueryFunc& root) {
std::vector<QueryFuncRef> callers; std::vector<QueryFuncRef> callers;
optional<QueryFuncId> func_id = root.def.base; optional<QueryFuncId> func_id = root.def.base;
while (func_id) { while (func_id) {
QueryableFuncDef& def = db->funcs[func_id->id]; QueryFunc& func = db->funcs[func_id->id];
AddRange(&callers, def.callers); AddRange(&callers, func.callers);
func_id = def.def.base; func_id = func.def.base;
} }
return callers; return callers;
} }
std::vector<QueryFuncRef> GetCallersForAllDerivedFunctions(QueryableDatabase* db, QueryableFuncDef& root) { std::vector<QueryFuncRef> GetCallersForAllDerivedFunctions(QueryDatabase* db, QueryFunc& root) {
std::vector<QueryFuncRef> callers; std::vector<QueryFuncRef> callers;
std::queue<QueryFuncId> queue; std::queue<QueryFuncId> queue;
PushRange(&queue, root.derived); PushRange(&queue, root.derived);
while (!queue.empty()) { while (!queue.empty()) {
QueryableFuncDef& def = db->funcs[queue.front().id]; QueryFunc& func = db->funcs[queue.front().id];
queue.pop(); queue.pop();
PushRange(&queue, def.derived); PushRange(&queue, func.derived);
AddRange(&callers, def.callers); AddRange(&callers, func.callers);
} }
return callers; return callers;
@ -317,17 +299,17 @@ optional<lsRange> GetLsRange(WorkingFile* working_file, const Range& location) {
lsPosition(working_file->GetBufferLineFromDiskLine(location.end.line) - 1, location.end.column - 1)); lsPosition(working_file->GetBufferLineFromDiskLine(location.end.line) - 1, location.end.column - 1));
} }
lsDocumentUri GetLsDocumentUri(QueryableDatabase* db, QueryFileId file_id, std::string* path) { lsDocumentUri GetLsDocumentUri(QueryDatabase* db, QueryFileId file_id, std::string* path) {
*path = db->files[file_id.id].def.usr; *path = db->files[file_id.id].def.path;
return lsDocumentUri::FromPath(*path); return lsDocumentUri::FromPath(*path);
} }
lsDocumentUri GetLsDocumentUri(QueryableDatabase* db, QueryFileId file_id) { lsDocumentUri GetLsDocumentUri(QueryDatabase* db, QueryFileId file_id) {
std::string path = db->files[file_id.id].def.usr; std::string path = db->files[file_id.id].def.path;
return lsDocumentUri::FromPath(path); return lsDocumentUri::FromPath(path);
} }
optional<lsLocation> GetLsLocation(QueryableDatabase* db, WorkingFiles* working_files, const QueryableLocation& location) { optional<lsLocation> GetLsLocation(QueryDatabase* db, WorkingFiles* working_files, const QueryLocation& location) {
std::string path; std::string path;
lsDocumentUri uri = GetLsDocumentUri(db, location.path, &path); lsDocumentUri uri = GetLsDocumentUri(db, location.path, &path);
optional<lsRange> range = GetLsRange(working_files->GetFileByFilename(path), location.range); optional<lsRange> range = GetLsRange(working_files->GetFileByFilename(path), location.range);
@ -337,29 +319,29 @@ optional<lsLocation> GetLsLocation(QueryableDatabase* db, WorkingFiles* working_
} }
// Returns a symbol. The symbol will have *NOT* have a location assigned. // 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; lsSymbolInformation info;
switch (symbol.kind) { switch (symbol.kind) {
case SymbolKind::File: { case SymbolKind::File: {
QueryableFile* def = symbol.ResolveFile(db); QueryFile* file = symbol.ResolveFile(db);
info.name = def->def.usr; info.name = file->def.path;
info.kind = lsSymbolKind::File; info.kind = lsSymbolKind::File;
break; break;
} }
case SymbolKind::Type: { case SymbolKind::Type: {
QueryableTypeDef* def = symbol.ResolveType(db); QueryType* type = symbol.ResolveType(db);
info.name = def->def.detailed_name; info.name = type->def.detailed_name;
info.kind = lsSymbolKind::Class; info.kind = lsSymbolKind::Class;
break; break;
} }
case SymbolKind::Func: { case SymbolKind::Func: {
QueryableFuncDef* def = symbol.ResolveFunc(db); QueryFunc* func = symbol.ResolveFunc(db);
info.name = def->def.detailed_name; info.name = func->def.detailed_name;
if (def->def.declaring_type.has_value()) { if (func->def.declaring_type.has_value()) {
info.kind = lsSymbolKind::Method; 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 { else {
info.kind = lsSymbolKind::Function; info.kind = lsSymbolKind::Function;
@ -367,8 +349,8 @@ lsSymbolInformation GetSymbolInfo(QueryableDatabase* db, WorkingFiles* working_f
break; break;
} }
case SymbolKind::Var: { case SymbolKind::Var: {
QueryableVarDef* def = symbol.ResolveVar(db); QueryVar* var = symbol.ResolveVar(db);
info.name += def->def.detailed_name; info.name += var->def.detailed_name;
info.kind = lsSymbolKind::Variable; info.kind = lsSymbolKind::Variable;
break; break;
} }
@ -383,15 +365,15 @@ lsSymbolInformation GetSymbolInfo(QueryableDatabase* db, WorkingFiles* working_f
struct CommonCodeLensParams { struct CommonCodeLensParams {
std::vector<TCodeLens>* result; std::vector<TCodeLens>* result;
QueryableDatabase* db; QueryDatabase* db;
WorkingFiles* working_files; WorkingFiles* working_files;
WorkingFile* working_file; WorkingFile* working_file;
}; };
void AddCodeLens( void AddCodeLens(
CommonCodeLensParams* common, CommonCodeLensParams* common,
QueryableLocation loc, QueryLocation loc,
const std::vector<QueryableLocation>& uses, const std::vector<QueryLocation>& uses,
const char* singular, const char* singular,
const char* plural, const char* plural,
bool exclude_loc = false, bool exclude_loc = false,
@ -408,7 +390,7 @@ void AddCodeLens(
// Add unique uses. // Add unique uses.
std::unordered_set<lsLocation> unique_uses; std::unordered_set<lsLocation> unique_uses;
for (const QueryableLocation& use : uses) { for (const QueryLocation& use : uses) {
if (exclude_loc && use == loc) if (exclude_loc && use == loc)
continue; continue;
if (only_interesting && !use.range.interesting) if (only_interesting && !use.range.interesting)
@ -433,7 +415,7 @@ void AddCodeLens(
common->result->push_back(code_lens); common->result->push_back(code_lens);
} }
lsWorkspaceEdit BuildWorkspaceEdit(QueryableDatabase* db, WorkingFiles* working_files, const std::vector<QueryableLocation>& locations, const std::string& new_text) { lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db, WorkingFiles* working_files, const std::vector<QueryLocation>& locations, const std::string& new_text) {
std::unordered_map<QueryFileId, lsTextDocumentEdit> path_to_edit; std::unordered_map<QueryFileId, lsTextDocumentEdit> path_to_edit;
for (auto& location : locations) { 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()) { if (path_to_edit.find(location.path) == path_to_edit.end()) {
path_to_edit[location.path] = lsTextDocumentEdit(); 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); path_to_edit[location.path].textDocument.uri = lsDocumentUri::FromPath(path);
WorkingFile* working_file = working_files->GetFileByFilename(path); WorkingFile* working_file = working_files->GetFileByFilename(path);
@ -465,7 +447,7 @@ lsWorkspaceEdit BuildWorkspaceEdit(QueryableDatabase* db, WorkingFiles* working_
return edit; return edit;
} }
std::vector<SymbolRef> FindSymbolsAtLocation(QueryableFile* file, lsPosition position) { std::vector<SymbolRef> FindSymbolsAtLocation(QueryFile* file, lsPosition position) {
std::vector<SymbolRef> symbols; std::vector<SymbolRef> symbols;
symbols.reserve(1); symbols.reserve(1);
@ -815,7 +797,7 @@ void IndexMain(
void QueryDbMainLoop( void QueryDbMainLoop(
QueryableDatabase* db, QueryDatabase* db,
IpcMessageQueue* language_client, IpcMessageQueue* language_client,
Index_DoIndexQueue* queue_do_index, Index_DoIndexQueue* queue_do_index,
Index_DoIdMapQueue* queue_do_id_map, Index_DoIdMapQueue* queue_do_id_map,
@ -906,7 +888,7 @@ void QueryDbMainLoop(
auto msg = static_cast<Ipc_TextDocumentRename*>(message.get()); auto msg = static_cast<Ipc_TextDocumentRename*>(message.get());
QueryFileId file_id; 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) { if (!file) {
std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl; std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl;
break; break;
@ -916,7 +898,7 @@ void QueryDbMainLoop(
for (const SymbolRef& ref : FindSymbolsAtLocation(file, msg->params.position)) { for (const SymbolRef& ref : FindSymbolsAtLocation(file, msg->params.position)) {
// Found symbol. Return references to rename. // Found symbol. Return references to rename.
std::vector<QueryableLocation> uses = GetUsesOfSymbol(db, ref.idx); std::vector<QueryLocation> uses = GetUsesOfSymbol(db, ref.idx);
response.result = BuildWorkspaceEdit(db, working_files, uses, msg->params.newName); response.result = BuildWorkspaceEdit(db, working_files, uses, msg->params.newName);
break; break;
} }
@ -945,7 +927,7 @@ void QueryDbMainLoop(
auto msg = static_cast<Ipc_TextDocumentDefinition*>(message.get()); auto msg = static_cast<Ipc_TextDocumentDefinition*>(message.get());
QueryFileId file_id; 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) { if (!file) {
std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl; std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl;
break; break;
@ -965,12 +947,12 @@ void QueryDbMainLoop(
// - start at spelling but end at extent for better mouse tooltip // - start at spelling but end at extent for better mouse tooltip
// - goto declaration while in definition of recursive type // - goto declaration while in definition of recursive type
optional<QueryableLocation> def_loc = GetDefinitionSpellingOfSymbol(db, ref.idx); optional<QueryLocation> def_loc = GetDefinitionSpellingOfSymbol(db, ref.idx);
// We use spelling start and extent end because this causes vscode to // We use spelling start and extent end because this causes vscode to
// highlight the entire definition when previewing / hoving with the // highlight the entire definition when previewing / hoving with the
// mouse. // mouse.
optional<QueryableLocation> def_extent = GetDefinitionExtentOfSymbol(db, ref.idx); optional<QueryLocation> def_extent = GetDefinitionExtentOfSymbol(db, ref.idx);
if (def_loc && def_extent) if (def_loc && def_extent)
def_loc->range.end = def_extent->range.end; def_loc->range.end = def_extent->range.end;
@ -982,7 +964,7 @@ void QueryDbMainLoop(
def_loc->range.Contains(target_line, target_column))) { def_loc->range.Contains(target_line, target_column))) {
// Goto declaration. // Goto declaration.
std::vector<QueryableLocation> declarations = GetDeclarationsOfSymbolForGotoDefinition(db, ref.idx); std::vector<QueryLocation> declarations = GetDeclarationsOfSymbolForGotoDefinition(db, ref.idx);
for (auto declaration : declarations) { for (auto declaration : declarations) {
optional<lsLocation> ls_declaration = GetLsLocation(db, working_files, declaration); optional<lsLocation> ls_declaration = GetLsLocation(db, working_files, declaration);
if (ls_declaration) if (ls_declaration)
@ -1008,7 +990,7 @@ void QueryDbMainLoop(
auto msg = static_cast<Ipc_TextDocumentDocumentHighlight*>(message.get()); auto msg = static_cast<Ipc_TextDocumentDocumentHighlight*>(message.get());
QueryFileId file_id; 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) { if (!file) {
std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl; std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl;
break; break;
@ -1018,9 +1000,9 @@ void QueryDbMainLoop(
for (const SymbolRef& ref : FindSymbolsAtLocation(file, msg->params.position)) { for (const SymbolRef& ref : FindSymbolsAtLocation(file, msg->params.position)) {
// Found symbol. Return references to highlight. // Found symbol. Return references to highlight.
std::vector<QueryableLocation> uses = GetUsesOfSymbol(db, ref.idx); std::vector<QueryLocation> uses = GetUsesOfSymbol(db, ref.idx);
response.result.reserve(uses.size()); response.result.reserve(uses.size());
for (const QueryableLocation& use : uses) { for (const QueryLocation& use : uses) {
if (use.path != file_id) if (use.path != file_id)
continue; continue;
@ -1043,7 +1025,7 @@ void QueryDbMainLoop(
case IpcId::TextDocumentHover: { case IpcId::TextDocumentHover: {
auto msg = static_cast<Ipc_TextDocumentHover*>(message.get()); auto msg = static_cast<Ipc_TextDocumentHover*>(message.get());
QueryableFile* file = FindFile(db, msg->params.textDocument.uri.GetPath()); QueryFile* file = FindFile(db, msg->params.textDocument.uri.GetPath());
if (!file) { if (!file) {
std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl; std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl;
break; break;
@ -1053,7 +1035,7 @@ void QueryDbMainLoop(
for (const SymbolRef& ref : FindSymbolsAtLocation(file, msg->params.position)) { for (const SymbolRef& ref : FindSymbolsAtLocation(file, msg->params.position)) {
// Found symbol. Return hover. // Found symbol. Return hover.
optional<lsRange> ls_range = GetLsRange(working_files->GetFileByFilename(file->def.usr), ref.loc.range); optional<lsRange> ls_range = GetLsRange(working_files->GetFileByFilename(file->def.path), ref.loc.range);
if (!ls_range) if (!ls_range)
continue; continue;
@ -1069,7 +1051,7 @@ void QueryDbMainLoop(
case IpcId::TextDocumentReferences: { case IpcId::TextDocumentReferences: {
auto msg = static_cast<Ipc_TextDocumentReferences*>(message.get()); auto msg = static_cast<Ipc_TextDocumentReferences*>(message.get());
QueryableFile* file = FindFile(db, msg->params.textDocument.uri.GetPath()); QueryFile* file = FindFile(db, msg->params.textDocument.uri.GetPath());
if (!file) { if (!file) {
std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl; std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl;
break; break;
@ -1079,16 +1061,16 @@ void QueryDbMainLoop(
response.id = msg->id; response.id = msg->id;
for (const SymbolRef& ref : FindSymbolsAtLocation(file, msg->params.position)) { for (const SymbolRef& ref : FindSymbolsAtLocation(file, msg->params.position)) {
optional<QueryableLocation> excluded_declaration; optional<QueryLocation> excluded_declaration;
if (!msg->params.context.includeDeclaration) { if (!msg->params.context.includeDeclaration) {
std::cerr << "Excluding declaration in references" << std::endl; std::cerr << "Excluding declaration in references" << std::endl;
excluded_declaration = GetDefinitionSpellingOfSymbol(db, ref.idx); excluded_declaration = GetDefinitionSpellingOfSymbol(db, ref.idx);
} }
// Found symbol. Return references. // Found symbol. Return references.
std::vector<QueryableLocation> uses = GetUsesOfSymbol(db, ref.idx); std::vector<QueryLocation> uses = GetUsesOfSymbol(db, ref.idx);
response.result.reserve(uses.size()); response.result.reserve(uses.size());
for (const QueryableLocation& use : uses) { for (const QueryLocation& use : uses) {
if (excluded_declaration.has_value() && use == *excluded_declaration) if (excluded_declaration.has_value() && use == *excluded_declaration)
continue; continue;
@ -1109,7 +1091,7 @@ void QueryDbMainLoop(
Out_TextDocumentDocumentSymbol response; Out_TextDocumentDocumentSymbol response;
response.id = msg->id; response.id = msg->id;
QueryableFile* file = FindFile(db, msg->params.textDocument.uri.GetPath()); QueryFile* file = FindFile(db, msg->params.textDocument.uri.GetPath());
if (!file) { if (!file) {
std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl; std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl;
break; break;
@ -1137,7 +1119,7 @@ void QueryDbMainLoop(
lsDocumentUri file_as_uri = msg->params.textDocument.uri; 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) { if (!file) {
std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl; std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl;
break; break;
@ -1146,7 +1128,7 @@ void QueryDbMainLoop(
common.result = &response.result; common.result = &response.result;
common.db = db; common.db = db;
common.working_files = working_files; 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) { for (SymbolRef ref : file->def.outline) {
// NOTE: We OffsetColumn so that the code lens always show up in a // NOTE: We OffsetColumn so that the code lens always show up in a
@ -1155,15 +1137,15 @@ void QueryDbMainLoop(
SymbolIdx symbol = ref.idx; SymbolIdx symbol = ref.idx;
switch (symbol.kind) { switch (symbol.kind) {
case SymbolKind::Type: { case SymbolKind::Type: {
QueryableTypeDef& def = db->types[symbol.idx]; QueryType& type = db->types[symbol.idx];
AddCodeLens(&common, ref.loc.OffsetStartColumn(0), def.uses, "ref", "refs"); AddCodeLens(&common, ref.loc.OffsetStartColumn(0), type.uses, "ref", "refs");
AddCodeLens(&common, ref.loc.OffsetStartColumn(1), def.uses, "iref", "irefs", false /*exclude_loc*/, true /*only_interesting*/); AddCodeLens(&common, ref.loc.OffsetStartColumn(1), type.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(2), ToQueryLocation(db, type.derived), "derived", "derived");
AddCodeLens(&common, ref.loc.OffsetStartColumn(3), ToQueryableLocation(db, def.instantiations), "instantiation", "instantiations"); AddCodeLens(&common, ref.loc.OffsetStartColumn(3), ToQueryLocation(db, type.instantiations), "instantiation", "instantiations");
break; break;
} }
case SymbolKind::Func: { case SymbolKind::Func: {
QueryableFuncDef& func = db->funcs[symbol.idx]; QueryFunc& func = db->funcs[symbol.idx];
int offset = 0; int offset = 0;
@ -1172,20 +1154,20 @@ void QueryDbMainLoop(
std::vector<QueryFuncRef> derived_callers = GetCallersForAllDerivedFunctions(db, func); std::vector<QueryFuncRef> derived_callers = GetCallersForAllDerivedFunctions(db, func);
if (base_callers.empty() && derived_callers.empty()) { if (base_callers.empty() && derived_callers.empty()) {
// set exclude_loc to true to force the code lens to show up // 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 { 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()) 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()) 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" // "Base"
optional<QueryableLocation> base_loc = GetBaseDefinitionOrDeclarationSpelling(db, func); optional<QueryLocation> base_loc = GetBaseDefinitionOrDeclarationSpelling(db, func);
if (base_loc) { if (base_loc) {
optional<lsLocation> ls_base = GetLsLocation(db, working_files, *base_loc); optional<lsLocation> ls_base = GetLsLocation(db, working_files, *base_loc);
if (ls_base) { if (ls_base) {
@ -1207,8 +1189,8 @@ void QueryDbMainLoop(
break; break;
} }
case SymbolKind::Var: { case SymbolKind::Var: {
QueryableVarDef& def = db->vars[symbol.idx]; QueryVar& var = db->vars[symbol.idx];
AddCodeLens(&common, ref.loc.OffsetStartColumn(0), def.uses, "ref", "refs", true /*exclude_loc*/, false /*only_interesting*/); AddCodeLens(&common, ref.loc.OffsetStartColumn(0), var.uses, "ref", "refs", true /*exclude_loc*/, false /*only_interesting*/);
break; break;
} }
case SymbolKind::File: case SymbolKind::File:
@ -1242,7 +1224,7 @@ void QueryDbMainLoop(
if (db->detailed_names[i].find(query) != std::string::npos) { if (db->detailed_names[i].find(query) != std::string::npos) {
lsSymbolInformation info = GetSymbolInfo(db, working_files, db->symbols[i]); lsSymbolInformation info = GetSymbolInfo(db, working_files, db->symbols[i]);
optional<QueryableLocation> location = GetDefinitionExtentOfSymbol(db, db->symbols[i]); optional<QueryLocation> location = GetDefinitionExtentOfSymbol(db, db->symbols[i]);
if (!location) { if (!location) {
auto decls = GetDeclarationsOfSymbolForGotoDefinition(db, db->symbols[i]); auto decls = GetDeclarationsOfSymbolForGotoDefinition(db, db->symbols[i]);
if (decls.empty()) if (decls.empty())
@ -1330,7 +1312,7 @@ void QueryDbMain() {
} }
// Run query db main loop. // Run query db main loop.
QueryableDatabase db; QueryDatabase db;
while (true) { 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); 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)); std::this_thread::sleep_for(std::chrono::milliseconds(10));

View File

@ -16,9 +16,9 @@
namespace { 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()); assert(!type.short_name.empty());
QueryableTypeDef::DefUpdate result(type.usr); QueryType::DefUpdate result(type.usr);
result.short_name = type.short_name; result.short_name = type.short_name;
result.detailed_name = type.detailed_name; result.detailed_name = type.detailed_name;
result.definition_spelling = id_map.ToQuery(type.definition_spelling); 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; 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()); assert(!func.short_name.empty());
QueryableFuncDef::DefUpdate result(func.usr); QueryFunc::DefUpdate result(func.usr);
result.short_name = func.short_name; result.short_name = func.short_name;
result.detailed_name = func.detailed_name; result.detailed_name = func.detailed_name;
result.definition_spelling = id_map.ToQuery(func.definition_spelling); 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; 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()); assert(!var.short_name.empty());
QueryableVarDef::DefUpdate result(var.usr); QueryVar::DefUpdate result(var.usr);
result.short_name = var.short_name; result.short_name = var.short_name;
result.detailed_name = var.detailed_name; result.detailed_name = var.detailed_name;
result.declaration = id_map.ToQuery(var.declaration); 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) { QueryFile::Def BuildFileDef(const IdMap& id_map, const IndexedFile& indexed) {
QueryableFile::Def def; QueryFile::Def def;
def.usr = indexed.path; def.path = indexed.path;
auto add_outline = [&def, &id_map](SymbolIdx idx, Range range) { auto add_outline = [&def, &id_map](SymbolIdx idx, Range range) {
def.outline.push_back(SymbolRef(idx, id_map.ToQuery(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); assert(kind == SymbolKind::File);
return &db->files[idx]; return &db->files[idx];
} }
QueryableTypeDef* SymbolIdx::ResolveType(QueryableDatabase* db) const { QueryType* SymbolIdx::ResolveType(QueryDatabase* db) const {
assert(kind == SymbolKind::Type); assert(kind == SymbolKind::Type);
return &db->types[idx]; return &db->types[idx];
} }
QueryableFuncDef* SymbolIdx::ResolveFunc(QueryableDatabase* db) const { QueryFunc* SymbolIdx::ResolveFunc(QueryDatabase* db) const {
assert(kind == SymbolKind::Func); assert(kind == SymbolKind::Func);
return &db->funcs[idx]; return &db->funcs[idx];
} }
QueryableVarDef* SymbolIdx::ResolveVar(QueryableDatabase* db) const { QueryVar* SymbolIdx::ResolveVar(QueryDatabase* db) const {
assert(kind == SymbolKind::Var); assert(kind == SymbolKind::Var);
return &db->vars[idx]; return &db->vars[idx];
} }
@ -263,20 +263,20 @@ void CompareGroups(
// TODO: consider having separate lookup maps so they are smaller (maybe // TODO: consider having separate lookup maps so they are smaller (maybe
// lookups will go faster). // lookups will go faster).
// TODO: Figure out where the invalid SymbolKinds are coming from. // TODO: Figure out where the invalid SymbolKinds are coming from.
QueryFileId GetQueryFileIdFromUsr(QueryableDatabase* query_db, const Usr& usr) { QueryFileId GetQueryFileIdFromPath(QueryDatabase* query_db, const std::string& path) {
auto it = query_db->usr_to_symbol.find(usr); auto it = query_db->usr_to_symbol.find(path);
if (it != query_db->usr_to_symbol.end() && it->second.kind != SymbolKind::Invalid) { if (it != query_db->usr_to_symbol.end() && it->second.kind != SymbolKind::Invalid) {
assert(it->second.kind == SymbolKind::File); assert(it->second.kind == SymbolKind::File);
return QueryFileId(it->second.idx); return QueryFileId(it->second.idx);
} }
size_t idx = query_db->files.size(); size_t idx = query_db->files.size();
query_db->usr_to_symbol[usr] = SymbolIdx(SymbolKind::File, idx); query_db->usr_to_symbol[path] = SymbolIdx(SymbolKind::File, idx);
query_db->files.push_back(QueryableFile(usr)); query_db->files.push_back(QueryFile(path));
return QueryFileId(idx); 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); auto it = query_db->usr_to_symbol.find(usr);
if (it != query_db->usr_to_symbol.end() && it->second.kind != SymbolKind::Invalid) { if (it != query_db->usr_to_symbol.end() && it->second.kind != SymbolKind::Invalid) {
assert(it->second.kind == SymbolKind::Type); 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(); size_t idx = query_db->types.size();
query_db->usr_to_symbol[usr] = SymbolIdx(SymbolKind::Type, idx); 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); 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); auto it = query_db->usr_to_symbol.find(usr);
if (it != query_db->usr_to_symbol.end() && it->second.kind != SymbolKind::Invalid) { if (it != query_db->usr_to_symbol.end() && it->second.kind != SymbolKind::Invalid) {
assert(it->second.kind == SymbolKind::Func); 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(); size_t idx = query_db->funcs.size();
query_db->usr_to_symbol[usr] = SymbolIdx(SymbolKind::Func, idx); 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); 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); auto it = query_db->usr_to_symbol.find(usr);
if (it != query_db->usr_to_symbol.end() && it->second.kind != SymbolKind::Invalid) { if (it != query_db->usr_to_symbol.end() && it->second.kind != SymbolKind::Invalid) {
assert(it->second.kind == SymbolKind::Var); 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(); size_t idx = query_db->vars.size();
query_db->usr_to_symbol[usr] = SymbolIdx(SymbolKind::Var, idx); 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); 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) { : 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_.set_empty_key(-1);
cached_type_ids_.resize(local_ids.type_id_to_usr.size()); 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; cached_var_ids_[entry.first.id] = GetQueryVarIdFromUsr(query_db, entry.second).id;
} }
QueryableLocation IdMap::ToQuery(Range range) const { QueryLocation IdMap::ToQuery(Range range) const {
return QueryableLocation(primary_file, range); return QueryLocation(primary_file, range);
} }
QueryTypeId IdMap::ToQuery(IndexTypeId id) const { QueryTypeId IdMap::ToQuery(IndexTypeId id) const {
@ -356,7 +356,7 @@ QueryFuncRef IdMap::ToQuery(IndexFuncRef ref) const {
return QueryFuncRef(ToQuery(ref.id_), ToQuery(ref.loc)); return QueryFuncRef(ToQuery(ref.id_), ToQuery(ref.loc));
} }
optional<QueryableLocation> IdMap::ToQuery(optional<Range> range) const { optional<QueryLocation> IdMap::ToQuery(optional<Range> range) const {
if (!range) if (!range)
return nullopt; return nullopt;
return ToQuery(range.value()); return ToQuery(range.value());
@ -390,8 +390,8 @@ std::vector<Out> ToQueryTransform(const IdMap& id_map, const std::vector<In>& in
result.push_back(id_map.ToQuery(in)); result.push_back(id_map.ToQuery(in));
return result; return result;
} }
std::vector<QueryableLocation> IdMap::ToQuery(std::vector<Range> ranges) const { std::vector<QueryLocation> IdMap::ToQuery(std::vector<Range> ranges) const {
return ToQueryTransform<Range, QueryableLocation>(*this, ranges); return ToQueryTransform<Range, QueryLocation>(*this, ranges);
} }
std::vector<QueryTypeId> IdMap::ToQuery(std::vector<IndexTypeId> ids) const { std::vector<QueryTypeId> IdMap::ToQuery(std::vector<IndexTypeId> ids) const {
return ToQueryTransform<IndexTypeId, QueryTypeId>(*this, ids); return ToQueryTransform<IndexTypeId, QueryTypeId>(*this, ids);
@ -472,21 +472,21 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, const IdMap& current_id_m
if (!type->def.short_name.empty()) if (!type->def.short_name.empty())
types_def_update.push_back(ToQuery(current_id_map, type->def)); types_def_update.push_back(ToQuery(current_id_map, type->def));
if (!type->derived.empty()) 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()) 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()) 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, &current_id_map](IndexedTypeDef* previous_def, IndexedTypeDef* current_def) { /*onFound:*/[this, &previous_id_map, &current_id_map](IndexedTypeDef* previous_def, IndexedTypeDef* current_def) {
optional<QueryableTypeDef::DefUpdate> previous_remapped_def = ToQuery(previous_id_map, previous_def->def); optional<QueryType::DefUpdate> previous_remapped_def = ToQuery(previous_id_map, previous_def->def);
optional<QueryableTypeDef::DefUpdate> current_remapped_def = ToQuery(current_id_map, current_def->def); optional<QueryType::DefUpdate> current_remapped_def = ToQuery(current_id_map, current_def->def);
if (current_remapped_def && previous_remapped_def != current_remapped_def) if (current_remapped_def && previous_remapped_def != current_remapped_def)
types_def_update.push_back(*current_remapped_def); types_def_update.push_back(*current_remapped_def);
PROCESS_UPDATE_DIFF(QueryTypeId, types_derived, derived, QueryTypeId); PROCESS_UPDATE_DIFF(QueryTypeId, types_derived, derived, QueryTypeId);
PROCESS_UPDATE_DIFF(QueryTypeId, types_instantiations, instantiations, QueryVarId); 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 // Functions
@ -498,19 +498,19 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, const IdMap& current_id_m
if (!func->def.short_name.empty()) if (!func->def.short_name.empty())
funcs_def_update.push_back(ToQuery(current_id_map, func->def)); funcs_def_update.push_back(ToQuery(current_id_map, func->def));
if (!func->declarations.empty()) 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()) 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()) 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, &current_id_map](IndexedFuncDef* previous_def, IndexedFuncDef* current_def) { /*onFound:*/[this, &previous_id_map, &current_id_map](IndexedFuncDef* previous_def, IndexedFuncDef* current_def) {
optional<QueryableFuncDef::DefUpdate> previous_remapped_def = ToQuery(previous_id_map, previous_def->def); optional<QueryFunc::DefUpdate> previous_remapped_def = ToQuery(previous_id_map, previous_def->def);
optional<QueryableFuncDef::DefUpdate> current_remapped_def = ToQuery(current_id_map, current_def->def); optional<QueryFunc::DefUpdate> current_remapped_def = ToQuery(current_id_map, current_def->def);
if (current_remapped_def && previous_remapped_def != current_remapped_def) if (current_remapped_def && previous_remapped_def != current_remapped_def)
funcs_def_update.push_back(*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_derived, derived, QueryFuncId);
PROCESS_UPDATE_DIFF(QueryFuncId, funcs_callers, callers, QueryFuncRef); 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()) if (!var->def.short_name.empty())
vars_def_update.push_back(ToQuery(current_id_map, var->def)); vars_def_update.push_back(ToQuery(current_id_map, var->def));
if (!var->uses.empty()) 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, &current_id_map](IndexedVarDef* previous_def, IndexedVarDef* current_def) { /*onFound:*/[this, &previous_id_map, &current_id_map](IndexedVarDef* previous_def, IndexedVarDef* current_def) {
optional<QueryableVarDef::DefUpdate> previous_remapped_def = ToQuery(previous_id_map, previous_def->def); optional<QueryVar::DefUpdate> previous_remapped_def = ToQuery(previous_id_map, previous_def->def);
optional<QueryableVarDef::DefUpdate> current_remapped_def = ToQuery(current_id_map, current_def->def); optional<QueryVar::DefUpdate> current_remapped_def = ToQuery(current_id_map, current_def->def);
if (current_remapped_def && previous_remapped_def != current_remapped_def) if (current_remapped_def && previous_remapped_def != current_remapped_def)
vars_def_update.push_back(*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 #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) { if (*qualified_name_index == -1) {
db->detailed_names.push_back(name); db->detailed_names.push_back(name);
db->symbols.push_back(SymbolIdx(kind, symbol_index)); 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<Usr>& to_remove) { void QueryDatabase::RemoveUsrs(const std::vector<Usr>& to_remove) {
// TODO: Removing usrs is tricky because it means we will have to rebuild idx locations. I'm thinking we just nullify // 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. // the entry instead of actually removing the data. The index could be massive.
for (Usr usr : to_remove) for (Usr usr : to_remove)
@ -610,18 +610,18 @@ void QueryableDatabase::RemoveUsrs(const std::vector<Usr>& to_remove) {
// TODO: also remove from qualified_names? // TODO: also remove from qualified_names?
} }
void QueryableDatabase::ImportOrUpdate(const std::vector<QueryableFile::DefUpdate>& updates) { void QueryDatabase::ImportOrUpdate(const std::vector<QueryFile::DefUpdate>& updates) {
for (auto& def : 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()); assert(it != usr_to_symbol.end());
QueryableFile& existing = files[it->second.idx]; QueryFile& existing = files[it->second.idx];
existing.def = def; existing.def = def;
//SetQualifiedNameForWorkspaceSearch(this, &existing.qualified_name_idx, SymbolKind::File, it->second.idx, def.qualified_name); //SetQualifiedNameForWorkspaceSearch(this, &existing.qualified_name_idx, SymbolKind::File, it->second.idx, def.qualified_name);
} }
} }
void QueryableDatabase::ImportOrUpdate(const std::vector<QueryableTypeDef::DefUpdate>& updates) { void QueryDatabase::ImportOrUpdate(const std::vector<QueryType::DefUpdate>& updates) {
for (auto& def : updates) { for (auto& def : updates) {
if (def.detailed_name.empty()) if (def.detailed_name.empty())
continue; continue;
@ -629,7 +629,7 @@ void QueryableDatabase::ImportOrUpdate(const std::vector<QueryableTypeDef::DefUp
auto it = usr_to_symbol.find(def.usr); auto it = usr_to_symbol.find(def.usr);
assert(it != usr_to_symbol.end()); assert(it != usr_to_symbol.end());
QueryableTypeDef& existing = types[it->second.idx]; QueryType& existing = types[it->second.idx];
if (existing.def.definition_spelling && !def.definition_spelling) if (existing.def.definition_spelling && !def.definition_spelling)
continue; continue;
@ -638,7 +638,7 @@ void QueryableDatabase::ImportOrUpdate(const std::vector<QueryableTypeDef::DefUp
} }
} }
void QueryableDatabase::ImportOrUpdate(const std::vector<QueryableFuncDef::DefUpdate>& updates) { void QueryDatabase::ImportOrUpdate(const std::vector<QueryFunc::DefUpdate>& updates) {
for (auto& def : updates) { for (auto& def : updates) {
if (def.detailed_name.empty()) if (def.detailed_name.empty())
continue; continue;
@ -646,7 +646,7 @@ void QueryableDatabase::ImportOrUpdate(const std::vector<QueryableFuncDef::DefUp
auto it = usr_to_symbol.find(def.usr); auto it = usr_to_symbol.find(def.usr);
assert(it != usr_to_symbol.end()); assert(it != usr_to_symbol.end());
QueryableFuncDef& existing = funcs[it->second.idx]; QueryFunc& existing = funcs[it->second.idx];
if (existing.def.definition_spelling && !def.definition_spelling) if (existing.def.definition_spelling && !def.definition_spelling)
continue; continue;
@ -655,7 +655,7 @@ void QueryableDatabase::ImportOrUpdate(const std::vector<QueryableFuncDef::DefUp
} }
} }
void QueryableDatabase::ImportOrUpdate(const std::vector<QueryableVarDef::DefUpdate>& updates) { void QueryDatabase::ImportOrUpdate(const std::vector<QueryVar::DefUpdate>& updates) {
for (auto& def : updates) { for (auto& def : updates) {
if (def.detailed_name.empty()) if (def.detailed_name.empty())
continue; continue;
@ -663,7 +663,7 @@ void QueryableDatabase::ImportOrUpdate(const std::vector<QueryableVarDef::DefUpd
auto it = usr_to_symbol.find(def.usr); auto it = usr_to_symbol.find(def.usr);
assert(it != usr_to_symbol.end()); assert(it != usr_to_symbol.end());
QueryableVarDef& existing = vars[it->second.idx]; QueryVar& existing = vars[it->second.idx];
if (existing.def.definition_spelling && !def.definition_spelling) if (existing.def.definition_spelling && !def.definition_spelling)
continue; continue;
@ -673,7 +673,7 @@ void QueryableDatabase::ImportOrUpdate(const std::vector<QueryableVarDef::DefUpd
} }
} }
void QueryableDatabase::ApplyIndexUpdate(IndexUpdate* update) { void QueryDatabase::ApplyIndexUpdate(IndexUpdate* update) {
#define HANDLE_MERGEABLE(update_var_name, def_var_name, storage_name) \ #define HANDLE_MERGEABLE(update_var_name, def_var_name, storage_name) \
for (auto merge_update : update->update_var_name) { \ for (auto merge_update : update->update_var_name) { \
auto* def = &storage_name[merge_update.id.id]; \ auto* def = &storage_name[merge_update.id.id]; \

View File

@ -7,15 +7,16 @@
using Usr = std::string; using Usr = std::string;
struct QueryableFile; struct QueryFile;
struct QueryableTypeDef; struct QueryType;
struct QueryableFuncDef; struct QueryFunc;
struct QueryableVarDef; struct QueryVar;
struct QueryDatabase;
using QueryFileId = Id<QueryableFile>; using QueryFileId = Id<QueryFile>;
using QueryTypeId = Id<QueryableTypeDef>; using QueryTypeId = Id<QueryType>;
using QueryFuncId = Id<QueryableFuncDef>; using QueryFuncId = Id<QueryFunc>;
using QueryVarId = Id<QueryableVarDef>; using QueryVarId = Id<QueryVar>;
@ -29,39 +30,33 @@ struct IdMap;
// TODO: in types, store refs separately from irefs. Then we can drop // TODO: in types, store refs separately from irefs. Then we can drop
// 'interesting' from location when that is cleaned up. // 'interesting' from location when that is cleaned up.
struct QueryableLocation { struct QueryLocation {
QueryFileId path; QueryFileId path;
Range range; Range range;
QueryableLocation(QueryFileId path, Range range) QueryLocation(QueryFileId path, Range range)
: path(path), range(range) {} : path(path), range(range) {}
QueryableLocation OffsetStartColumn(int offset) const { QueryLocation OffsetStartColumn(int offset) const {
QueryableLocation result = *this; QueryLocation result = *this;
result.range.start.column += offset; result.range.start.column += offset;
return result; return result;
} }
bool operator==(const QueryableLocation& other) const { bool operator==(const QueryLocation& other) const {
// Note: We ignore |is_interesting|. // Note: We ignore |is_interesting|.
return return
path == other.path && path == other.path &&
range == other.range; range == other.range;
} }
bool operator!=(const QueryableLocation& other) const { return !(*this == other); } bool operator!=(const QueryLocation& other) const { return !(*this == other); }
bool operator<(const QueryableLocation& o) const { bool operator<(const QueryLocation& o) const {
return return
path < o.path && path < o.path &&
range < o.range; range < o.range;
} }
}; };
struct QueryableFile;
struct QueryableTypeDef;
struct QueryableFuncDef;
struct QueryableVarDef;
struct QueryableDatabase;
enum class SymbolKind { Invalid, File, Type, Func, Var }; enum class SymbolKind { Invalid, File, Type, Func, Var };
struct SymbolIdx { struct SymbolIdx {
SymbolKind kind; SymbolKind kind;
@ -78,17 +73,17 @@ struct SymbolIdx {
return kind < that.kind || idx < that.idx; return kind < that.kind || idx < that.idx;
} }
QueryableFile* ResolveFile(QueryableDatabase* db) const; QueryFile* ResolveFile(QueryDatabase* db) const;
QueryableTypeDef* ResolveType(QueryableDatabase* db) const; QueryType* ResolveType(QueryDatabase* db) const;
QueryableFuncDef* ResolveFunc(QueryableDatabase* db) const; QueryFunc* ResolveFunc(QueryDatabase* db) const;
QueryableVarDef* ResolveVar(QueryableDatabase* db) const; QueryVar* ResolveVar(QueryDatabase* db) const;
}; };
struct SymbolRef { struct SymbolRef {
SymbolIdx idx; 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 { bool operator==(const SymbolRef& that) const {
return idx == that.idx && loc == that.loc; return idx == that.idx && loc == that.loc;
@ -109,9 +104,9 @@ struct QueryFuncRef {
} }
QueryFuncId id_; 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 { bool operator==(const QueryFuncRef& that) const {
return id_ == that.id_ && loc == that.loc; return id_ == that.id_ && loc == that.loc;
@ -146,9 +141,9 @@ struct MergeableUpdate {
: id(id), to_add(to_add), to_remove(to_remove) {} : id(id), to_add(to_add), to_remove(to_remove) {}
}; };
struct QueryableFile { struct QueryFile {
struct Def { struct Def {
Usr usr; std::string path;
// Outline of the file (ie, for code lens). // Outline of the file (ie, for code lens).
std::vector<SymbolRef> outline; std::vector<SymbolRef> outline;
// Every symbol found in the file (ie, for goto definition) // Every symbol found in the file (ie, for goto definition)
@ -160,49 +155,49 @@ struct QueryableFile {
DefUpdate def; DefUpdate def;
size_t detailed_name_idx = -1; size_t detailed_name_idx = -1;
QueryableFile(const Usr& usr) { def.usr = usr; } QueryFile(const std::string& path) { def.path = path; }
}; };
struct QueryableTypeDef { struct QueryType {
using DefUpdate = TypeDefDefinitionData<QueryTypeId, QueryFuncId, QueryVarId, QueryableLocation>; using DefUpdate = TypeDefDefinitionData<QueryTypeId, QueryFuncId, QueryVarId, QueryLocation>;
using DerivedUpdate = MergeableUpdate<QueryTypeId, QueryTypeId>; using DerivedUpdate = MergeableUpdate<QueryTypeId, QueryTypeId>;
using InstantiationsUpdate = MergeableUpdate<QueryTypeId, QueryVarId>; using InstantiationsUpdate = MergeableUpdate<QueryTypeId, QueryVarId>;
using UsesUpdate = MergeableUpdate<QueryTypeId, QueryableLocation>; using UsesUpdate = MergeableUpdate<QueryTypeId, QueryLocation>;
DefUpdate def; DefUpdate def;
std::vector<QueryTypeId> derived; std::vector<QueryTypeId> derived;
std::vector<QueryVarId> instantiations; std::vector<QueryVarId> instantiations;
std::vector<QueryableLocation> uses; std::vector<QueryLocation> uses;
size_t detailed_name_idx = -1; size_t detailed_name_idx = -1;
QueryableTypeDef(const Usr& usr) : def(usr) {} QueryType(const Usr& usr) : def(usr) {}
}; };
struct QueryableFuncDef { struct QueryFunc {
using DefUpdate = FuncDefDefinitionData<QueryTypeId, QueryFuncId, QueryVarId, QueryFuncRef, QueryableLocation>; using DefUpdate = FuncDefDefinitionData<QueryTypeId, QueryFuncId, QueryVarId, QueryFuncRef, QueryLocation>;
using DeclarationsUpdate = MergeableUpdate<QueryFuncId, QueryableLocation>; using DeclarationsUpdate = MergeableUpdate<QueryFuncId, QueryLocation>;
using DerivedUpdate = MergeableUpdate<QueryFuncId, QueryFuncId>; using DerivedUpdate = MergeableUpdate<QueryFuncId, QueryFuncId>;
using CallersUpdate = MergeableUpdate<QueryFuncId, QueryFuncRef>; using CallersUpdate = MergeableUpdate<QueryFuncId, QueryFuncRef>;
DefUpdate def; DefUpdate def;
std::vector<QueryableLocation> declarations; std::vector<QueryLocation> declarations;
std::vector<QueryFuncId> derived; std::vector<QueryFuncId> derived;
std::vector<QueryFuncRef> callers; std::vector<QueryFuncRef> callers;
size_t detailed_name_idx = -1; size_t detailed_name_idx = -1;
QueryableFuncDef(const Usr& usr) : def(usr) {} QueryFunc(const Usr& usr) : def(usr) {}
QueryableFuncDef(const DefUpdate& def) : def(def) {} QueryFunc(const DefUpdate& def) : def(def) {}
}; };
struct QueryableVarDef { struct QueryVar {
using DefUpdate = VarDefDefinitionData<QueryTypeId, QueryFuncId, QueryVarId, QueryableLocation>; using DefUpdate = VarDefDefinitionData<QueryTypeId, QueryFuncId, QueryVarId, QueryLocation>;
using UsesUpdate = MergeableUpdate<QueryVarId, QueryableLocation>; using UsesUpdate = MergeableUpdate<QueryVarId, QueryLocation>;
DefUpdate def; DefUpdate def;
std::vector<QueryableLocation> uses; std::vector<QueryLocation> uses;
size_t detailed_name_idx = -1; size_t detailed_name_idx = -1;
QueryableVarDef(const Usr& usr) : def(usr) {} QueryVar(const Usr& usr) : def(usr) {}
}; };
struct IndexUpdate { struct IndexUpdate {
@ -216,26 +211,26 @@ struct IndexUpdate {
// File updates. // File updates.
std::vector<Usr> files_removed; std::vector<Usr> files_removed;
std::vector<QueryableFile::DefUpdate> files_def_update; std::vector<QueryFile::DefUpdate> files_def_update;
// Type updates. // Type updates.
std::vector<Usr> types_removed; std::vector<Usr> types_removed;
std::vector<QueryableTypeDef::DefUpdate> types_def_update; std::vector<QueryType::DefUpdate> types_def_update;
std::vector<QueryableTypeDef::DerivedUpdate> types_derived; std::vector<QueryType::DerivedUpdate> types_derived;
std::vector<QueryableTypeDef::InstantiationsUpdate> types_instantiations; std::vector<QueryType::InstantiationsUpdate> types_instantiations;
std::vector<QueryableTypeDef::UsesUpdate> types_uses; std::vector<QueryType::UsesUpdate> types_uses;
// Function updates. // Function updates.
std::vector<Usr> funcs_removed; std::vector<Usr> funcs_removed;
std::vector<QueryableFuncDef::DefUpdate> funcs_def_update; std::vector<QueryFunc::DefUpdate> funcs_def_update;
std::vector<QueryableFuncDef::DeclarationsUpdate> funcs_declarations; std::vector<QueryFunc::DeclarationsUpdate> funcs_declarations;
std::vector<QueryableFuncDef::DerivedUpdate> funcs_derived; std::vector<QueryFunc::DerivedUpdate> funcs_derived;
std::vector<QueryableFuncDef::CallersUpdate> funcs_callers; std::vector<QueryFunc::CallersUpdate> funcs_callers;
// Variable updates. // Variable updates.
std::vector<Usr> vars_removed; std::vector<Usr> vars_removed;
std::vector<QueryableVarDef::DefUpdate> vars_def_update; std::vector<QueryVar::DefUpdate> vars_def_update;
std::vector<QueryableVarDef::UsesUpdate> vars_uses; std::vector<QueryVar::UsesUpdate> vars_uses;
private: private:
// Creates an index update assuming that |previous| is already // 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 // The query database is heavily optimized for fast queries. It is stored
// in-memory. // in-memory.
struct QueryableDatabase { struct QueryDatabase {
// Indicies between lookup vectors are related to symbols, ie, index 5 in // Indicies between lookup vectors are related to symbols, ie, index 5 in
// |detailed_names| matches index 5 in |symbols|. // |detailed_names| matches index 5 in |symbols|.
std::vector<std::string> detailed_names; std::vector<std::string> detailed_names;
std::vector<SymbolIdx> symbols; std::vector<SymbolIdx> symbols;
// Raw data storage. // Raw data storage.
std::vector<QueryableFile> files; // File path is stored as a Usr. std::vector<QueryFile> files; // File path is stored as a Usr.
std::vector<QueryableTypeDef> types; std::vector<QueryType> types;
std::vector<QueryableFuncDef> funcs; std::vector<QueryFunc> funcs;
std::vector<QueryableVarDef> vars; std::vector<QueryVar> vars;
// Lookup symbol based on a usr. // Lookup symbol based on a usr.
google::dense_hash_map<Usr, SymbolIdx> usr_to_symbol; google::dense_hash_map<Usr, SymbolIdx> usr_to_symbol;
QueryableDatabase() { QueryDatabase() {
usr_to_symbol.set_empty_key(""); usr_to_symbol.set_empty_key("");
} }
//std::unordered_map<Usr, SymbolIdx> usr_to_symbol; //std::unordered_map<Usr, SymbolIdx> usr_to_symbol;
@ -271,10 +266,10 @@ struct QueryableDatabase {
void ApplyIndexUpdate(IndexUpdate* update); void ApplyIndexUpdate(IndexUpdate* update);
void RemoveUsrs(const std::vector<Usr>& to_remove); void RemoveUsrs(const std::vector<Usr>& to_remove);
void ImportOrUpdate(const std::vector<QueryableFile::DefUpdate>& updates); void ImportOrUpdate(const std::vector<QueryFile::DefUpdate>& updates);
void ImportOrUpdate(const std::vector<QueryableTypeDef::DefUpdate>& updates); void ImportOrUpdate(const std::vector<QueryType::DefUpdate>& updates);
void ImportOrUpdate(const std::vector<QueryableFuncDef::DefUpdate>& updates); void ImportOrUpdate(const std::vector<QueryFunc::DefUpdate>& updates);
void ImportOrUpdate(const std::vector<QueryableVarDef::DefUpdate>& updates); void ImportOrUpdate(const std::vector<QueryVar::DefUpdate>& updates);
}; };
@ -291,19 +286,19 @@ struct IdMap {
const IdCache& local_ids; const IdCache& local_ids;
QueryFileId primary_file; 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; QueryTypeId ToQuery(IndexTypeId id) const;
QueryFuncId ToQuery(IndexFuncId id) const; QueryFuncId ToQuery(IndexFuncId id) const;
QueryVarId ToQuery(IndexVarId id) const; QueryVarId ToQuery(IndexVarId id) const;
QueryFuncRef ToQuery(IndexFuncRef ref) const; QueryFuncRef ToQuery(IndexFuncRef ref) const;
optional<QueryableLocation> ToQuery(optional<Range> range) const; optional<QueryLocation> ToQuery(optional<Range> range) const;
optional<QueryTypeId> ToQuery(optional<IndexTypeId> id) const; optional<QueryTypeId> ToQuery(optional<IndexTypeId> id) const;
optional<QueryFuncId> ToQuery(optional<IndexFuncId> id) const; optional<QueryFuncId> ToQuery(optional<IndexFuncId> id) const;
optional<QueryVarId> ToQuery(optional<IndexVarId> id) const; optional<QueryVarId> ToQuery(optional<IndexVarId> id) const;
optional<QueryFuncRef> ToQuery(optional<IndexFuncRef> ref) const; optional<QueryFuncRef> ToQuery(optional<IndexFuncRef> ref) const;
std::vector<QueryableLocation> ToQuery(std::vector<Range> ranges) const; std::vector<QueryLocation> ToQuery(std::vector<Range> ranges) const;
std::vector<QueryTypeId> ToQuery(std::vector<IndexTypeId> ids) const; std::vector<QueryTypeId> ToQuery(std::vector<IndexTypeId> ids) const;
std::vector<QueryFuncId> ToQuery(std::vector<IndexFuncId> ids) const; std::vector<QueryFuncId> ToQuery(std::vector<IndexFuncId> ids) const;
std::vector<QueryVarId> ToQuery(std::vector<IndexVarId> ids) const; std::vector<QueryVarId> ToQuery(std::vector<IndexVarId> ids) const;