diff --git a/src/import_pipeline.cc b/src/import_pipeline.cc index ab108947..5e79ba44 100644 --- a/src/import_pipeline.cc +++ b/src/import_pipeline.cc @@ -352,7 +352,7 @@ void ParseFile(Config* config, if (!indexes) { if (config->enableIndexing && - std::holds_alternative(request.id)) { + !std::holds_alternative(request.id)) { Out_Error out; out.id = request.id; out.error.code = lsErrorCodes::InternalError; diff --git a/src/messages/cquery_call_tree.cc b/src/messages/cquery_call_tree.cc index 8f0bdb9a..a768b47e 100644 --- a/src/messages/cquery_call_tree.cc +++ b/src/messages/cquery_call_tree.cc @@ -187,11 +187,10 @@ struct CqueryCallTreeExpandHandler Out_CqueryCallTree out; out.id = request->id; - // FIXME - optional func_id = - db->GetQueryFuncIdFromUsr(std::stoull(request->params.usr)); - if (func_id) - out.result = BuildExpandCallTree(db, working_files, func_id.value()); + // FIXME Change VSCode plugin to use number representation of USR hash + QueryFuncId func_id = db->GetQueryFuncIdFromUsr(std::stoull(request->params.usr)); + if (func_id.id != QueryFuncId::INVALID_ID) + out.result = BuildExpandCallTree(db, working_files, func_id); QueueManager::WriteStdout(IpcId::CqueryCallTreeExpand, out); } diff --git a/src/query.cc b/src/query.cc index 6277ce53..478614cf 100644 --- a/src/query.cc +++ b/src/query.cc @@ -281,14 +281,14 @@ QueryFile::Def BuildFileDef(const IdMap& id_map, const IndexFile& indexed) { } // namespace -optional GetQueryFileIdFromPath(QueryDatabase* query_db, +QueryFileId GetQueryFileIdFromPath(QueryDatabase* query_db, const std::string& path, bool create_if_missing) { auto it = query_db->usr_to_file.find(LowerPathIfCaseInsensitive(path)); if (it != query_db->usr_to_file.end()) return QueryFileId(it->second.id); if (!create_if_missing) - return {}; + return QueryFileId(QueryFileId::INVALID_ID); size_t idx = query_db->files.size(); query_db->usr_to_file[LowerPathIfCaseInsensitive(path)] = QueryFileId(idx); @@ -296,14 +296,14 @@ optional GetQueryFileIdFromPath(QueryDatabase* query_db, return QueryFileId(idx); } -optional GetQueryTypeIdFromUsr(QueryDatabase* query_db, +QueryTypeId GetQueryTypeIdFromUsr(QueryDatabase* query_db, Usr usr, bool create_if_missing) { auto it = query_db->usr_to_type.find(usr); if (it != query_db->usr_to_type.end()) return QueryTypeId(it->second.id); if (!create_if_missing) - return {}; + return QueryTypeId(QueryTypeId::INVALID_ID); size_t idx = query_db->types.size(); query_db->usr_to_type[usr] = QueryTypeId(idx); @@ -311,29 +311,28 @@ optional GetQueryTypeIdFromUsr(QueryDatabase* query_db, return QueryTypeId(idx); } -optional GetQueryFuncIdFromUsr(QueryDatabase* query_db, +QueryFuncId GetQueryFuncIdFromUsr(QueryDatabase* query_db, Usr usr, bool create_if_missing) { auto it = query_db->usr_to_func.find(usr); if (it != query_db->usr_to_func.end()) return QueryFuncId(it->second.id); if (!create_if_missing) - return {}; - + return QueryFuncId(QueryFuncId::INVALID_ID); size_t idx = query_db->funcs.size(); query_db->usr_to_func[usr] = QueryFuncId(idx); query_db->funcs.push_back(QueryFunc(usr)); return QueryFuncId(idx); } -optional GetQueryVarIdFromUsr(QueryDatabase* query_db, - Usr usr, - bool create_if_missing) { +QueryVarId GetQueryVarIdFromUsr(QueryDatabase* query_db, + Usr usr, + bool create_if_missing) { auto it = query_db->usr_to_var.find(usr); if (it != query_db->usr_to_var.end()) return QueryVarId(it->second.id); if (!create_if_missing) - return {}; + return QueryVarId(QueryVarId::INVALID_ID); size_t idx = query_db->vars.size(); query_db->usr_to_var[usr] = QueryVarId(idx); @@ -341,43 +340,42 @@ optional GetQueryVarIdFromUsr(QueryDatabase* query_db, return QueryVarId(idx); } -optional QueryDatabase::GetQueryFileIdFromPath( +QueryFileId QueryDatabase::GetQueryFileIdFromPath( const std::string& path) { return ::GetQueryFileIdFromPath(this, path, false); } -optional QueryDatabase::GetQueryTypeIdFromUsr(Usr usr) { +QueryTypeId QueryDatabase::GetQueryTypeIdFromUsr(Usr usr) { return ::GetQueryTypeIdFromUsr(this, usr, false); } -optional QueryDatabase::GetQueryFuncIdFromUsr(Usr usr) { +QueryFuncId QueryDatabase::GetQueryFuncIdFromUsr(Usr usr) { return ::GetQueryFuncIdFromUsr(this, usr, false); } -optional QueryDatabase::GetQueryVarIdFromUsr(Usr usr) { +QueryVarId QueryDatabase::GetQueryVarIdFromUsr(Usr usr) { return ::GetQueryVarIdFromUsr(this, usr, false); } IdMap::IdMap(QueryDatabase* query_db, const IdCache& local_ids) : local_ids(local_ids) { // LOG_S(INFO) << "Creating IdMap for " << local_ids.primary_file; - primary_file = - GetQueryFileIdFromPath(query_db, local_ids.primary_file, true).value(); + primary_file = GetQueryFileIdFromPath(query_db, local_ids.primary_file, true); cached_type_ids_.resize(local_ids.type_id_to_usr.size()); for (const auto& entry : local_ids.type_id_to_usr) cached_type_ids_[entry.first] = - GetQueryTypeIdFromUsr(query_db, entry.second, true).value(); + GetQueryTypeIdFromUsr(query_db, entry.second, true); cached_func_ids_.resize(local_ids.func_id_to_usr.size()); for (const auto& entry : local_ids.func_id_to_usr) cached_func_ids_[entry.first] = - GetQueryFuncIdFromUsr(query_db, entry.second, true).value(); + GetQueryFuncIdFromUsr(query_db, entry.second, true); cached_var_ids_.resize(local_ids.var_id_to_usr.size()); for (const auto& entry : local_ids.var_id_to_usr) cached_var_ids_[entry.first] = - GetQueryVarIdFromUsr(query_db, entry.second, true).value(); + GetQueryVarIdFromUsr(query_db, entry.second, true); } QueryLocation IdMap::ToQuery(Range range) const { diff --git a/src/query.h b/src/query.h index 91f21b88..f5a775d4 100644 --- a/src/query.h +++ b/src/query.h @@ -368,10 +368,12 @@ struct QueryDatabase { const std::string& detailed_name); // Query the indexing structure to look up symbol id for given Usr. - optional GetQueryFileIdFromPath(const std::string& path); - optional GetQueryTypeIdFromUsr(Usr usr); - optional GetQueryFuncIdFromUsr(Usr usr); - optional GetQueryVarIdFromUsr(Usr usr); + // In case the given Usr does not exist in the indexing structure, + // |INVALID_ID| will be returned + QueryFileId GetQueryFileIdFromPath(const std::string& path); + QueryTypeId GetQueryTypeIdFromUsr(Usr usr); + QueryFuncId GetQueryFuncIdFromUsr(Usr usr); + QueryVarId GetQueryVarIdFromUsr(Usr usr); }; struct IdMap {