mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-31 18:00:26 +00:00
Fix removing entries from querydb.
I expect this will resolve most of the issues with the index getting messed up when actively editing a file.
This commit is contained in:
parent
b3d5327342
commit
9ae526089a
29
src/query.cc
29
src/query.cc
@ -828,5 +828,34 @@ TEST_CASE("type usages") {
|
|||||||
REQUIRE(update.types_uses[0].to_add[0].range == Range(Position(2, 0)));
|
REQUIRE(update.types_uses[0].to_add[0].range == Range(Position(2, 0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("apply delta") {
|
||||||
|
IndexFile previous("foo.cc");
|
||||||
|
IndexFile current("foo.cc");
|
||||||
|
|
||||||
|
IndexFunc* pf = previous.Resolve(previous.ToFuncId("usr"));
|
||||||
|
IndexFunc* cf = current.Resolve(current.ToFuncId("usr"));
|
||||||
|
pf->callers.push_back(IndexFuncRef(IndexFuncId(0), Range(Position(1, 0))));
|
||||||
|
pf->callers.push_back(IndexFuncRef(IndexFuncId(0), Range(Position(2, 0))));
|
||||||
|
cf->callers.push_back(IndexFuncRef(IndexFuncId(0), Range(Position(4, 0))));
|
||||||
|
cf->callers.push_back(IndexFuncRef(IndexFuncId(0), Range(Position(5, 0))));
|
||||||
|
|
||||||
|
QueryDatabase db;
|
||||||
|
IdMap previous_map(&db, previous.id_cache);
|
||||||
|
IdMap current_map(&db, current.id_cache);
|
||||||
|
REQUIRE(db.funcs.size() == 1);
|
||||||
|
|
||||||
|
IndexUpdate import_update = IndexUpdate::CreateDelta(nullptr, &previous_map, nullptr, &previous);
|
||||||
|
IndexUpdate delta_update = IndexUpdate::CreateDelta(&previous_map, ¤t_map, &previous, ¤t);
|
||||||
|
|
||||||
|
db.ApplyIndexUpdate(&import_update);
|
||||||
|
REQUIRE(db.funcs[0]->callers.size() == 2);
|
||||||
|
REQUIRE(db.funcs[0]->callers[0].loc.range == Range(Position(1, 0)));
|
||||||
|
REQUIRE(db.funcs[0]->callers[1].loc.range == Range(Position(2, 0)));
|
||||||
|
|
||||||
|
db.ApplyIndexUpdate(&delta_update);
|
||||||
|
REQUIRE(db.funcs[0]->callers.size() == 2);
|
||||||
|
REQUIRE(db.funcs[0]->callers[0].loc.range == Range(Position(4, 0)));
|
||||||
|
REQUIRE(db.funcs[0]->callers[1].loc.range == Range(Position(5, 0)));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_SUITE_END();
|
TEST_SUITE_END();
|
@ -75,12 +75,10 @@ void PushRange(std::queue<T>* dest, const std::vector<T>& to_add) {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void RemoveRange(std::vector<T>* dest, const std::vector<T>& to_remove) {
|
void RemoveRange(std::vector<T>* dest, const std::vector<T>& to_remove) {
|
||||||
auto it = std::remove_if(dest->begin(), dest->end(), [&](const T& t) {
|
dest->erase(std::remove_if(dest->begin(), dest->end(), [&](const T& t) {
|
||||||
// TODO: make to_remove a set?
|
// TODO: make to_remove a set?
|
||||||
return std::find(to_remove.begin(), to_remove.end(), t) != to_remove.end();
|
return std::find(to_remove.begin(), to_remove.end(), t) != to_remove.end();
|
||||||
});
|
}), dest->end());
|
||||||
if (it != dest->end())
|
|
||||||
dest->erase(it);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://stackoverflow.com/a/38140932
|
// http://stackoverflow.com/a/38140932
|
||||||
|
Loading…
Reference in New Issue
Block a user