From ab6498e2ffe992ca11bc04905cc034910cbde8d2 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 20 Jul 2019 01:16:15 -0700 Subject: [PATCH] Support indexing non-existent files in index.onChange:true mode --- src/messages/workspace.cc | 6 +++--- src/pipeline.cc | 36 +++++++++++++++++++----------------- src/pipeline.hh | 1 + 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/messages/workspace.cc b/src/messages/workspace.cc index 0a17d592..6036fe13 100644 --- a/src/messages/workspace.cc +++ b/src/messages/workspace.cc @@ -42,11 +42,11 @@ void MessageHandler::workspace_didChangeWatchedFiles( if (cur[0] == '.') return; - IndexMode mode = - wfiles->GetFile(path) ? IndexMode::Normal : IndexMode::Background; switch (event.type) { case FileChangeType::Created: case FileChangeType::Changed: { + IndexMode mode = + wfiles->GetFile(path) ? IndexMode::Normal : IndexMode::Background; pipeline::Index(path, {}, mode, true); if (event.type == FileChangeType::Changed) { if (mode == IndexMode::Normal) @@ -57,7 +57,7 @@ void MessageHandler::workspace_didChangeWatchedFiles( break; } case FileChangeType::Deleted: - pipeline::Index(path, {}, mode, false); + pipeline::Index(path, {}, IndexMode::Delete, false); manager->OnClose(path); break; } diff --git a/src/pipeline.cc b/src/pipeline.cc index 14f9341e..850c564e 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -212,7 +212,6 @@ bool Indexer_Parse(SemaManager *completion, WorkingFiles *wfiles, return false; } - // must_exist is currently unused. Project::Entry entry = project->FindEntry(request.path, true, request.must_exist); if (request.must_exist && entry.filename.empty()) @@ -222,25 +221,28 @@ bool Indexer_Parse(SemaManager *completion, WorkingFiles *wfiles, std::string path_to_index = entry.filename; std::unique_ptr prev; - bool deleted = false, no_linkage = g_config->index.initialNoLinkage || - request.mode != IndexMode::Background; + bool deleted = request.mode == IndexMode::Delete, + no_linkage = g_config->index.initialNoLinkage || + request.mode != IndexMode::Background; int reparse = 0; - std::optional write_time = LastWriteTime(path_to_index); - if (!write_time) { - deleted = true; - } else { - if (vfs->Stamp(path_to_index, *write_time, no_linkage ? 2 : 0)) - reparse = 1; - if (request.path != path_to_index) { - std::optional mtime1 = LastWriteTime(request.path); - if (!mtime1) - deleted = true; - else if (vfs->Stamp(request.path, *mtime1, no_linkage ? 2 : 0)) - reparse = 2; - } - } if (deleted) reparse = 2; + else if (!(g_config->index.onChange && wfiles->GetFile(path_to_index))) { + std::optional write_time = LastWriteTime(path_to_index); + if (!write_time) { + deleted = true; + } else { + if (vfs->Stamp(path_to_index, *write_time, no_linkage ? 2 : 0)) + reparse = 1; + if (request.path != path_to_index) { + std::optional mtime1 = LastWriteTime(request.path); + if (!mtime1) + deleted = true; + else if (vfs->Stamp(request.path, *mtime1, no_linkage ? 2 : 0)) + reparse = 2; + } + } + } if (g_config->index.onChange) { reparse = 2; diff --git a/src/pipeline.hh b/src/pipeline.hh index 7c6c64e9..ca48f94e 100644 --- a/src/pipeline.hh +++ b/src/pipeline.hh @@ -33,6 +33,7 @@ struct VFS { }; enum class IndexMode { + Delete, Background, OnChange, Normal,