mirror of
				https://github.com/MaskRay/ccls.git
				synced 2025-10-30 20:22:38 +00:00 
			
		
		
		
	Add --log-stdin-stdout-to-stderr
Prints messages received and stdin/stdout to stderr. Useful when developing a new client that uses cquery as the backend.
This commit is contained in:
		
							parent
							
								
									f1f2cc3bd1
								
							
						
					
					
						commit
						f4acde7588
					
				| @ -52,6 +52,9 @@ std::vector<std::string> kEmptyArgs; | |||||||
| // Expected client version. We show an error if this doesn't match.
 | // Expected client version. We show an error if this doesn't match.
 | ||||||
| const int kExpectedClientVersion = 3; | const int kExpectedClientVersion = 3; | ||||||
| 
 | 
 | ||||||
|  | // If true stdout will be printed to stderr.
 | ||||||
|  | bool g_log_stdin_stdout_to_stderr = false; | ||||||
|  | 
 | ||||||
| // Cached completion information, so we can give fast completion results when
 | // Cached completion information, so we can give fast completion results when
 | ||||||
| // the user erases a character. vscode will resend the completion request if
 | // the user erases a character. vscode will resend the completion request if
 | ||||||
| // that happens.
 | // that happens.
 | ||||||
| @ -3027,7 +3030,8 @@ void LaunchStdinLoop(Config* config, | |||||||
|     IpcManager* ipc = IpcManager::instance(); |     IpcManager* ipc = IpcManager::instance(); | ||||||
| 
 | 
 | ||||||
|     std::unique_ptr<BaseIpcMessage> message = |     std::unique_ptr<BaseIpcMessage> message = | ||||||
|         MessageRegistry::instance()->ReadMessageFromStdin(); |         MessageRegistry::instance()->ReadMessageFromStdin( | ||||||
|  |             g_log_stdin_stdout_to_stderr); | ||||||
| 
 | 
 | ||||||
|     // Message parsing can fail if we don't recognize the method.
 |     // Message parsing can fail if we don't recognize the method.
 | ||||||
|     if (!message) |     if (!message) | ||||||
| @ -3133,6 +3137,12 @@ void LaunchStdoutThread(std::unordered_map<IpcId, Timer>* request_times, | |||||||
|                                                       msg->original_ipc_id))); |                                                       msg->original_ipc_id))); | ||||||
|           } |           } | ||||||
| 
 | 
 | ||||||
|  |           if (g_log_stdin_stdout_to_stderr) { | ||||||
|  |             std::string printed = "[COUT] |" + msg->content + "|\n"; | ||||||
|  |             std::cerr << printed; | ||||||
|  |             std::cerr.flush(); | ||||||
|  |           } | ||||||
|  | 
 | ||||||
|           std::cout << msg->content; |           std::cout << msg->content; | ||||||
|           std::cout.flush(); |           std::cout.flush(); | ||||||
|           break; |           break; | ||||||
| @ -3210,6 +3220,9 @@ int main(int argc, char** argv) { | |||||||
| 
 | 
 | ||||||
|   bool print_help = true; |   bool print_help = true; | ||||||
| 
 | 
 | ||||||
|  |   if (HasOption(options, "--log-stdin-stdout-to-stderr")) | ||||||
|  |     g_log_stdin_stdout_to_stderr = true; | ||||||
|  | 
 | ||||||
|   if (HasOption(options, "--test-unit")) { |   if (HasOption(options, "--test-unit")) { | ||||||
|     print_help = false; |     print_help = false; | ||||||
|     doctest::Context context; |     doctest::Context context; | ||||||
| @ -3248,6 +3261,10 @@ int main(int argc, char** argv) { | |||||||
|                   server spec over STDIN and STDOUT. |                   server spec over STDIN and STDOUT. | ||||||
|     --test-unit   Run unit tests. |     --test-unit   Run unit tests. | ||||||
|     --test-index  Run index tests. |     --test-index  Run index tests. | ||||||
|  |     --log-stdin-stdout-to-stderr | ||||||
|  |                   Print stdin and stdout messages to stderr. This is a aid for | ||||||
|  |                   developing new language clients, as it makes it easier to | ||||||
|  |                   figure out how the client is interacting with cquery. | ||||||
| 
 | 
 | ||||||
|   Configuration: |   Configuration: | ||||||
|     When opening up a directory, cquery will look for a compile_commands.json |     When opening up a directory, cquery will look for a compile_commands.json | ||||||
|  | |||||||
| @ -134,7 +134,8 @@ optional<char> ReadCharFromStdinBlocking() { | |||||||
|   return c; |   return c; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| std::unique_ptr<BaseIpcMessage> MessageRegistry::ReadMessageFromStdin() { | std::unique_ptr<BaseIpcMessage> MessageRegistry::ReadMessageFromStdin( | ||||||
|  |     bool log_stdin_to_stderr) { | ||||||
|   optional<std::string> content = |   optional<std::string> content = | ||||||
|       ReadJsonRpcContentFrom(&ReadCharFromStdinBlocking); |       ReadJsonRpcContentFrom(&ReadCharFromStdinBlocking); | ||||||
|   if (!content) { |   if (!content) { | ||||||
| @ -142,6 +143,14 @@ std::unique_ptr<BaseIpcMessage> MessageRegistry::ReadMessageFromStdin() { | |||||||
|     exit(1); |     exit(1); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   if (log_stdin_to_stderr) { | ||||||
|  |     // TODO: This should go inside of ReadJsonRpcContentFrom since it does not
 | ||||||
|  |     // print the header.
 | ||||||
|  |     std::string printed = "[CIN] |" + *content + "|\n"; | ||||||
|  |     std::cerr << printed; | ||||||
|  |     std::cerr.flush(); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   rapidjson::Document document; |   rapidjson::Document document; | ||||||
|   document.Parse(content->c_str(), content->length()); |   document.Parse(content->c_str(), content->length()); | ||||||
|   assert(!document.HasParseError()); |   assert(!document.HasParseError()); | ||||||
|  | |||||||
| @ -58,7 +58,8 @@ struct MessageRegistry { | |||||||
|     }; |     }; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   std::unique_ptr<BaseIpcMessage> ReadMessageFromStdin(); |   std::unique_ptr<BaseIpcMessage> ReadMessageFromStdin( | ||||||
|  |       bool log_stdin_to_stderr); | ||||||
|   std::unique_ptr<BaseIpcMessage> Parse(Reader& visitor); |   std::unique_ptr<BaseIpcMessage> Parse(Reader& visitor); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user