textDocument/didOpen: add args to override project entry

This commit is contained in:
Fangrui Song 2018-03-17 13:24:01 -07:00
parent ad3f990267
commit 11293722cc

View File

@ -14,10 +14,15 @@ struct Ipc_TextDocumentDidOpen
const static IpcId kIpcId = IpcId::TextDocumentDidOpen; const static IpcId kIpcId = IpcId::TextDocumentDidOpen;
struct Params { struct Params {
lsTextDocumentItem textDocument; lsTextDocumentItem textDocument;
// cquery extension
// If specified (e.g. ["clang++", "-DM", "a.cc"]), it overrides the project
// entry (e.g. loaded from compile_commands.json or .cquery).
std::vector<std::string> args;
}; };
Params params; Params params;
}; };
MAKE_REFLECT_STRUCT(Ipc_TextDocumentDidOpen::Params, textDocument); MAKE_REFLECT_STRUCT(Ipc_TextDocumentDidOpen::Params, textDocument, args);
MAKE_REFLECT_STRUCT(Ipc_TextDocumentDidOpen, params); MAKE_REFLECT_STRUCT(Ipc_TextDocumentDidOpen, params);
REGISTER_IPC_MESSAGE(Ipc_TextDocumentDidOpen); REGISTER_IPC_MESSAGE(Ipc_TextDocumentDidOpen);
@ -26,15 +31,14 @@ struct TextDocumentDidOpenHandler
void Run(Ipc_TextDocumentDidOpen* request) override { void Run(Ipc_TextDocumentDidOpen* request) override {
// NOTE: This function blocks code lens. If it starts taking a long time // 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. // we will need to find a way to unblock the code lens request.
const auto& params = request->params;
Timer time; Timer time;
std::string path = request->params.textDocument.uri.GetPath(); std::string path = params.textDocument.uri.GetPath();
if (ShouldIgnoreFileForIndexing(path)) if (ShouldIgnoreFileForIndexing(path))
return; return;
std::shared_ptr<ICacheManager> cache_manager = ICacheManager::Make(config); std::shared_ptr<ICacheManager> cache_manager = ICacheManager::Make(config);
WorkingFile* working_file = WorkingFile* working_file = working_files->OnOpen(params.textDocument);
working_files->OnOpen(request->params.textDocument);
optional<std::string> cached_file_contents = optional<std::string> cached_file_contents =
cache_manager->LoadCachedFileContents(path); cache_manager->LoadCachedFileContents(path);
if (cached_file_contents) if (cached_file_contents)
@ -57,8 +61,9 @@ struct TextDocumentDidOpenHandler
// Submit new index request. // Submit new index request.
const Project::Entry& entry = project->FindCompilationEntryForFile(path); const Project::Entry& entry = project->FindCompilationEntryForFile(path);
QueueManager::instance()->index_request.PushBack( QueueManager::instance()->index_request.PushBack(
Index_Request(entry.filename, entry.args, true /*is_interactive*/, Index_Request(
request->params.textDocument.text, cache_manager), entry.filename, params.args.size() ? params.args : entry.args,
true /*is_interactive*/, params.textDocument.text, cache_manager),
true /* priority */); true /* priority */);
} }
}; };