Class: PinkSpoon::Server
- Inherits:
-
Object
- Object
- PinkSpoon::Server
- Defined in:
- lib/pink_spoon/server.rb
Overview
JSON-RPC 2.0 server over stdin/stdout. Implements only initialize, textDocument/definition, and textDocument/hover. Every other request gets a null result so clients don’t hang.
Instance Method Summary collapse
-
#initialize ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
13 14 15 16 17 |
# File 'lib/pink_spoon/server.rb', line 13 def initialize @rbi_index = nil # built lazily after initialize gives us the project root @constant_resolver = nil @definition_finder = nil end |
Instance Method Details
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/pink_spoon/server.rb', line 19 def run $stdout.sync = true $stderr.sync = true loop do header = read_header break unless header length = header[/Content-Length:\s*(\d+)/i, 1]&.to_i next unless length&.positive? body = $stdin.read(length) next unless body request = JSON.parse(body, symbolize_names: true) handle(request) end end |