From 55bfe58feaf3ca12e24a5eb49fd5bd8c62712dd2 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 17 Mar 2018 13:24:01 -0700 Subject: [PATCH] textDocument/didOpen: add args to override project entry --- src/messages/text_document_did_open.cc | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 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 */); } };