Skip to content

Commit 59b8306

Browse files
author
James Pogran
authored
Merge pull request #133 from glennsarti/gh-132-fix-stdio
(GH-132) Suppress $stdout usage for STDIO transport
2 parents da5d292 + 4a0d970 commit 59b8306

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/puppet-editor-services/simple_stdio_server.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ def initialize(simple_stdio_server)
99
end
1010

1111
def send_data(data)
12-
$stdout.write(data)
12+
$editor_services_stdout.write(data) # rubocop:disable Style/GlobalVars We need this global var
1313
true
1414
end
1515

1616
def close_connection_after_writing
17-
$stdout.flush
17+
$editor_services_stdout.flush # rubocop:disable Style/GlobalVars We need this global var
1818
@simple_stdio_server.close_connection
1919
true
2020
end
@@ -40,10 +40,14 @@ def start(handler_klass = PuppetEditorServices::SimpleTCPServerConnection, conne
4040
connection_options[:servicename] = 'LANGUAGE SERVER' if connection_options[:servicename].nil?
4141
# This is a little heavy handed but we need to suppress writes to STDOUT and STDERR
4242
$VERBOSE = nil
43+
# Some libraries use $stdout to write to the console. Suppress all of that too!
44+
# Copy the existing $stdout variable and then reassign to NUL to suppress it
45+
$editor_services_stdout = $stdout # rubocop:disable Style/GlobalVars We need this global var
46+
$stdout = File.open(File::NULL, 'w')
4347

44-
$stdout.sync = true
48+
$editor_services_stdout.sync = true # rubocop:disable Style/GlobalVars We need this global var
4549
# Stop the stupid CRLF injection when on Windows
46-
$stdout.binmode unless $stdout.binmode
50+
$editor_services_stdout.binmode unless $editor_services_stdout.binmode # rubocop:disable Style/GlobalVars We need this global var
4751

4852
handler = handler_klass.new(connection_options)
4953
client_connection = PuppetEditorServices::SimpleSTDIOServerConnection.new(self)

0 commit comments

Comments
 (0)