From 795f830c25adbbce80d32e4b6d6ceacfe41218f3 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Wed, 13 Jul 2022 17:21:09 -0600 Subject: [PATCH] Write to stdout ASAP in server mode Don't wait for a full 4KB of output, or a timeout, just write it as we get it. This makes the experience feel much more like you're running rubocop directly --- changelog/change_no_buffer_server_stdout.md | 1 + lib/rubocop/server/client_command/base.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 changelog/change_no_buffer_server_stdout.md diff --git a/changelog/change_no_buffer_server_stdout.md b/changelog/change_no_buffer_server_stdout.md new file mode 100644 index 00000000000..f15392bb711 --- /dev/null +++ b/changelog/change_no_buffer_server_stdout.md @@ -0,0 +1 @@ +* [#10814](https://github.com/rubocop/rubocop/pull/10814): Avoid buffering stdout when running in server mode. ([@ccutrer][]) diff --git a/lib/rubocop/server/client_command/base.rb b/lib/rubocop/server/client_command/base.rb index 6c8f87dc010..e8f768f40fa 100644 --- a/lib/rubocop/server/client_command/base.rb +++ b/lib/rubocop/server/client_command/base.rb @@ -29,7 +29,7 @@ def send_request(command:, args: [], body: '') socket.puts [Cache.token_path.read, Dir.pwd, command, *args].shelljoin socket.write body socket.close_write - $stdout.write socket.read(4096) until socket.eof? + $stdout.write socket.readpartial(4096) until socket.eof? end end