2018-01-26 07:04:07 +00:00
|
|
|
#include "clang_complete.h"
|
2018-01-10 05:11:30 +00:00
|
|
|
#include "message_handler.h"
|
2018-01-26 07:04:07 +00:00
|
|
|
#include "project.h"
|
2018-01-10 05:11:30 +00:00
|
|
|
#include "queue_manager.h"
|
2018-01-26 07:04:07 +00:00
|
|
|
#include "working_files.h"
|
|
|
|
|
|
|
|
#include <loguru/loguru.hpp>
|
2018-01-10 05:11:30 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
enum class lsFileChangeType {
|
|
|
|
Created = 1,
|
|
|
|
Changed = 2,
|
|
|
|
Deleted = 3,
|
|
|
|
};
|
|
|
|
MAKE_REFLECT_TYPE_PROXY(lsFileChangeType,
|
|
|
|
std::underlying_type<lsFileChangeType>::type);
|
|
|
|
|
|
|
|
struct lsFileEvent {
|
|
|
|
lsDocumentUri uri;
|
|
|
|
lsFileChangeType type;
|
|
|
|
};
|
|
|
|
MAKE_REFLECT_STRUCT(lsFileEvent, uri, type);
|
|
|
|
|
|
|
|
struct lsDidChangeWatchedFilesParams {
|
|
|
|
std::vector<lsFileEvent> changes;
|
|
|
|
};
|
|
|
|
MAKE_REFLECT_STRUCT(lsDidChangeWatchedFilesParams, changes);
|
|
|
|
|
|
|
|
struct Ipc_WorkspaceDidChangeWatchedFiles
|
2018-01-19 08:56:09 +00:00
|
|
|
: public NotificationMessage<Ipc_WorkspaceDidChangeWatchedFiles> {
|
2018-01-10 05:11:30 +00:00
|
|
|
const static IpcId kIpcId = IpcId::WorkspaceDidChangeWatchedFiles;
|
|
|
|
lsDidChangeWatchedFilesParams params;
|
|
|
|
};
|
|
|
|
MAKE_REFLECT_STRUCT(Ipc_WorkspaceDidChangeWatchedFiles, params);
|
|
|
|
REGISTER_IPC_MESSAGE(Ipc_WorkspaceDidChangeWatchedFiles);
|
|
|
|
|
|
|
|
struct WorkspaceDidChangeWatchedFilesHandler
|
|
|
|
: BaseMessageHandler<Ipc_WorkspaceDidChangeWatchedFiles> {
|
|
|
|
void Run(Ipc_WorkspaceDidChangeWatchedFiles* request) override {
|
|
|
|
for (lsFileEvent& event : request->params.changes) {
|
2018-01-26 07:04:07 +00:00
|
|
|
std::string path = event.uri.GetPath();
|
2018-01-10 05:11:30 +00:00
|
|
|
switch (event.type) {
|
|
|
|
case lsFileChangeType::Created:
|
2018-01-26 07:04:07 +00:00
|
|
|
// TODO
|
|
|
|
case lsFileChangeType::Changed: {
|
|
|
|
Project::Entry entry = project->FindCompilationEntryForFile(path);
|
|
|
|
optional<std::string> 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);
|
|
|
|
}
|
2018-01-10 05:11:30 +00:00
|
|
|
break;
|
2018-01-26 07:04:07 +00:00
|
|
|
}
|
2018-01-10 05:11:30 +00:00
|
|
|
case lsFileChangeType::Deleted:
|
|
|
|
// TODO
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
REGISTER_MESSAGE_HANDLER(WorkspaceDidChangeWatchedFilesHandler);
|
|
|
|
} // namespace
|