Skip to content

Commit

Permalink
Add a --wait option for --reindex
Browse files Browse the repository at this point in the history
  • Loading branch information
Andersbakken committed Jun 11, 2015
1 parent b85f025 commit 49494fe
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 18 deletions.
7 changes: 7 additions & 0 deletions src/IndexerJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ IndexerJob::IndexerJob(const Source &s,
visited.insert(s.fileId);
}

IndexerJob::~IndexerJob()
{
destroyed(this);
}

void IndexerJob::acquireId()
{
id = sNextId++;
Expand Down Expand Up @@ -154,3 +159,5 @@ String IndexerJob::dumpFlags(Flags<Flag> flags)

return String::join(ret, ", ");
}


2 changes: 2 additions & 0 deletions src/IndexerJob.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class IndexerJob
Flags<Flag> flags,
const std::shared_ptr<Project> &project,
const UnsavedFiles &unsavedFiles = UnsavedFiles());
~IndexerJob();
void acquireId();
String encode() const;

Expand All @@ -58,6 +59,7 @@ class IndexerJob
UnsavedFiles unsavedFiles;
Set<uint32_t> visited;
int crashCount;
Signal<std::function<void(IndexerJob *)> > destroyed;
private:
static uint64_t sNextId;
};
Expand Down
18 changes: 14 additions & 4 deletions src/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,9 @@ void Project::updateDeclarations(const Set<uint32_t> &visited, Declarations &dec
}
}

int Project::reindex(const Match &match, const std::shared_ptr<QueryMessage> &query)
int Project::reindex(const Match &match,
const std::shared_ptr<QueryMessage> &query,
const std::shared_ptr<Connection> &wait)
{
if (query->type() == QueryMessage::Reindex) {
Set<uint32_t> dirtyFiles;
Expand All @@ -954,11 +956,11 @@ int Project::reindex(const Match &match, const std::shared_ptr<QueryMessage> &qu
return 0;
SimpleDirty dirty;
dirty.init(dirtyFiles, shared_from_this());
return startDirtyJobs(&dirty, query->unsavedFiles());
return startDirtyJobs(&dirty, query->unsavedFiles(), wait);
} else {
assert(query->type() == QueryMessage::CheckReindex);
IfModifiedDirty dirty(shared_from_this(), match);
return startDirtyJobs(&dirty, query->unsavedFiles());
return startDirtyJobs(&dirty, query->unsavedFiles(), wait);
}
}

Expand Down Expand Up @@ -986,7 +988,7 @@ int Project::remove(const Match &match)
return count;
}

int Project::startDirtyJobs(Dirty *dirty, const UnsavedFiles &unsavedFiles)
int Project::startDirtyJobs(Dirty *dirty, const UnsavedFiles &unsavedFiles, const std::shared_ptr<Connection> &wait)
{
const JobScheduler::JobScope scope(Server::instance()->jobScheduler());
List<Source> toIndex;
Expand All @@ -1004,8 +1006,16 @@ int Project::startDirtyJobs(Dirty *dirty, const UnsavedFiles &unsavedFiles)
}
}

std::weak_ptr<Connection> weakConn(wait);
for (const auto &source : toIndex) {
std::shared_ptr<IndexerJob> job(new IndexerJob(source, IndexerJob::Dirty, shared_from_this(), unsavedFiles));
if (wait) {
job->destroyed.connect([weakConn](IndexerJob *) {
if (auto strong = weakConn.lock()) {
strong->finish();
}
});
}
index(job);
}

Expand Down
8 changes: 6 additions & 2 deletions src/Project.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ class Project : public std::enable_shared_from_this<Project>
inline bool visitFile(uint32_t fileId, const Path &path, uint64_t id);
inline void releaseFileIds(const Set<uint32_t> &fileIds);
String fixIts(uint32_t fileId) const;
int reindex(const Match &match, const std::shared_ptr<QueryMessage> &query);
int reindex(const Match &match,
const std::shared_ptr<QueryMessage> &query,
const std::shared_ptr<Connection> &wait);
int remove(const Match &match);
void onJobFinished(const std::shared_ptr<IndexerJob> &job, const std::shared_ptr<IndexDataMessage> &msg);
Sources sources() const { return mSources; }
Expand Down Expand Up @@ -198,7 +200,9 @@ class Project : public std::enable_shared_from_this<Project>
void updateDependencies(const std::shared_ptr<IndexDataMessage> &msg);
void updateDeclarations(const Set<uint32_t> &visited, Declarations &declarations);
void updateFixIts(const Set<uint32_t> &visited, FixIts &fixIts);
int startDirtyJobs(Dirty *dirty, const UnsavedFiles &unsavedFiles = UnsavedFiles());
int startDirtyJobs(Dirty *dirty,
const UnsavedFiles &unsavedFiles = UnsavedFiles(),
const std::shared_ptr<Connection> &wait = std::shared_ptr<Connection>());
bool save();
void onDirtyTimeout(Timer *);

Expand Down
3 changes: 2 additions & 1 deletion src/QueryMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ class QueryMessage : public RTagsMessage
WildcardSymbolNames = 0x020000000,
NoColor = 0x040000000,
Rename = 0x080000000,
ContainingFunction = 0x100000000
ContainingFunction = 0x100000000,
Wait = 0x200000000
};

QueryMessage(Type type = Invalid);
Expand Down
6 changes: 5 additions & 1 deletion src/RClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ struct Option opts[] = {
{ RClient::ProjectRoot, "project-root", 0, required_argument, "Override project root for compile commands." },
{ RClient::RTagsConfig, "rtags-config", 0, required_argument, "Print out .rtags-config for argument." },
{ RClient::WildcardSymbolNames, "wildcard-symbol-names", 'a', no_argument, "Expand * like wildcards in --list-symbols and --find-symbols." },
{ RClient::NoColor, "no-color", 0, no_argument, "Don't colorize context. " },
{ RClient::NoColor, "no-color", 0, no_argument, "Don't colorize context." },
{ RClient::Wait, "wait", 0, no_argument, "Wait for reindexing to finish." },
{ RClient::None, 0, 0, 0, 0 }
};

Expand Down Expand Up @@ -553,6 +554,9 @@ RClient::ParseStatus RClient::parse(int &argc, char **argv)
case GuessFlags:
mGuessFlags = true;
break;
case Wait:
mQueryFlags |= QueryMessage::Wait;
break;
case IMenu:
mQueryFlags |= QueryMessage::IMenu;
break;
Expand Down
1 change: 1 addition & 0 deletions src/RClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class RClient
UnsavedFile,
Verbose,
Version,
Wait,
WildcardSymbolNames,
XmlDiagnostics,
NumOptions
Expand Down
25 changes: 15 additions & 10 deletions src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,19 @@ bool Server::initUnixServer()
// If Launchd, it goes into this bit and never comes out.
if (mOptions.options & Launchd) {
mUnixServer.reset(new SocketServer);

printf("initUnixServer: launchd mode.\n");

bool good = false;
int *fds = 0;
size_t numFDs;
int ret = launch_activate_socket("Listener", &fds, &numFDs);

if (ret != 0) {
error("Failed to retrieve launchd socket: %s", strerror(ret));
goto launchd_done;
}

if (numFDs != 1) {
error("Unexpected number of sockets from launch_activate_socket: %zu", numFDs);
goto launchd_done;
Expand All @@ -269,7 +269,7 @@ bool Server::initUnixServer()
launchd_done:;
free(fds);
fds = 0;

return good;
}
#endif
Expand Down Expand Up @@ -297,7 +297,7 @@ bool Server::initUnixServer()
}

return true;
}
}

std::shared_ptr<Project> Server::addProject(const Path &path)
{
Expand Down Expand Up @@ -1165,14 +1165,19 @@ void Server::reindex(const std::shared_ptr<QueryMessage> &query, const std::shar
}
}

const int count = project->reindex(match, query);
std::shared_ptr<Connection> wait;
if (query->flags() & QueryMessage::Wait)
wait = conn;

const int count = project->reindex(match, query, wait);
// error() << count << query->query();
if (count) {
conn->write<128>("Dirtied %d files", count);
} else {
conn->write("No matches");
}
conn->finish();
if (!wait)
conn->finish();
}

bool Server::shouldIndex(const Source &source, const Path &srcRoot) const
Expand Down Expand Up @@ -1622,14 +1627,14 @@ void Server::removeSocketFile()
return;
}
#endif

Path::rm(mOptions.socketFile);
}

void Server::stopServers()
{
removeSocketFile();

mUnixServer.reset();
}

Expand Down

0 comments on commit 49494fe

Please sign in to comment.