Skip to content

Commit

Permalink
More work.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andersbakken committed Oct 20, 2016
1 parent 7a89b8d commit ce5cdbd
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 34 deletions.
8 changes: 0 additions & 8 deletions src/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,6 @@ static String formatDiagnostics(const Diagnostics &diagnostics, Flags<QueryMessa

void Project::onJobFinished(const std::shared_ptr<IndexerJob> &job, const std::shared_ptr<IndexDataMessage> &msg)
{
error() << "GOT A JOB" << Location::path(msg->fileId()) << Location::path(job->fileId()) << job.get();
mBytesWritten += msg->bytesWritten();
std::shared_ptr<IndexerJob> restart;
const uint32_t fileId = msg->fileId();
Expand Down Expand Up @@ -936,13 +935,6 @@ void Project::onDirtyTimeout(Timer *)
debug() << "onDirtyTimeout" << dirtyFiles << dirtied;
}

Sources Project::sources() const
{
Sources ret;
forEachSources([&ret](const Sources &srcs) { ret += srcs; return Continue; });
return ret;
}

Set<Source> Project::sources(uint32_t fileId) const
{
Set<Source> ret;
Expand Down
3 changes: 1 addition & 2 deletions src/Project.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ class Project : public std::enable_shared_from_this<Project>
const IndexParseData &indexParseData() const { return mIndexParseData; }
void index(const std::shared_ptr<IndexerJob> &job);
void reindex(uint32_t fileId, Flags<IndexerJob::Flag> flags);
Sources sources() const;
Set<Source> sources(uint32_t fileId) const;
Source source(uint32_t fileId, int buildIndex) const;
bool hasSource(uint32_t fileId) const;
Expand Down Expand Up @@ -235,7 +234,6 @@ class Project : public std::enable_shared_from_this<Project>
void includeCompletions(Flags<QueryMessage::Flag> flags, const std::shared_ptr<Connection> &conn, Source &&source) const;
size_t bytesWritten() const { return mBytesWritten; }
void destroy() { mSaveDirty = false; }
private:
enum VisitResult {
Stop,
Continue,
Expand All @@ -252,6 +250,7 @@ class Project : public std::enable_shared_from_this<Project>
static void forEachSource(const IndexParseData &data, std::function<VisitResult(const Source &source)> cb);
void forEachSource(std::function<VisitResult(const Source &source)> cb) const { forEachSource(mIndexParseData, cb); }
void forEachSource(std::function<VisitResult(Source &source)> cb) { forEachSource(mIndexParseData, cb); }
private:

void reloadCompileCommands();
void onFileAddedOrModified(const Path &path);
Expand Down
28 changes: 10 additions & 18 deletions src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ bool Server::loadCompileCommands(IndexParseData &data, const Path &compileComman
error("Can't load compilation database from %scompile_Commands.json", compileCommands.constData());
return false;
}
const uint32_t fileId = Location::insertFile(compileCommands);
const uint32_t fileId = Location::insertFile(compileCommands + "compile_commands.json");
bool ret = false;
CXCompileCommands cmds = clang_CompilationDatabase_getAllCompileCommands(db);
const unsigned int sz = clang_CompileCommands_getSize(cmds);
Expand Down Expand Up @@ -608,20 +608,14 @@ void Server::handleIndexMessage(const std::shared_ptr<IndexMessage> &message, co
if (conn)
conn->finish(ret ? 0 : 1);
if (ret) {
processParseData(std::move(data));
auto proj = addProject(data.project);
assert(proj);
proj->processParseData(std::move(data));
if (!currentProject())
setCurrentProject(proj);
}
}

void Server::processParseData(IndexParseData &&data)
{
assert(!data.project.isEmpty());
auto proj = addProject(data.project);
assert(proj);
proj->processParseData(std::forward<IndexParseData>(data));
if (!currentProject())
setCurrentProject(proj);
}

void Server::handleLogOutputMessage(const std::shared_ptr<LogOutputMessage> &message, const std::shared_ptr<Connection> &conn)
{
std::shared_ptr<RTagsLogOutput> log(new RTagsLogOutput(message->level(), message->flags(), conn));
Expand Down Expand Up @@ -1652,14 +1646,12 @@ void Server::sources(const std::shared_ptr<QueryMessage> &query, const std::shar

if (std::shared_ptr<Project> project = currentProject()) {
const Match match = query->match();
const Sources infos = project->sources();
for (const auto &it : infos) {
if (match.isEmpty() || match.match(Location::path(it.first))) {
for (const Source &src : it.second) {
project->forEachSource([&conn, &match, &format](const Source &src) {
if (match.isEmpty() || match.match(src.sourceFile())) {
conn->write(format(src));
}
}
}
return Project::Continue;
});
} else {
conn->write("No project");
}
Expand Down
1 change: 0 additions & 1 deletion src/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ class Server
std::shared_ptr<Project> currentProject() const { return mCurrentProject.lock(); }
void onNewMessage(const std::shared_ptr<Message> &message, const std::shared_ptr<Connection> &conn);
bool saveFileIds();
void processParseData(IndexParseData &&data);
bool loadCompileCommands(IndexParseData &data, const Path &compileCommands, const List<String> &environment) const;
bool parse(IndexParseData &data, String &&arguments, const Path &pwd, uint32_t compileCommandsFileId = 0) const;
enum FileIdsFileFlag {
Expand Down
26 changes: 21 additions & 5 deletions src/StatusJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,30 @@ int StatusJob::execute()

if (query.isEmpty() || match("sources")) {
matched = true;
const Sources &map = proj->sources();
if (!write(delimiter) || !write("sources") || !write(delimiter))
return 1;
for (const auto &ss : map) {
for (const auto &s : ss.second) {
if (!write<512>(" %s: %s", s.sourceFile().constData(), s.toString().constData()))
return 1;
const auto &sources = proj->indexParseData();

auto process = [this](const String &str, const Sources &sss) {
if (!sss.isEmpty()) {
if (!write<512>("%s:", str.constData()))
return false;

for (const auto &ss : sss) {
for (const auto &s : ss.second) {
if (!write<512>(" %s: %s", s.sourceFile().constData(), s.toString().constData()))
return false;
}
}
}
return true;
};
if (!process("Sources", sources.sources))
return 1;

for (const auto &commands : sources.compileCommands) {
if (!process(Location::path(commands.first), commands.second.sources))
return 1;
}
}

Expand Down

0 comments on commit ce5cdbd

Please sign in to comment.