From 3ef0abec1498f88a2eb8e697a79537a45960474a Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 25 Jan 2018 23:04:07 -0800 Subject: [PATCH] WIP DidChangeWatchedFiles --- .../workspace_did_change_watched_files.cc | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/messages/workspace_did_change_watched_files.cc b/src/messages/workspace_did_change_watched_files.cc index 51e6ef49..d1e6c598 100644 --- a/src/messages/workspace_did_change_watched_files.cc +++ b/src/messages/workspace_did_change_watched_files.cc @@ -1,5 +1,10 @@ +#include "clang_complete.h" #include "message_handler.h" +#include "project.h" #include "queue_manager.h" +#include "working_files.h" + +#include namespace { enum class lsFileChangeType { @@ -33,16 +38,27 @@ struct WorkspaceDidChangeWatchedFilesHandler : BaseMessageHandler { void Run(Ipc_WorkspaceDidChangeWatchedFiles* request) override { for (lsFileEvent& event : request->params.changes) { + std::string path = event.uri.GetPath(); switch (event.type) { case lsFileChangeType::Created: - // TODO + // TODO + case lsFileChangeType::Changed: { + Project::Entry entry = project->FindCompilationEntryForFile(path); + optional content = ReadContent(path); + if (!content) + LOG_S(ERROR) << "Unable to read file content after saving " << path; + else { + bool is_interactive = + working_files->GetFileByFilename(entry.filename) != nullptr; + QueueManager::instance()->index_request.Enqueue( + Index_Request(path, entry.args, is_interactive, *content)); + clang_complete->NotifySave(path); + } break; + } case lsFileChangeType::Deleted: // TODO break; - case lsFileChangeType::Changed: - // TODO - break; } } }