Skip to content

Commit

Permalink
Use $stderr.puts instead of warn (#285)
Browse files Browse the repository at this point in the history
Co-authored-by: Andy Waite <[email protected]>
  • Loading branch information
andyw8 and andyw8 authored Mar 8, 2024
1 parent 734259e commit 04fca2a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,3 @@ Sorbet/StrictSigil:
Exclude:
- "**/*.rake"
- "test/**/*.rb"

Style/StderrPuts:
Enabled: true
20 changes: 10 additions & 10 deletions lib/ruby_lsp/ruby_lsp_rails/runner_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class << self
def create_client
new
rescue Errno::ENOENT, StandardError => e # rubocop:disable Lint/ShadowedException
warn("Ruby LSP Rails failed to initialize server: #{e.message}\n#{e.backtrace&.join("\n")}")
warn("Server dependent features will not be available")
$stderr.puts("Ruby LSP Rails failed to initialize server: #{e.message}\n#{e.backtrace&.join("\n")}")
$stderr.puts("Server dependent features will not be available")
NullClient.new
end
end
Expand Down Expand Up @@ -50,14 +50,14 @@ def initialize
@stdin.binmode # for Windows compatibility
@stdout.binmode # for Windows compatibility

warn("Ruby LSP Rails booting server")
$stderr.puts("Ruby LSP Rails booting server")
read_response
warn("Finished booting Ruby LSP Rails server")
$stderr.puts("Finished booting Ruby LSP Rails server")

unless ENV["RAILS_ENV"] == "test"
at_exit do
if @wait_thread.alive?
warn("Ruby LSP Rails is force killing the server")
$stderr.puts("Ruby LSP Rails is force killing the server")
sleep(0.5) # give the server a bit of time if we already issued a shutdown notification
Process.kill(T.must(Signal.list["TERM"]), @wait_thread.pid)
end
Expand All @@ -71,22 +71,22 @@ def initialize
def model(name)
make_request("model", name: name)
rescue IncompleteMessageError
warn("Ruby LSP Rails failed to get model information: #{@stderr.read}")
$stderr.puts("Ruby LSP Rails failed to get model information: #{@stderr.read}")
nil
end

sig { void }
def trigger_reload
warn("Reloading Rails application")
$stderr.puts("Reloading Rails application")
send_notification("reload")
rescue IncompleteMessageError
warn("Ruby LSP Rails failed to trigger reload")
$stderr.puts("Ruby LSP Rails failed to trigger reload")
nil
end

sig { void }
def shutdown
warn("Ruby LSP Rails shutting down server")
$stderr.puts("Ruby LSP Rails shutting down server")
send_message("shutdown")
sleep(0.5) # give the server a bit of time to shutdown
[@stdin, @stdout, @stderr].each(&:close)
Expand Down Expand Up @@ -130,7 +130,7 @@ def read_response
response = JSON.parse(T.must(raw_response), symbolize_names: true)

if response[:error]
warn("Ruby LSP Rails error: " + response[:error])
$stderr.puts("Ruby LSP Rails error: " + response[:error])
return
end

Expand Down
6 changes: 3 additions & 3 deletions lib/ruby_lsp/ruby_lsp_rails/support/rails_document_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def generate_rails_document_urls(name)
private def build_search_index
return unless RAILTIES_VERSION

warn("Fetching Rails Documents...")
$stderr.puts("Fetching Rails Documents...")

response = Net::HTTP.get_response(URI("#{RAILS_DOC_HOST}/v#{RAILTIES_VERSION}/js/search_index.js"))

Expand All @@ -79,13 +79,13 @@ def generate_rails_document_urls(name)
response = Net::HTTP.get_response(URI("#{RAILS_DOC_HOST}/js/search_index.js"))
response.body if response.is_a?(Net::HTTPSuccess)
else
warn("Response failed: #{response.inspect}")
$stderr.puts("Response failed: #{response.inspect}")
nil
end

process_search_index(body) if body
rescue StandardError => e
warn("Exception occurred when fetching Rails document index: #{e.inspect}")
$stderr.puts("Exception occurred when fetching Rails document index: #{e.inspect}")
end

sig { params(js: String).returns(T::Hash[String, T::Array[T::Hash[Symbol, String]]]) }
Expand Down

0 comments on commit 04fca2a

Please sign in to comment.