mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 09:05:10 +00:00
pipeline improvement for files not having a project entry (e.g. .h)
This commit is contained in:
parent
f939b6cc44
commit
c633ce437b
@ -27,10 +27,8 @@ struct Handler_TextDocumentDidChange
|
|||||||
const auto ¶ms = request->params;
|
const auto ¶ms = request->params;
|
||||||
std::string path = params.textDocument.uri.GetPath();
|
std::string path = params.textDocument.uri.GetPath();
|
||||||
working_files->OnChange(params);
|
working_files->OnChange(params);
|
||||||
if (g_config->index.onChange) {
|
if (g_config->index.onChange)
|
||||||
Project::Entry entry = project->FindCompilationEntryForFile(path);
|
pipeline::Index(path, {}, IndexMode::OnChange);
|
||||||
pipeline::Index(entry.filename, entry.args, IndexMode::OnChange);
|
|
||||||
}
|
|
||||||
clang_complete->NotifyView(path);
|
clang_complete->NotifyView(path);
|
||||||
if (g_config->diagnostics.onChange)
|
if (g_config->diagnostics.onChange)
|
||||||
clang_complete->DiagnosticsUpdate(
|
clang_complete->DiagnosticsUpdate(
|
||||||
|
@ -57,12 +57,10 @@ struct Handler_TextDocumentDidOpen
|
|||||||
|
|
||||||
// Submit new index request if it is not a header file.
|
// Submit new index request if it is not a header file.
|
||||||
if (SourceFileLanguage(path) != LanguageId::Unknown) {
|
if (SourceFileLanguage(path) != LanguageId::Unknown) {
|
||||||
Project::Entry entry = project->FindCompilationEntryForFile(path);
|
pipeline::Index(
|
||||||
pipeline::Index(entry.filename,
|
path, params.args.size() ? params.args : std::vector<std::string>{},
|
||||||
params.args.size() ? params.args : entry.args,
|
IndexMode::Normal);
|
||||||
IndexMode::Normal);
|
clang_complete->FlushSession(path);
|
||||||
|
|
||||||
clang_complete->FlushSession(entry.filename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clang_complete->NotifyView(path);
|
clang_complete->NotifyView(path);
|
||||||
|
@ -33,9 +33,7 @@ struct Handler_TextDocumentDidSave
|
|||||||
void Run(In_TextDocumentDidSave *request) override {
|
void Run(In_TextDocumentDidSave *request) override {
|
||||||
const auto ¶ms = request->params;
|
const auto ¶ms = request->params;
|
||||||
std::string path = params.textDocument.uri.GetPath();
|
std::string path = params.textDocument.uri.GetPath();
|
||||||
|
pipeline::Index(path, {}, IndexMode::Normal);
|
||||||
Project::Entry entry = project->FindCompilationEntryForFile(path);
|
|
||||||
pipeline::Index(entry.filename, entry.args, IndexMode::Normal);
|
|
||||||
clang_complete->NotifySave(path);
|
clang_complete->NotifySave(path);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -178,25 +178,23 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Project::Entry entry;
|
Project::Entry entry = project->FindCompilationEntryForFile(request.path);
|
||||||
{
|
if (request.args.size())
|
||||||
std::lock_guard<std::mutex> lock(project->mutex_);
|
entry.args = request.args;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::string path_to_index = entry.filename;
|
std::string path_to_index = entry.filename;
|
||||||
std::unique_ptr<IndexFile> prev;
|
std::unique_ptr<IndexFile> prev;
|
||||||
|
|
||||||
// Try to load the file from cache.
|
|
||||||
std::optional<int64_t> write_time = LastWriteTime(path_to_index);
|
std::optional<int64_t> write_time = LastWriteTime(path_to_index);
|
||||||
if (!write_time)
|
if (!write_time)
|
||||||
return true;
|
return true;
|
||||||
int reparse = vfs->Stamp(path_to_index, *write_time);
|
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)
|
if (g_config->index.onChange)
|
||||||
reparse = 2;
|
reparse = 2;
|
||||||
if (!vfs->Mark(path_to_index, g_thread_id, 1) && !reparse)
|
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());
|
IndexUpdate update = IndexUpdate::CreateDelta(nullptr, prev.get());
|
||||||
on_indexed->PushBack(std::move(update),
|
on_indexed->PushBack(std::move(update),
|
||||||
request.mode != IndexMode::NonInteractive);
|
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;
|
return true;
|
||||||
@ -256,9 +260,9 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
|
|||||||
|
|
||||||
std::vector<std::pair<std::string, std::string>> remapped;
|
std::vector<std::pair<std::string, std::string>> remapped;
|
||||||
if (g_config->index.onChange) {
|
if (g_config->index.onChange) {
|
||||||
std::string content = wfiles->GetContent(request.path);
|
std::string content = wfiles->GetContent(path_to_index);
|
||||||
if (content.size())
|
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,
|
auto indexes = idx::Index(completion, wfiles, vfs, entry.directory,
|
||||||
path_to_index, entry.args, remapped);
|
path_to_index, entry.args, remapped);
|
||||||
@ -277,7 +281,7 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
|
|||||||
|
|
||||||
for (std::unique_ptr<IndexFile> &curr : indexes) {
|
for (std::unique_ptr<IndexFile> &curr : indexes) {
|
||||||
std::string path = curr->path;
|
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);
|
std::lock_guard<std::mutex> lock(vfs->mutex);
|
||||||
VFS::State &st = vfs->state[path];
|
VFS::State &st = vfs->state[path];
|
||||||
@ -288,11 +292,13 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
|
|||||||
loaded = st.loaded;
|
loaded = st.loaded;
|
||||||
st.loaded = true;
|
st.loaded = true;
|
||||||
}
|
}
|
||||||
if (!do_update)
|
|
||||||
continue;
|
|
||||||
if (std::string reason; !matcher.IsMatch(path, &reason)) {
|
if (std::string reason; !matcher.IsMatch(path, &reason)) {
|
||||||
LOG_IF_S(INFO, loud) << "skip emitting and storing index of " << path << " for "
|
LOG_IF_S(INFO, loud) << "skip emitting and storing index of " << path << " for "
|
||||||
<< reason;
|
<< reason;
|
||||||
|
do_update = false;
|
||||||
|
}
|
||||||
|
if (!do_update) {
|
||||||
|
vfs->Reset(path);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user