Class: ThemeCheck::LanguageServer::Server
- Inherits:
-
Object
- Object
- ThemeCheck::LanguageServer::Server
- Defined in:
- lib/theme_check/language_server/server.rb
Instance Attribute Summary collapse
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#should_raise_errors ⇒ Object
readonly
Returns the value of attribute should_raise_errors.
Instance Method Summary collapse
-
#initialize(in_stream: STDIN, out_stream: STDOUT, err_stream: STDERR, should_raise_errors: false) ⇒ Server
constructor
A new instance of Server.
- #listen ⇒ Object
- #log(message) ⇒ Object
- #send_response(response) ⇒ Object
Constructor Details
#initialize(in_stream: STDIN, out_stream: STDOUT, err_stream: STDERR, should_raise_errors: false) ⇒ Server
Returns a new instance of Server.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/theme_check/language_server/server.rb', line 15 def initialize( in_stream: STDIN, out_stream: STDOUT, err_stream: STDERR, should_raise_errors: false ) validate!([in_stream, out_stream, err_stream]) @handler = Handler.new(self) @in = in_stream @out = out_stream @err = err_stream @out.sync = true # do not buffer @err.sync = true # do not buffer @should_raise_errors = should_raise_errors end |
Instance Attribute Details
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
12 13 14 |
# File 'lib/theme_check/language_server/server.rb', line 12 def handler @handler end |
#should_raise_errors ⇒ Object (readonly)
Returns the value of attribute should_raise_errors.
13 14 15 |
# File 'lib/theme_check/language_server/server.rb', line 13 def should_raise_errors @should_raise_errors end |
Instance Method Details
#listen ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/theme_check/language_server/server.rb', line 34 def listen loop do process_request # support ctrl+c and stuff rescue SignalException, DoneStreaming cleanup return 0 rescue Exception => e # rubocop:disable Lint/RescueException raise e if should_raise_errors log(e) log(e.backtrace) return 1 end end |
#log(message) ⇒ Object
61 62 63 64 |
# File 'lib/theme_check/language_server/server.rb', line 61 def log() @err.puts() @err.flush end |
#send_response(response) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/theme_check/language_server/server.rb', line 51 def send_response(response) response_body = JSON.dump(response) log(JSON.pretty_generate(response)) if $DEBUG @out.write("Content-Length: #{response_body.bytesize}\r\n") @out.write("\r\n") @out.write(response_body) @out.flush end |