mirror of
https://github.com/MaskRay/ccls.git
synced 2025-03-30 13:32:13 +00:00
optional<...> GetQuery*IdFromUsr -> Maybe
This commit is contained in:
parent
ae999f9c92
commit
e42f6b6191
@ -40,7 +40,8 @@ template <typename T>
|
|||||||
struct Id {
|
struct Id {
|
||||||
size_t id;
|
size_t id;
|
||||||
|
|
||||||
Id() : id(-1) {} // Needed for containers and Maybe<Id>. Do not use directly.
|
// Invalid id.
|
||||||
|
Id() : id(-1) {}
|
||||||
explicit Id(size_t id) : id(id) {}
|
explicit Id(size_t id) : id(id) {}
|
||||||
template <typename U>
|
template <typename U>
|
||||||
explicit Id(Id<U> o) : id(o.id) {}
|
explicit Id(Id<U> o) : id(o.id) {}
|
||||||
|
@ -124,7 +124,7 @@ optional<std::string> MessageRegistry::ReadMessageFromStdin(
|
|||||||
optional<std::string> content =
|
optional<std::string> content =
|
||||||
ReadJsonRpcContentFrom(&ReadCharFromStdinBlocking);
|
ReadJsonRpcContentFrom(&ReadCharFromStdinBlocking);
|
||||||
if (!content) {
|
if (!content) {
|
||||||
LOG_S(FATAL) << "Failed to read JsonRpc input; exiting";
|
LOG_S(ERROR) << "Failed to read JsonRpc input; exiting";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ class Maybe {
|
|||||||
public:
|
public:
|
||||||
constexpr Maybe() = default;
|
constexpr Maybe() = default;
|
||||||
Maybe(const Maybe&) = default;
|
Maybe(const Maybe&) = default;
|
||||||
|
Maybe(std::nullopt_t) {}
|
||||||
Maybe(const T& x) : storage(x) {}
|
Maybe(const T& x) : storage(x) {}
|
||||||
Maybe(T&& x) : storage(std::forward<T>(x)) {}
|
Maybe(T&& x) : storage(std::forward<T>(x)) {}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ std::vector<Out_CqueryCallTree::CallEntry> BuildExpandCallTree(
|
|||||||
// std::endl; return;
|
// std::endl; return;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
if (caller.has_id()) {
|
if (caller.HasValue()) {
|
||||||
QueryFunc& call_func = db->funcs[caller.id_.id];
|
QueryFunc& call_func = db->funcs[caller.id_.id];
|
||||||
if (!call_func.def)
|
if (!call_func.def)
|
||||||
return;
|
return;
|
||||||
@ -189,10 +189,10 @@ struct CqueryCallTreeExpandHandler
|
|||||||
out.id = request->id;
|
out.id = request->id;
|
||||||
|
|
||||||
// FIXME
|
// FIXME
|
||||||
optional<QueryFuncId> func_id =
|
Maybe<QueryFuncId> func_id =
|
||||||
db->GetQueryFuncIdFromUsr(std::stoull(request->params.usr));
|
db->GetQueryFuncIdFromUsr(std::stoull(request->params.usr));
|
||||||
if (func_id)
|
if (func_id)
|
||||||
out.result = BuildExpandCallTree(db, working_files, func_id.value());
|
out.result = BuildExpandCallTree(db, working_files, *func_id);
|
||||||
|
|
||||||
QueueManager::WriteStdout(IpcId::CqueryCallTreeExpand, out);
|
QueueManager::WriteStdout(IpcId::CqueryCallTreeExpand, out);
|
||||||
}
|
}
|
||||||
|
44
src/query.cc
44
src/query.cc
@ -294,9 +294,9 @@ QueryFile::DefUpdate BuildFileDefUpdate(const IdMap& id_map, const IndexFile& in
|
|||||||
return QueryFile::DefUpdate(def, indexed.file_contents);
|
return QueryFile::DefUpdate(def, indexed.file_contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline optional<QueryFileId> GetQueryFileIdFromPath(QueryDatabase* query_db,
|
Maybe<QueryFileId> GetQueryFileIdFromPath(QueryDatabase* query_db,
|
||||||
const std::string& path,
|
const std::string& path,
|
||||||
bool create_if_missing) {
|
bool create_if_missing) {
|
||||||
NormalizedPath normalized_path(path);
|
NormalizedPath normalized_path(path);
|
||||||
auto it = query_db->usr_to_file.find(normalized_path);
|
auto it = query_db->usr_to_file.find(normalized_path);
|
||||||
if (it != query_db->usr_to_file.end())
|
if (it != query_db->usr_to_file.end())
|
||||||
@ -310,9 +310,9 @@ inline optional<QueryFileId> GetQueryFileIdFromPath(QueryDatabase* query_db,
|
|||||||
return QueryFileId(idx);
|
return QueryFileId(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline optional<QueryTypeId> GetQueryTypeIdFromUsr(QueryDatabase* query_db,
|
Maybe<QueryTypeId> GetQueryTypeIdFromUsr(QueryDatabase* query_db,
|
||||||
Usr usr,
|
Usr usr,
|
||||||
bool create_if_missing) {
|
bool create_if_missing) {
|
||||||
auto it = query_db->usr_to_type.find(usr);
|
auto it = query_db->usr_to_type.find(usr);
|
||||||
if (it != query_db->usr_to_type.end())
|
if (it != query_db->usr_to_type.end())
|
||||||
return QueryTypeId(it->second.id);
|
return QueryTypeId(it->second.id);
|
||||||
@ -325,9 +325,9 @@ inline optional<QueryTypeId> GetQueryTypeIdFromUsr(QueryDatabase* query_db,
|
|||||||
return QueryTypeId(idx);
|
return QueryTypeId(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline optional<QueryFuncId> GetQueryFuncIdFromUsr(QueryDatabase* query_db,
|
Maybe<QueryFuncId> GetQueryFuncIdFromUsr(QueryDatabase* query_db,
|
||||||
Usr usr,
|
Usr usr,
|
||||||
bool create_if_missing) {
|
bool create_if_missing) {
|
||||||
auto it = query_db->usr_to_func.find(usr);
|
auto it = query_db->usr_to_func.find(usr);
|
||||||
if (it != query_db->usr_to_func.end())
|
if (it != query_db->usr_to_func.end())
|
||||||
return QueryFuncId(it->second.id);
|
return QueryFuncId(it->second.id);
|
||||||
@ -340,9 +340,9 @@ inline optional<QueryFuncId> GetQueryFuncIdFromUsr(QueryDatabase* query_db,
|
|||||||
return QueryFuncId(idx);
|
return QueryFuncId(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline optional<QueryVarId> GetQueryVarIdFromUsr(QueryDatabase* query_db,
|
Maybe<QueryVarId> GetQueryVarIdFromUsr(QueryDatabase* query_db,
|
||||||
Usr usr,
|
Usr usr,
|
||||||
bool create_if_missing) {
|
bool create_if_missing) {
|
||||||
auto it = query_db->usr_to_var.find(usr);
|
auto it = query_db->usr_to_var.find(usr);
|
||||||
if (it != query_db->usr_to_var.end())
|
if (it != query_db->usr_to_var.end())
|
||||||
return QueryVarId(it->second.id);
|
return QueryVarId(it->second.id);
|
||||||
@ -362,20 +362,20 @@ bool Maybe<QueryLocation>::has_value() const {
|
|||||||
return storage.range.start.line >= 0;
|
return storage.range.start.line >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<QueryFileId> QueryDatabase::GetQueryFileIdFromPath(
|
Maybe<QueryFileId> QueryDatabase::GetQueryFileIdFromPath(
|
||||||
const std::string& path) {
|
const std::string& path) {
|
||||||
return ::GetQueryFileIdFromPath(this, path, false);
|
return ::GetQueryFileIdFromPath(this, path, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<QueryTypeId> QueryDatabase::GetQueryTypeIdFromUsr(Usr usr) {
|
Maybe<QueryTypeId> QueryDatabase::GetQueryTypeIdFromUsr(Usr usr) {
|
||||||
return ::GetQueryTypeIdFromUsr(this, usr, false);
|
return ::GetQueryTypeIdFromUsr(this, usr, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<QueryFuncId> QueryDatabase::GetQueryFuncIdFromUsr(Usr usr) {
|
Maybe<QueryFuncId> QueryDatabase::GetQueryFuncIdFromUsr(Usr usr) {
|
||||||
return ::GetQueryFuncIdFromUsr(this, usr, false);
|
return ::GetQueryFuncIdFromUsr(this, usr, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<QueryVarId> QueryDatabase::GetQueryVarIdFromUsr(Usr usr) {
|
Maybe<QueryVarId> QueryDatabase::GetQueryVarIdFromUsr(Usr usr) {
|
||||||
return ::GetQueryVarIdFromUsr(this, usr, false);
|
return ::GetQueryVarIdFromUsr(this, usr, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,22 +383,22 @@ IdMap::IdMap(QueryDatabase* query_db, const IdCache& local_ids)
|
|||||||
: local_ids(local_ids) {
|
: local_ids(local_ids) {
|
||||||
// LOG_S(INFO) << "Creating IdMap for " << local_ids.primary_file;
|
// LOG_S(INFO) << "Creating IdMap for " << local_ids.primary_file;
|
||||||
primary_file =
|
primary_file =
|
||||||
GetQueryFileIdFromPath(query_db, local_ids.primary_file, true).value();
|
*GetQueryFileIdFromPath(query_db, local_ids.primary_file, true);
|
||||||
|
|
||||||
cached_type_ids_.resize(local_ids.type_id_to_usr.size());
|
cached_type_ids_.resize(local_ids.type_id_to_usr.size());
|
||||||
for (const auto& entry : local_ids.type_id_to_usr)
|
for (const auto& entry : local_ids.type_id_to_usr)
|
||||||
cached_type_ids_[entry.first] =
|
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());
|
cached_func_ids_.resize(local_ids.func_id_to_usr.size());
|
||||||
for (const auto& entry : local_ids.func_id_to_usr)
|
for (const auto& entry : local_ids.func_id_to_usr)
|
||||||
cached_func_ids_[entry.first] =
|
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());
|
cached_var_ids_.resize(local_ids.var_id_to_usr.size());
|
||||||
for (const auto& entry : local_ids.var_id_to_usr)
|
for (const auto& entry : local_ids.var_id_to_usr)
|
||||||
cached_var_ids_[entry.first] =
|
cached_var_ids_[entry.first] =
|
||||||
GetQueryVarIdFromUsr(query_db, entry.second, true).value();
|
*GetQueryVarIdFromUsr(query_db, entry.second, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryLocation IdMap::ToQuery(Range range) const {
|
QueryLocation IdMap::ToQuery(Range range) const {
|
||||||
@ -409,8 +409,8 @@ QueryTypeId IdMap::ToQuery(IndexTypeId id) const {
|
|||||||
return QueryTypeId(cached_type_ids_.find(id)->second);
|
return QueryTypeId(cached_type_ids_.find(id)->second);
|
||||||
}
|
}
|
||||||
QueryFuncId IdMap::ToQuery(IndexFuncId id) const {
|
QueryFuncId IdMap::ToQuery(IndexFuncId id) const {
|
||||||
if (id.id == -1)
|
if (id == IndexFuncId())
|
||||||
return QueryFuncId((size_t)-1);
|
return QueryFuncId();
|
||||||
assert(cached_func_ids_.find(id) != cached_func_ids_.end());
|
assert(cached_func_ids_.find(id) != cached_func_ids_.end());
|
||||||
return QueryFuncId(cached_func_ids_.find(id)->second);
|
return QueryFuncId(cached_func_ids_.find(id)->second);
|
||||||
}
|
}
|
||||||
|
10
src/query.h
10
src/query.h
@ -108,7 +108,7 @@ struct QueryFuncRef {
|
|||||||
QueryLocation loc;
|
QueryLocation loc;
|
||||||
bool is_implicit = false;
|
bool is_implicit = false;
|
||||||
|
|
||||||
bool has_id() const { return id_.id != static_cast<size_t>(-1); }
|
bool HasValue() const { return id_.HasValue(); }
|
||||||
|
|
||||||
QueryFuncRef() {} // Do not use, needed for reflect.
|
QueryFuncRef() {} // Do not use, needed for reflect.
|
||||||
QueryFuncRef(QueryFuncId id, QueryLocation loc, bool is_implicit)
|
QueryFuncRef(QueryFuncId id, QueryLocation loc, bool is_implicit)
|
||||||
@ -391,10 +391,10 @@ struct QueryDatabase {
|
|||||||
std::string_view GetSymbolShortName(size_t symbol_idx) const;
|
std::string_view GetSymbolShortName(size_t symbol_idx) const;
|
||||||
|
|
||||||
// Query the indexing structure to look up symbol id for given Usr.
|
// Query the indexing structure to look up symbol id for given Usr.
|
||||||
optional<QueryFileId> GetQueryFileIdFromPath(const std::string& path);
|
Maybe<QueryFileId> GetQueryFileIdFromPath(const std::string& path);
|
||||||
optional<QueryTypeId> GetQueryTypeIdFromUsr(Usr usr);
|
Maybe<QueryTypeId> GetQueryTypeIdFromUsr(Usr usr);
|
||||||
optional<QueryFuncId> GetQueryFuncIdFromUsr(Usr usr);
|
Maybe<QueryFuncId> GetQueryFuncIdFromUsr(Usr usr);
|
||||||
optional<QueryVarId> GetQueryVarIdFromUsr(Usr usr);
|
Maybe<QueryVarId> GetQueryVarIdFromUsr(Usr usr);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IdMap {
|
struct IdMap {
|
||||||
|
Loading…
Reference in New Issue
Block a user