diff --git a/src/messages/text_document_did_open.cc b/src/messages/text_document_did_open.cc index a16c0fb7..0bd4f990 100644 --- a/src/messages/text_document_did_open.cc +++ b/src/messages/text_document_did_open.cc @@ -14,10 +14,15 @@ struct Ipc_TextDocumentDidOpen const static IpcId kIpcId = IpcId::TextDocumentDidOpen; struct Params { 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 args; }; Params params; }; -MAKE_REFLECT_STRUCT(Ipc_TextDocumentDidOpen::Params, textDocument); +MAKE_REFLECT_STRUCT(Ipc_TextDocumentDidOpen::Params, textDocument, args); MAKE_REFLECT_STRUCT(Ipc_TextDocumentDidOpen, params); REGISTER_IPC_MESSAGE(Ipc_TextDocumentDidOpen); @@ -26,15 +31,14 @@ struct TextDocumentDidOpenHandler 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. - + const auto& params = request->params; Timer time; - std::string path = request->params.textDocument.uri.GetPath(); + std::string path = params.textDocument.uri.GetPath(); if (ShouldIgnoreFileForIndexing(path)) return; std::shared_ptr cache_manager = ICacheManager::Make(config); - WorkingFile* working_file = - working_files->OnOpen(request->params.textDocument); + WorkingFile* working_file = working_files->OnOpen(params.textDocument); optional cached_file_contents = cache_manager->LoadCachedFileContents(path); if (cached_file_contents) @@ -57,8 +61,9 @@ struct TextDocumentDidOpenHandler // Submit new index request. const Project::Entry& entry = project->FindCompilationEntryForFile(path); QueueManager::instance()->index_request.PushBack( - Index_Request(entry.filename, entry.args, true /*is_interactive*/, - request->params.textDocument.text, cache_manager), + Index_Request( + entry.filename, params.args.size() ? params.args : entry.args, + true /*is_interactive*/, params.textDocument.text, cache_manager), true /* priority */); } };