mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-19 12:05:50 +00:00
Tons of renames (generally, Queryable -> Query, QueryableTypeDef -> QueryType, QueryableFuncDef -> QueryFunc, QueryableVarDef -> QueryVar)
This commit is contained in:
parent
4135186ae2
commit
5109d27b87
@ -44,7 +44,7 @@ void PushBack(NonElidedVector<lsLocation>* result, optional<lsLocation> 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<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) {
|
||||
return GetQueryable(db, id)->def.definition_spelling;
|
||||
optional<QueryLocation> GetDefinitionSpellingOfSymbol(QueryDatabase* db, const QueryTypeId& id) {
|
||||
return GetQuery(db, id)->def.definition_spelling;
|
||||
}
|
||||
optional<QueryableLocation> GetDefinitionSpellingOfSymbol(QueryableDatabase* db, const QueryFuncId& id) {
|
||||
return GetQueryable(db, id)->def.definition_spelling;
|
||||
optional<QueryLocation> GetDefinitionSpellingOfSymbol(QueryDatabase* db, const QueryFuncId& id) {
|
||||
return GetQuery(db, id)->def.definition_spelling;
|
||||
}
|
||||
optional<QueryableLocation> GetDefinitionSpellingOfSymbol(QueryableDatabase* db, const QueryVarId& id) {
|
||||
return GetQueryable(db, id)->def.definition_spelling;
|
||||
optional<QueryLocation> GetDefinitionSpellingOfSymbol(QueryDatabase* db, const QueryVarId& id) {
|
||||
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) {
|
||||
case SymbolKind::Type:
|
||||
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) {
|
||||
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<QueryableLocation> ToQueryableLocation(QueryableDatabase* db, const std::vector<QueryFuncRef>& refs) {
|
||||
std::vector<QueryableLocation> locs;
|
||||
std::vector<QueryLocation> ToQueryLocation(QueryDatabase* db, const std::vector<QueryFuncRef>& refs) {
|
||||
std::vector<QueryLocation> locs;
|
||||
locs.reserve(refs.size());
|
||||
for (const QueryFuncRef& ref : refs)
|
||||
locs.push_back(ref.loc);
|
||||
return locs;
|
||||
}
|
||||
std::vector<QueryableLocation> ToQueryableLocation(QueryableDatabase* db, const std::vector<QueryTypeId>& ids) {
|
||||
std::vector<QueryableLocation> locs;
|
||||
std::vector<QueryLocation> ToQueryLocation(QueryDatabase* db, const std::vector<QueryTypeId>& ids) {
|
||||
std::vector<QueryLocation> locs;
|
||||
locs.reserve(ids.size());
|
||||
for (const QueryTypeId& id : ids) {
|
||||
optional<QueryableLocation> loc = GetDefinitionSpellingOfSymbol(db, id);
|
||||
optional<QueryLocation> loc = GetDefinitionSpellingOfSymbol(db, id);
|
||||
if (loc)
|
||||
locs.push_back(loc.value());
|
||||
}
|
||||
return locs;
|
||||
}
|
||||
std::vector<QueryableLocation> ToQueryableLocation(QueryableDatabase* db, const std::vector<QueryFuncId>& ids) {
|
||||
std::vector<QueryableLocation> locs;
|
||||
std::vector<QueryLocation> ToQueryLocation(QueryDatabase* db, const std::vector<QueryFuncId>& ids) {
|
||||
std::vector<QueryLocation> locs;
|
||||
locs.reserve(ids.size());
|
||||
for (const QueryFuncId& id : ids) {
|
||||
optional<QueryableLocation> loc = GetDefinitionSpellingOfSymbol(db, id);
|
||||
optional<QueryLocation> loc = GetDefinitionSpellingOfSymbol(db, id);
|
||||
if (loc)
|
||||
locs.push_back(loc.value());
|
||||
}
|
||||
return locs;
|
||||
}
|
||||
std::vector<QueryableLocation> ToQueryableLocation(QueryableDatabase* db, const std::vector<QueryVarId>& ids) {
|
||||
std::vector<QueryableLocation> locs;
|
||||
std::vector<QueryLocation> ToQueryLocation(QueryDatabase* db, const std::vector<QueryVarId>& ids) {
|
||||
std::vector<QueryLocation> locs;
|
||||
locs.reserve(ids.size());
|
||||
for (const QueryVarId& id : ids) {
|
||||
optional<QueryableLocation> loc = GetDefinitionSpellingOfSymbol(db, id);
|
||||
optional<QueryLocation> loc = GetDefinitionSpellingOfSymbol(db, id);
|
||||
if (loc)
|
||||
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) {
|
||||
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<QueryableLocation> result = ToQueryableLocation(db, func.callers);
|
||||
const QueryFunc& func = db->funcs[symbol.idx];
|
||||
std::vector<QueryLocation> 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<QueryableLocation> GetUsesOfSymbol(QueryableDatabase* db, const Symb
|
||||
return {};
|
||||
}
|
||||
|
||||
optional<QueryableLocation> GetDefinitionExtentOfSymbol(QueryableDatabase* db, const QueryTypeId& id) {
|
||||
return GetQueryable(db, id)->def.definition_extent;
|
||||
optional<QueryLocation> GetDefinitionExtentOfSymbol(QueryDatabase* db, const QueryTypeId& id) {
|
||||
return GetQuery(db, id)->def.definition_extent;
|
||||
}
|
||||
optional<QueryableLocation> GetDefinitionExtentOfSymbol(QueryableDatabase* db, const QueryFuncId& id) {
|
||||
return GetQueryable(db, id)->def.definition_extent;
|
||||
optional<QueryLocation> GetDefinitionExtentOfSymbol(QueryDatabase* db, const QueryFuncId& id) {
|
||||
return GetQuery(db, id)->def.definition_extent;
|
||||
}
|
||||
optional<QueryableLocation> GetDefinitionExtentOfSymbol(QueryableDatabase* db, const QueryVarId& id) {
|
||||
return GetQueryable(db, id)->def.definition_extent;
|
||||
optional<QueryLocation> GetDefinitionExtentOfSymbol(QueryDatabase* db, const QueryVarId& id) {
|
||||
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) {
|
||||
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<QueryableLocation> GetDefinitionExtentOfSymbol(QueryableDatabase* db, c
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
std::vector<QueryableLocation> GetDeclarationsOfSymbolForGotoDefinition(QueryableDatabase* db, const SymbolIdx& symbol) {
|
||||
std::vector<QueryLocation> 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<QueryableLocation> declaration = db->types[symbol.idx].def.definition_spelling;
|
||||
optional<QueryLocation> declaration = db->types[symbol.idx].def.definition_spelling;
|
||||
if (declaration)
|
||||
return { *declaration };
|
||||
break;
|
||||
@ -251,7 +233,7 @@ std::vector<QueryableLocation> GetDeclarationsOfSymbolForGotoDefinition(Queryabl
|
||||
case SymbolKind::Func:
|
||||
return db->funcs[symbol.idx].declarations;
|
||||
case SymbolKind::Var: {
|
||||
optional<QueryableLocation> declaration = db->vars[symbol.idx].def.declaration;
|
||||
optional<QueryLocation> declaration = db->vars[symbol.idx].def.declaration;
|
||||
if (declaration)
|
||||
return { *declaration };
|
||||
break;
|
||||
@ -261,41 +243,41 @@ std::vector<QueryableLocation> GetDeclarationsOfSymbolForGotoDefinition(Queryabl
|
||||
return {};
|
||||
}
|
||||
|
||||
optional<QueryableLocation> GetBaseDefinitionOrDeclarationSpelling(QueryableDatabase* db, QueryableFuncDef& func) {
|
||||
optional<QueryLocation> 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<QueryFuncRef> GetCallersForAllBaseFunctions(QueryableDatabase* db, QueryableFuncDef& root) {
|
||||
std::vector<QueryFuncRef> GetCallersForAllBaseFunctions(QueryDatabase* db, QueryFunc& root) {
|
||||
std::vector<QueryFuncRef> callers;
|
||||
|
||||
optional<QueryFuncId> 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<QueryFuncRef> GetCallersForAllDerivedFunctions(QueryableDatabase* db, QueryableFuncDef& root) {
|
||||
std::vector<QueryFuncRef> GetCallersForAllDerivedFunctions(QueryDatabase* db, QueryFunc& root) {
|
||||
std::vector<QueryFuncRef> callers;
|
||||
|
||||
std::queue<QueryFuncId> 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<lsRange> 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<lsLocation> GetLsLocation(QueryableDatabase* db, WorkingFiles* working_files, const QueryableLocation& location) {
|
||||
optional<lsLocation> GetLsLocation(QueryDatabase* db, WorkingFiles* working_files, const QueryLocation& location) {
|
||||
std::string path;
|
||||
lsDocumentUri uri = GetLsDocumentUri(db, location.path, &path);
|
||||
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.
|
||||
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<TCodeLens>* result;
|
||||
QueryableDatabase* db;
|
||||
QueryDatabase* db;
|
||||
WorkingFiles* working_files;
|
||||
WorkingFile* working_file;
|
||||
};
|
||||
|
||||
void AddCodeLens(
|
||||
CommonCodeLensParams* common,
|
||||
QueryableLocation loc,
|
||||
const std::vector<QueryableLocation>& uses,
|
||||
QueryLocation loc,
|
||||
const std::vector<QueryLocation>& uses,
|
||||
const char* singular,
|
||||
const char* plural,
|
||||
bool exclude_loc = false,
|
||||
@ -408,7 +390,7 @@ void AddCodeLens(
|
||||
|
||||
// Add unique uses.
|
||||
std::unordered_set<lsLocation> 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<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;
|
||||
|
||||
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<SymbolRef> FindSymbolsAtLocation(QueryableFile* file, lsPosition position) {
|
||||
std::vector<SymbolRef> FindSymbolsAtLocation(QueryFile* file, lsPosition position) {
|
||||
std::vector<SymbolRef> 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<Ipc_TextDocumentRename*>(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<QueryableLocation> uses = GetUsesOfSymbol(db, ref.idx);
|
||||
std::vector<QueryLocation> 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<Ipc_TextDocumentDefinition*>(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<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
|
||||
// highlight the entire definition when previewing / hoving with the
|
||||
// mouse.
|
||||
optional<QueryableLocation> def_extent = GetDefinitionExtentOfSymbol(db, ref.idx);
|
||||
optional<QueryLocation> 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<QueryableLocation> declarations = GetDeclarationsOfSymbolForGotoDefinition(db, ref.idx);
|
||||
std::vector<QueryLocation> declarations = GetDeclarationsOfSymbolForGotoDefinition(db, ref.idx);
|
||||
for (auto declaration : declarations) {
|
||||
optional<lsLocation> ls_declaration = GetLsLocation(db, working_files, declaration);
|
||||
if (ls_declaration)
|
||||
@ -1008,7 +990,7 @@ void QueryDbMainLoop(
|
||||
auto msg = static_cast<Ipc_TextDocumentDocumentHighlight*>(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<QueryableLocation> uses = GetUsesOfSymbol(db, ref.idx);
|
||||
std::vector<QueryLocation> 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<Ipc_TextDocumentHover*>(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<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)
|
||||
continue;
|
||||
|
||||
@ -1069,7 +1051,7 @@ void QueryDbMainLoop(
|
||||
case IpcId::TextDocumentReferences: {
|
||||
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) {
|
||||
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<QueryableLocation> excluded_declaration;
|
||||
optional<QueryLocation> 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<QueryableLocation> uses = GetUsesOfSymbol(db, ref.idx);
|
||||
std::vector<QueryLocation> 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<QueryFuncRef> 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<QueryableLocation> base_loc = GetBaseDefinitionOrDeclarationSpelling(db, func);
|
||||
optional<QueryLocation> base_loc = GetBaseDefinitionOrDeclarationSpelling(db, func);
|
||||
if (base_loc) {
|
||||
optional<lsLocation> 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<QueryableLocation> location = GetDefinitionExtentOfSymbol(db, db->symbols[i]);
|
||||
optional<QueryLocation> 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));
|
||||
|
116
src/query.cc
116
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<QueryableLocation> IdMap::ToQuery(optional<Range> range) const {
|
||||
optional<QueryLocation> IdMap::ToQuery(optional<Range> range) const {
|
||||
if (!range)
|
||||
return nullopt;
|
||||
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));
|
||||
return result;
|
||||
}
|
||||
std::vector<QueryableLocation> IdMap::ToQuery(std::vector<Range> ranges) const {
|
||||
return ToQueryTransform<Range, QueryableLocation>(*this, ranges);
|
||||
std::vector<QueryLocation> IdMap::ToQuery(std::vector<Range> ranges) const {
|
||||
return ToQueryTransform<Range, QueryLocation>(*this, ranges);
|
||||
}
|
||||
std::vector<QueryTypeId> IdMap::ToQuery(std::vector<IndexTypeId> ids) const {
|
||||
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())
|
||||
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<QueryableTypeDef::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> previous_remapped_def = ToQuery(previous_id_map, previous_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)
|
||||
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<QueryableFuncDef::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> previous_remapped_def = ToQuery(previous_id_map, previous_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)
|
||||
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<QueryableVarDef::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> previous_remapped_def = ToQuery(previous_id_map, previous_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)
|
||||
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<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
|
||||
// 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<Usr>& to_remove) {
|
||||
// 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) {
|
||||
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<QueryableTypeDef::DefUpdate>& updates) {
|
||||
void QueryDatabase::ImportOrUpdate(const std::vector<QueryType::DefUpdate>& updates) {
|
||||
for (auto& def : updates) {
|
||||
if (def.detailed_name.empty())
|
||||
continue;
|
||||
@ -629,7 +629,7 @@ void QueryableDatabase::ImportOrUpdate(const std::vector<QueryableTypeDef::DefUp
|
||||
auto it = usr_to_symbol.find(def.usr);
|
||||
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)
|
||||
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) {
|
||||
if (def.detailed_name.empty())
|
||||
continue;
|
||||
@ -646,7 +646,7 @@ void QueryableDatabase::ImportOrUpdate(const std::vector<QueryableFuncDef::DefUp
|
||||
auto it = usr_to_symbol.find(def.usr);
|
||||
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)
|
||||
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) {
|
||||
if (def.detailed_name.empty())
|
||||
continue;
|
||||
@ -663,7 +663,7 @@ void QueryableDatabase::ImportOrUpdate(const std::vector<QueryableVarDef::DefUpd
|
||||
auto it = usr_to_symbol.find(def.usr);
|
||||
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)
|
||||
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) \
|
||||
for (auto merge_update : update->update_var_name) { \
|
||||
auto* def = &storage_name[merge_update.id.id]; \
|
||||
|
141
src/query.h
141
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<QueryableFile>;
|
||||
using QueryTypeId = Id<QueryableTypeDef>;
|
||||
using QueryFuncId = Id<QueryableFuncDef>;
|
||||
using QueryVarId = Id<QueryableVarDef>;
|
||||
using QueryFileId = Id<QueryFile>;
|
||||
using QueryTypeId = Id<QueryType>;
|
||||
using QueryFuncId = Id<QueryFunc>;
|
||||
using QueryVarId = Id<QueryVar>;
|
||||
|
||||
|
||||
|
||||
@ -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<SymbolRef> 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<QueryTypeId, QueryFuncId, QueryVarId, QueryableLocation>;
|
||||
struct QueryType {
|
||||
using DefUpdate = TypeDefDefinitionData<QueryTypeId, QueryFuncId, QueryVarId, QueryLocation>;
|
||||
using DerivedUpdate = MergeableUpdate<QueryTypeId, QueryTypeId>;
|
||||
using InstantiationsUpdate = MergeableUpdate<QueryTypeId, QueryVarId>;
|
||||
using UsesUpdate = MergeableUpdate<QueryTypeId, QueryableLocation>;
|
||||
using UsesUpdate = MergeableUpdate<QueryTypeId, QueryLocation>;
|
||||
|
||||
DefUpdate def;
|
||||
std::vector<QueryTypeId> derived;
|
||||
std::vector<QueryVarId> instantiations;
|
||||
std::vector<QueryableLocation> uses;
|
||||
std::vector<QueryLocation> uses;
|
||||
size_t detailed_name_idx = -1;
|
||||
|
||||
QueryableTypeDef(const Usr& usr) : def(usr) {}
|
||||
QueryType(const Usr& usr) : def(usr) {}
|
||||
};
|
||||
|
||||
struct QueryableFuncDef {
|
||||
using DefUpdate = FuncDefDefinitionData<QueryTypeId, QueryFuncId, QueryVarId, QueryFuncRef, QueryableLocation>;
|
||||
using DeclarationsUpdate = MergeableUpdate<QueryFuncId, QueryableLocation>;
|
||||
struct QueryFunc {
|
||||
using DefUpdate = FuncDefDefinitionData<QueryTypeId, QueryFuncId, QueryVarId, QueryFuncRef, QueryLocation>;
|
||||
using DeclarationsUpdate = MergeableUpdate<QueryFuncId, QueryLocation>;
|
||||
using DerivedUpdate = MergeableUpdate<QueryFuncId, QueryFuncId>;
|
||||
using CallersUpdate = MergeableUpdate<QueryFuncId, QueryFuncRef>;
|
||||
|
||||
DefUpdate def;
|
||||
std::vector<QueryableLocation> declarations;
|
||||
std::vector<QueryLocation> declarations;
|
||||
std::vector<QueryFuncId> derived;
|
||||
std::vector<QueryFuncRef> 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<QueryTypeId, QueryFuncId, QueryVarId, QueryableLocation>;
|
||||
using UsesUpdate = MergeableUpdate<QueryVarId, QueryableLocation>;
|
||||
struct QueryVar {
|
||||
using DefUpdate = VarDefDefinitionData<QueryTypeId, QueryFuncId, QueryVarId, QueryLocation>;
|
||||
using UsesUpdate = MergeableUpdate<QueryVarId, QueryLocation>;
|
||||
|
||||
DefUpdate def;
|
||||
std::vector<QueryableLocation> uses;
|
||||
std::vector<QueryLocation> 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<Usr> files_removed;
|
||||
std::vector<QueryableFile::DefUpdate> files_def_update;
|
||||
std::vector<QueryFile::DefUpdate> files_def_update;
|
||||
|
||||
// Type updates.
|
||||
std::vector<Usr> types_removed;
|
||||
std::vector<QueryableTypeDef::DefUpdate> types_def_update;
|
||||
std::vector<QueryableTypeDef::DerivedUpdate> types_derived;
|
||||
std::vector<QueryableTypeDef::InstantiationsUpdate> types_instantiations;
|
||||
std::vector<QueryableTypeDef::UsesUpdate> types_uses;
|
||||
std::vector<QueryType::DefUpdate> types_def_update;
|
||||
std::vector<QueryType::DerivedUpdate> types_derived;
|
||||
std::vector<QueryType::InstantiationsUpdate> types_instantiations;
|
||||
std::vector<QueryType::UsesUpdate> types_uses;
|
||||
|
||||
// Function updates.
|
||||
std::vector<Usr> funcs_removed;
|
||||
std::vector<QueryableFuncDef::DefUpdate> funcs_def_update;
|
||||
std::vector<QueryableFuncDef::DeclarationsUpdate> funcs_declarations;
|
||||
std::vector<QueryableFuncDef::DerivedUpdate> funcs_derived;
|
||||
std::vector<QueryableFuncDef::CallersUpdate> funcs_callers;
|
||||
std::vector<QueryFunc::DefUpdate> funcs_def_update;
|
||||
std::vector<QueryFunc::DeclarationsUpdate> funcs_declarations;
|
||||
std::vector<QueryFunc::DerivedUpdate> funcs_derived;
|
||||
std::vector<QueryFunc::CallersUpdate> funcs_callers;
|
||||
|
||||
// Variable updates.
|
||||
std::vector<Usr> vars_removed;
|
||||
std::vector<QueryableVarDef::DefUpdate> vars_def_update;
|
||||
std::vector<QueryableVarDef::UsesUpdate> vars_uses;
|
||||
std::vector<QueryVar::DefUpdate> vars_def_update;
|
||||
std::vector<QueryVar::UsesUpdate> 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<std::string> detailed_names;
|
||||
std::vector<SymbolIdx> symbols;
|
||||
|
||||
// Raw data storage.
|
||||
std::vector<QueryableFile> files; // File path is stored as a Usr.
|
||||
std::vector<QueryableTypeDef> types;
|
||||
std::vector<QueryableFuncDef> funcs;
|
||||
std::vector<QueryableVarDef> vars;
|
||||
std::vector<QueryFile> files; // File path is stored as a Usr.
|
||||
std::vector<QueryType> types;
|
||||
std::vector<QueryFunc> funcs;
|
||||
std::vector<QueryVar> vars;
|
||||
|
||||
// Lookup symbol based on a usr.
|
||||
google::dense_hash_map<Usr, SymbolIdx> usr_to_symbol;
|
||||
|
||||
QueryableDatabase() {
|
||||
QueryDatabase() {
|
||||
usr_to_symbol.set_empty_key("");
|
||||
}
|
||||
//std::unordered_map<Usr, SymbolIdx> usr_to_symbol;
|
||||
@ -271,10 +266,10 @@ struct QueryableDatabase {
|
||||
void ApplyIndexUpdate(IndexUpdate* update);
|
||||
|
||||
void RemoveUsrs(const std::vector<Usr>& to_remove);
|
||||
void ImportOrUpdate(const std::vector<QueryableFile::DefUpdate>& updates);
|
||||
void ImportOrUpdate(const std::vector<QueryableTypeDef::DefUpdate>& updates);
|
||||
void ImportOrUpdate(const std::vector<QueryableFuncDef::DefUpdate>& updates);
|
||||
void ImportOrUpdate(const std::vector<QueryableVarDef::DefUpdate>& updates);
|
||||
void ImportOrUpdate(const std::vector<QueryFile::DefUpdate>& updates);
|
||||
void ImportOrUpdate(const std::vector<QueryType::DefUpdate>& updates);
|
||||
void ImportOrUpdate(const std::vector<QueryFunc::DefUpdate>& updates);
|
||||
void ImportOrUpdate(const std::vector<QueryVar::DefUpdate>& 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<QueryableLocation> ToQuery(optional<Range> range) const;
|
||||
optional<QueryLocation> ToQuery(optional<Range> range) const;
|
||||
optional<QueryTypeId> ToQuery(optional<IndexTypeId> id) const;
|
||||
optional<QueryFuncId> ToQuery(optional<IndexFuncId> id) const;
|
||||
optional<QueryVarId> ToQuery(optional<IndexVarId> id) 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<QueryFuncId> ToQuery(std::vector<IndexFuncId> ids) const;
|
||||
std::vector<QueryVarId> ToQuery(std::vector<IndexVarId> ids) const;
|
||||
|
Loading…
Reference in New Issue
Block a user