From 843a86a4a92031ce91b64d46949811a0e76e22ed Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Wed, 29 Mar 2017 00:00:53 -0700 Subject: [PATCH] add asserts --- src/language_server_api.cc | 2 +- src/query.cc | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/language_server_api.cc b/src/language_server_api.cc index 6136558d..92b7f90d 100644 --- a/src/language_server_api.cc +++ b/src/language_server_api.cc @@ -122,7 +122,7 @@ void lsDocumentUri::SetPath(const std::string& path) { raw_uri = path; size_t index = raw_uri.find(":"); - if (index != -1) { + if (index == 1) { // widows drive letters must always be 1 char raw_uri.replace(raw_uri.begin() + index, raw_uri.begin() + index + 1, "%3A"); } diff --git a/src/query.cc b/src/query.cc index 25cffb6f..0323c21c 100644 --- a/src/query.cc +++ b/src/query.cc @@ -32,30 +32,47 @@ std::vector Transform(const std::vector& input, std::function result.push_back(op(in)); return result; } + +// TODO: These functions are failing. Investigate why. Usr MapIdToUsr(const IdCache& id_cache, const TypeId& id) { + assert(id_cache.type_id_to_usr.find(id) != id_cache.type_id_to_usr.end()); return id_cache.type_id_to_usr.find(id)->second; } Usr MapIdToUsr(const IdCache& id_cache, const FuncId& id) { + assert(id_cache.func_id_to_usr.find(id) != id_cache.func_id_to_usr.end()); return id_cache.func_id_to_usr.find(id)->second; } Usr MapIdToUsr(const IdCache& id_cache, const VarId& id) { + assert(id_cache.var_id_to_usr.find(id) != id_cache.var_id_to_usr.end()); return id_cache.var_id_to_usr.find(id)->second; } QueryableLocation MapIdToUsr(const IdCache& id_cache, const Location& id) { + assert(id_cache.file_id_to_file_path.find(id.file_id()) != id_cache.file_id_to_file_path.end()); return QueryableLocation(id_cache.file_id_to_file_path.find(id.file_id())->second, id.line, id.column, id.interesting); } std::vector MapIdToUsr(const IdCache& id_cache, const std::vector& ids) { - return Transform(ids, [&](TypeId id) { return id_cache.type_id_to_usr.find(id)->second; }); + return Transform(ids, [&](TypeId id) { + assert(id_cache.type_id_to_usr.find(id) != id_cache.type_id_to_usr.end()); + return id_cache.type_id_to_usr.find(id)->second; + }); } std::vector MapIdToUsr(const IdCache& id_cache, const std::vector& ids) { - return Transform(ids, [&](FuncId id) { return id_cache.func_id_to_usr.find(id)->second; }); + return Transform(ids, [&](FuncId id) { + assert(id_cache.func_id_to_usr.find(id) != id_cache.func_id_to_usr.end()); + return id_cache.func_id_to_usr.find(id)->second; + }); } std::vector MapIdToUsr(const IdCache& id_cache, const std::vector& ids) { - return Transform(ids, [&](VarId id) { return id_cache.var_id_to_usr.find(id)->second; }); + return Transform(ids, [&](VarId id) { + assert(id_cache.var_id_to_usr.find(id) != id_cache.var_id_to_usr.end()); + return id_cache.var_id_to_usr.find(id)->second; + }); } std::vector MapIdToUsr(const IdCache& id_cache, const std::vector& ids) { return Transform(ids, [&](FuncRef ref) { + assert(id_cache.func_id_to_usr.find(ref.id) != id_cache.func_id_to_usr.end()); + UsrRef result; result.loc = MapIdToUsr(id_cache, ref.loc); result.usr = id_cache.func_id_to_usr.find(ref.id)->second; @@ -64,6 +81,7 @@ std::vector MapIdToUsr(const IdCache& id_cache, const std::vector MapIdToUsr(const IdCache& id_cache, const std::vector& ids) { return Transform(ids, [&](Location id) { + assert(id_cache.file_id_to_file_path.find(id.file_id()) != id_cache.file_id_to_file_path.end()); return QueryableLocation(id_cache.file_id_to_file_path.find(id.file_id())->second, id.line, id.column, id.interesting); }); }