2017-12-29 16:29:47 +00:00
|
|
|
#include "clang_complete.h"
|
2017-12-06 03:32:33 +00:00
|
|
|
#include "message_handler.h"
|
2017-12-29 16:29:47 +00:00
|
|
|
#include "project.h"
|
|
|
|
#include "queue_manager.h"
|
2017-12-06 03:32:33 +00:00
|
|
|
|
2017-12-06 05:03:38 +00:00
|
|
|
namespace {
|
2017-12-06 04:39:44 +00:00
|
|
|
struct Ipc_TextDocumentDidSave : public IpcMessage<Ipc_TextDocumentDidSave> {
|
|
|
|
struct Params {
|
|
|
|
// The document that was saved.
|
|
|
|
lsTextDocumentIdentifier textDocument;
|
|
|
|
|
|
|
|
// Optional the content when saved. Depends on the includeText value
|
|
|
|
// when the save notifcation was requested.
|
|
|
|
// std::string text;
|
|
|
|
};
|
|
|
|
|
|
|
|
const static IpcId kIpcId = IpcId::TextDocumentDidSave;
|
|
|
|
Params params;
|
|
|
|
};
|
|
|
|
MAKE_REFLECT_STRUCT(Ipc_TextDocumentDidSave::Params, textDocument);
|
|
|
|
MAKE_REFLECT_STRUCT(Ipc_TextDocumentDidSave, params);
|
|
|
|
REGISTER_IPC_MESSAGE(Ipc_TextDocumentDidSave);
|
|
|
|
|
2017-12-06 03:32:33 +00:00
|
|
|
struct TextDocumentDidSaveHandler
|
|
|
|
: BaseMessageHandler<Ipc_TextDocumentDidSave> {
|
|
|
|
void Run(Ipc_TextDocumentDidSave* request) override {
|
|
|
|
std::string path = request->params.textDocument.uri.GetPath();
|
2017-12-07 01:00:19 +00:00
|
|
|
if (ShouldIgnoreFileForIndexing(path))
|
|
|
|
return;
|
|
|
|
|
2017-12-06 03:32:33 +00:00
|
|
|
// Send out an index request, and copy the current buffer state so we
|
|
|
|
// can update the cached index contents when the index is done.
|
|
|
|
//
|
|
|
|
// We also do not index if there is already an index request.
|
|
|
|
//
|
|
|
|
// TODO: Cancel outgoing index request. Might be tricky to make
|
|
|
|
// efficient since we have to cancel.
|
|
|
|
// - we could have an |atomic<int> active_cancellations| variable
|
|
|
|
// that all of the indexers check before accepting an index. if
|
|
|
|
// zero we don't slow down fast-path. if non-zero we acquire
|
|
|
|
// mutex and check to see if we should skip the current request.
|
|
|
|
// if so, ignore that index response.
|
|
|
|
// TODO: send as priority request
|
|
|
|
Project::Entry entry = project->FindCompilationEntryForFile(path);
|
2017-12-24 00:25:18 +00:00
|
|
|
QueueManager::instance()->index_request.Enqueue(Index_Request(
|
2017-12-06 03:32:33 +00:00
|
|
|
entry.filename, entry.args, true /*is_interactive*/, nullopt));
|
|
|
|
|
|
|
|
clang_complete->NotifySave(path);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
REGISTER_MESSAGE_HANDLER(TextDocumentDidSaveHandler);
|
2017-12-07 01:00:19 +00:00
|
|
|
} // namespace
|