pipeline improvement for files not having a project entry (e.g. .h)

This commit is contained in:
Fangrui Song 2018-09-12 11:12:00 -07:00
parent f939b6cc44
commit c633ce437b
4 changed files with 32 additions and 32 deletions

View File

@ -27,10 +27,8 @@ struct Handler_TextDocumentDidChange
const auto &params = request->params;
std::string path = params.textDocument.uri.GetPath();
working_files->OnChange(params);
if (g_config->index.onChange) {
Project::Entry entry = project->FindCompilationEntryForFile(path);
pipeline::Index(entry.filename, entry.args, IndexMode::OnChange);
}
if (g_config->index.onChange)
pipeline::Index(path, {}, IndexMode::OnChange);
clang_complete->NotifyView(path);
if (g_config->diagnostics.onChange)
clang_complete->DiagnosticsUpdate(

View File

@ -57,12 +57,10 @@ struct Handler_TextDocumentDidOpen
// Submit new index request if it is not a header file.
if (SourceFileLanguage(path) != LanguageId::Unknown) {
Project::Entry entry = project->FindCompilationEntryForFile(path);
pipeline::Index(entry.filename,
params.args.size() ? params.args : entry.args,
IndexMode::Normal);
clang_complete->FlushSession(entry.filename);
pipeline::Index(
path, params.args.size() ? params.args : std::vector<std::string>{},
IndexMode::Normal);
clang_complete->FlushSession(path);
}
clang_complete->NotifyView(path);

View File

@ -33,9 +33,7 @@ struct Handler_TextDocumentDidSave
void Run(In_TextDocumentDidSave *request) override {
const auto &params = request->params;
std::string path = params.textDocument.uri.GetPath();
Project::Entry entry = project->FindCompilationEntryForFile(path);
pipeline::Index(entry.filename, entry.args, IndexMode::Normal);
pipeline::Index(path, {}, IndexMode::Normal);
clang_complete->NotifySave(path);
}
};

View File

@ -178,25 +178,23 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
return false;
}
Project::Entry entry;
{
std::lock_guard<std::mutex> lock(project->mutex_);
auto it = project->path_to_entry_index.find(request.path);
if (it != project->path_to_entry_index.end())
entry = project->entries[it->second];
else {
entry.filename = request.path;
entry.args = request.args;
}
}
Project::Entry entry = project->FindCompilationEntryForFile(request.path);
if (request.args.size())
entry.args = request.args;
std::string path_to_index = entry.filename;
std::unique_ptr<IndexFile> prev;
// Try to load the file from cache.
std::optional<int64_t> write_time = LastWriteTime(path_to_index);
if (!write_time)
return true;
int reparse = vfs->Stamp(path_to_index, *write_time);
if (request.path != path_to_index) {
std::optional<int64_t> mtime1 = LastWriteTime(request.path);
if (!mtime1)
return true;
if (vfs->Stamp(request.path, *mtime1))
reparse = 2;
}
if (g_config->index.onChange)
reparse = 2;
if (!vfs->Mark(path_to_index, g_thread_id, 1) && !reparse)
@ -245,8 +243,14 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
IndexUpdate update = IndexUpdate::CreateDelta(nullptr, prev.get());
on_indexed->PushBack(std::move(update),
request.mode != IndexMode::NonInteractive);
std::lock_guard lock(vfs->mutex);
vfs->state[path].loaded = true;
{
std::lock_guard lock(vfs->mutex);
vfs->state[path].loaded = true;
}
if (entry.id >= 0) {
std::lock_guard lock(project->mutex_);
project->path_to_entry_index[path] = entry.id;
}
}
}
return true;
@ -256,9 +260,9 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
std::vector<std::pair<std::string, std::string>> remapped;
if (g_config->index.onChange) {
std::string content = wfiles->GetContent(request.path);
std::string content = wfiles->GetContent(path_to_index);
if (content.size())
remapped.emplace_back(request.path, content);
remapped.emplace_back(path_to_index, content);
}
auto indexes = idx::Index(completion, wfiles, vfs, entry.directory,
path_to_index, entry.args, remapped);
@ -277,7 +281,7 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
for (std::unique_ptr<IndexFile> &curr : indexes) {
std::string path = curr->path;
bool do_update = path == path_to_index, loaded;
bool do_update = path == path_to_index || path == request.path, loaded;
{
std::lock_guard<std::mutex> lock(vfs->mutex);
VFS::State &st = vfs->state[path];
@ -288,11 +292,13 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
loaded = st.loaded;
st.loaded = true;
}
if (!do_update)
continue;
if (std::string reason; !matcher.IsMatch(path, &reason)) {
LOG_IF_S(INFO, loud) << "skip emitting and storing index of " << path << " for "
<< reason;
do_update = false;
}
if (!do_update) {
vfs->Reset(path);
continue;
}