diff --git a/src/command_line.cc b/src/command_line.cc index 8436c708..e8669a8f 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -178,7 +178,7 @@ void PushBack(NonElidedVector* result, optional location } QueryFile* FindFile(QueryDatabase* db, const std::string& filename, QueryFileId* file_id) { - auto it = db->usr_to_file.find(filename); + auto it = db->usr_to_file.find(LowerPathIfCaseInsensitive(filename)); if (it != db->usr_to_file.end()) { optional& file = db->files[it->second.id]; if (file) { @@ -193,8 +193,7 @@ QueryFile* FindFile(QueryDatabase* db, const std::string& filename, QueryFileId* } 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_file.find(filename); + auto it = db->usr_to_file.find(LowerPathIfCaseInsensitive(filename)); if (it != db->usr_to_file.end()) { optional& file = db->files[it->second.id]; if (file) diff --git a/src/query.cc b/src/query.cc index e5dd9859..f45d2e53 100644 --- a/src/query.cc +++ b/src/query.cc @@ -261,12 +261,12 @@ QueryFile::Def BuildFileDef(const IdMap& id_map, const IndexFile& indexed) { QueryFileId GetQueryFileIdFromPath(QueryDatabase* query_db, const std::string& path) { - auto it = query_db->usr_to_file.find(path); + auto it = query_db->usr_to_file.find(LowerPathIfCaseInsensitive(path)); if (it != query_db->usr_to_file.end()) return QueryFileId(it->second.id); size_t idx = query_db->files.size(); - query_db->usr_to_file[path] = QueryFileId(idx); + query_db->usr_to_file[LowerPathIfCaseInsensitive(path)] = QueryFileId(idx); query_db->files.push_back(QueryFile(path)); return QueryFileId(idx); } @@ -625,7 +625,7 @@ void QueryDatabase::RemoveUsrs(SymbolKind usr_kind, const std::vector& to_r switch (usr_kind) { case SymbolKind::File: { for (const Usr& usr : to_remove) - files[usr_to_file[usr].id] = nullopt; + files[usr_to_file[LowerPathIfCaseInsensitive(usr)].id] = nullopt; break; } case SymbolKind::Type: { @@ -691,7 +691,7 @@ void QueryDatabase::ImportOrUpdate(const std::vector& upda // This function runs on the querydb thread. for (auto& def : updates) { - auto it = usr_to_file.find(def.path); + auto it = usr_to_file.find(LowerPathIfCaseInsensitive(def.path)); assert(it != usr_to_file.end()); optional& existing = files[it->second.id]; diff --git a/src/query.h b/src/query.h index 69b5314f..d66f67b2 100644 --- a/src/query.h +++ b/src/query.h @@ -281,6 +281,8 @@ struct QueryDatabase { std::vector> vars; // Lookup symbol based on a usr. + // NOTE: For usr_to_file make sure to call LowerPathIfCaseInsensitive on key. + // TODO: add type wrapper to enforce we call it spp::sparse_hash_map usr_to_file; spp::sparse_hash_map usr_to_type; spp::sparse_hash_map usr_to_func; diff --git a/src/utils.cc b/src/utils.cc index c2ae783a..a0e7fd50 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -95,6 +95,15 @@ std::vector SplitString(const std::string& str, const std::string& return strings; } +std::string LowerPathIfCaseInsensitive(const std::string& path) { + std::string result = path; +#if defined(_WIN32) + for (size_t i = 0; i < result.size(); ++i) + result[i] = (char)tolower(result[i]); +#endif + return result; +} + static void GetFilesInFolderHelper( std::string folder, bool recursive, std::string output_prefix, const std::function& handler) { tinydir_dir dir; diff --git a/src/utils.h b/src/utils.h index 70150991..929fa8eb 100644 --- a/src/utils.h +++ b/src/utils.h @@ -23,6 +23,8 @@ std::string ReplaceAll(const std::string& source, const std::string& from, const std::vector SplitString(const std::string& str, const std::string& delimiter); +std::string LowerPathIfCaseInsensitive(const std::string& path); + template std::string StringJoin(const TValues& values) { std::string result;