Skip to content

Commit

Permalink
Handle removal of compile_commands.json better
Browse files Browse the repository at this point in the history
  • Loading branch information
Andersbakken committed May 24, 2019
1 parent a422b1f commit a66e5c7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/IndexParseData.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ class IndexParseData
return *this;
}

void clearSources()
{
lastModifiedMs = 0;
sources.clear();
}

uint64_t lastModifiedMs;
Sources sources;
List<String> environment;
Expand Down
20 changes: 9 additions & 11 deletions src/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ void Project::onFileAdded(const Path &path)

void Project::onFileAddedOrModified(const Path &file, uint32_t fileId)
{
// error() << file.fileName() << mCompileCommandsInfos.dir << file;
// error() << file.fileName() << fileId << mIndexParseData.compileCommands.keys();
if (mIndexParseData.compileCommands.contains(fileId)) {
mCheckTimer.restart(CheckExplicitTimeout);
return;
Expand Down Expand Up @@ -2543,23 +2543,21 @@ void Project::reloadCompileCommands()
data.project = mPath;
data.environment = mIndexParseData.environment;
bool found = false;
auto it = mIndexParseData.compileCommands.begin();
while (it != mIndexParseData.compileCommands.end()) {

for (auto it = mIndexParseData.compileCommands.begin(); it != mIndexParseData.compileCommands.end(); ++it) {
const Path file = Location::path(it->first);
const uint64_t lastModified = file.lastModifiedMs();
if (!lastModified) {
for (auto src : it->second.sources) {
removed[src.first] = it->first;
}
mIndexParseData.compileCommands.erase(it++);
continue;
}

if (lastModified != it->second.lastModifiedMs
&& Server::instance()->loadCompileCommands(data, file, it->second.environment, &cache)) {
found = true;
it->second.clearSources();
} else {
if (lastModified != it->second.lastModifiedMs
&& Server::instance()->loadCompileCommands(data, file, it->second.environment, &cache)) {
found = true;
}
}
++it;
}
removeSources(removed);
if (found)
Expand Down
1 change: 0 additions & 1 deletion src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2593,7 +2593,6 @@ void Server::sourceFileModified(const std::shared_ptr<Project> &project, uint32_
// error() << Location::path(fileId) << "modified" << (mCompletionThread ? (mCompletionThread->isCached(project, fileId) ? 1 : 0) : -1);
if (mCompletionThread && mCompletionThread->isCached(project, fileId)) {
mCompletionThread->reparse(project, fileId);

}
}

Expand Down

0 comments on commit a66e5c7

Please sign in to comment.