Support indexing non-existent files in index.onChange:true mode

This commit is contained in:
Fangrui Song 2019-07-20 01:16:15 -07:00
parent 86a93b2d71
commit ab6498e2ff
3 changed files with 23 additions and 20 deletions

View File

@ -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;
}

View File

@ -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,9 +221,13 @@ bool Indexer_Parse(SemaManager *completion, WorkingFiles *wfiles,
std::string path_to_index = entry.filename;
std::unique_ptr<IndexFile> prev;
bool deleted = false, no_linkage = g_config->index.initialNoLinkage ||
bool deleted = request.mode == IndexMode::Delete,
no_linkage = g_config->index.initialNoLinkage ||
request.mode != IndexMode::Background;
int reparse = 0;
if (deleted)
reparse = 2;
else if (!(g_config->index.onChange && wfiles->GetFile(path_to_index))) {
std::optional<int64_t> write_time = LastWriteTime(path_to_index);
if (!write_time) {
deleted = true;
@ -239,8 +242,7 @@ bool Indexer_Parse(SemaManager *completion, WorkingFiles *wfiles,
reparse = 2;
}
}
if (deleted)
reparse = 2;
}
if (g_config->index.onChange) {
reparse = 2;

View File

@ -33,6 +33,7 @@ struct VFS {
};
enum class IndexMode {
Delete,
Background,
OnChange,
Normal,