2017-12-29 17:27:56 +00:00
|
|
|
#include "cache_manager.h"
|
2017-12-29 16:29:47 +00:00
|
|
|
#include "clang_complete.h"
|
|
|
|
#include "include_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
|
|
|
#include "timer.h"
|
2017-12-29 16:29:47 +00:00
|
|
|
#include "working_files.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
|
|
|
// Open, view, change, close file
|
2018-01-19 08:56:09 +00:00
|
|
|
struct Ipc_TextDocumentDidOpen
|
|
|
|
: public NotificationMessage<Ipc_TextDocumentDidOpen> {
|
|
|
|
const static IpcId kIpcId = IpcId::TextDocumentDidOpen;
|
2017-12-06 04:39:44 +00:00
|
|
|
struct Params {
|
|
|
|
lsTextDocumentItem textDocument;
|
|
|
|
};
|
|
|
|
Params params;
|
|
|
|
};
|
|
|
|
MAKE_REFLECT_STRUCT(Ipc_TextDocumentDidOpen::Params, textDocument);
|
|
|
|
MAKE_REFLECT_STRUCT(Ipc_TextDocumentDidOpen, params);
|
|
|
|
REGISTER_IPC_MESSAGE(Ipc_TextDocumentDidOpen);
|
|
|
|
|
2017-12-06 03:32:33 +00:00
|
|
|
struct TextDocumentDidOpenHandler
|
|
|
|
: BaseMessageHandler<Ipc_TextDocumentDidOpen> {
|
|
|
|
void Run(Ipc_TextDocumentDidOpen* request) override {
|
|
|
|
// NOTE: This function blocks code lens. If it starts taking a long time
|
|
|
|
// we will need to find a way to unblock the code lens request.
|
|
|
|
|
|
|
|
Timer time;
|
|
|
|
std::string path = request->params.textDocument.uri.GetPath();
|
2017-12-07 01:00:19 +00:00
|
|
|
if (ShouldIgnoreFileForIndexing(path))
|
|
|
|
return;
|
|
|
|
|
2018-01-30 05:34:28 +00:00
|
|
|
std::shared_ptr<ICacheManager> cache_manager = ICacheManager::Make(config);
|
2017-12-06 04:39:44 +00:00
|
|
|
WorkingFile* working_file =
|
|
|
|
working_files->OnOpen(request->params.textDocument);
|
2017-12-06 03:32:33 +00:00
|
|
|
optional<std::string> cached_file_contents =
|
2017-12-29 18:19:39 +00:00
|
|
|
cache_manager->LoadCachedFileContents(path);
|
2017-12-06 03:32:33 +00:00
|
|
|
if (cached_file_contents)
|
|
|
|
working_file->SetIndexContent(*cached_file_contents);
|
|
|
|
|
|
|
|
QueryFile* file = nullptr;
|
2017-12-31 03:18:33 +00:00
|
|
|
FindFileOrFail(db, project, nullopt, path, &file);
|
2017-12-06 03:32:33 +00:00
|
|
|
if (file && file->def) {
|
|
|
|
EmitInactiveLines(working_file, file->def->inactive_regions);
|
|
|
|
EmitSemanticHighlighting(db, semantic_cache, working_file, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
time.ResetAndPrint(
|
|
|
|
"[querydb] Loading cached index file for DidOpen (blocks "
|
|
|
|
"CodeLens)");
|
|
|
|
|
|
|
|
include_complete->AddFile(working_file->filename);
|
|
|
|
clang_complete->NotifyView(path);
|
|
|
|
|
|
|
|
// Submit new index request.
|
|
|
|
const Project::Entry& entry = project->FindCompilationEntryForFile(path);
|
2018-02-05 06:03:22 +00:00
|
|
|
QueueManager::instance()->index_request.PushBack(
|
2017-12-29 18:00:44 +00:00
|
|
|
Index_Request(entry.filename, entry.args, true /*is_interactive*/,
|
2018-02-05 06:03:22 +00:00
|
|
|
request->params.textDocument.text, cache_manager),
|
|
|
|
true /* priority */);
|
2017-12-06 03:32:33 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
REGISTER_MESSAGE_HANDLER(TextDocumentDidOpenHandler);
|
2017-12-07 01:00:19 +00:00
|
|
|
} // namespace
|