123456789_123456789_123456789_123456789_123456789_

Class: TypeProf::LSP::Server

Relationships & Source Files
Namespace Children
Exceptions:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, Helpers
Inherits: Object
Defined in: lib/typeprof/lsp.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(config, reader, writer) ⇒ Server

[ GitHub ]

  
# File 'lib/typeprof/lsp.rb', line 835

def initialize(config, reader, writer)
  @typeprof_config = config
  @reader = reader
  @writer = writer
  @tx_mutex = Mutex.new
  @request_id = 0
  @running_requests_from_client = {}
  @running_requests_from_server = {}
  @open_texts = {}
  @sigs = {} # tmp
  @signature_enabled = true
end

Instance Attribute Details

#open_texts (readonly)

[ GitHub ]

  
# File 'lib/typeprof/lsp.rb', line 848

attr_reader :typeprof_config, :open_texts, :sigs, :running_requests_from_client

#root_uri (rw)

[ GitHub ]

  
# File 'lib/typeprof/lsp.rb', line 849

attr_accessor :root_uri, :signature_enabled

#running_requests_from_client (readonly)

[ GitHub ]

  
# File 'lib/typeprof/lsp.rb', line 848

attr_reader :typeprof_config, :open_texts, :sigs, :running_requests_from_client

#signature_enabled (rw)

[ GitHub ]

  
# File 'lib/typeprof/lsp.rb', line 849

attr_accessor :root_uri, :signature_enabled

#sigs (readonly)

[ GitHub ]

  
# File 'lib/typeprof/lsp.rb', line 848

attr_reader :typeprof_config, :open_texts, :sigs, :running_requests_from_client

#typeprof_config (readonly)

[ GitHub ]

  
# File 'lib/typeprof/lsp.rb', line 848

attr_reader :typeprof_config, :open_texts, :sigs, :running_requests_from_client

Instance Method Details

#exclusive_write(**json)

[ GitHub ]

  
# File 'lib/typeprof/lsp.rb', line 881

def exclusive_write(**json)
  @tx_mutex.synchronize do
    @writer.write(**json)
  end
end

#run

[ GitHub ]

  
# File 'lib/typeprof/lsp.rb', line 851

def run
  @reader.read do |json|
    if json[:method]
      # request or notification
      msg = Message.find(json[:method]).new(self, json)
      @running_requests_from_client[json[:id]] = msg if json[:id]
      msg.run
    else
      callback = @running_requests_from_server.delete(json[:id])
      callback&.call(json[:params])
    end
  end
rescue Exit
end

#send_notification(method, params = nil)

[ GitHub ]

  
# File 'lib/typeprof/lsp.rb', line 871

def send_notification(method, params = nil)
  exclusive_write(method: method, params: params)
end

#send_request(method, **params, &blk)

[ GitHub ]

  
# File 'lib/typeprof/lsp.rb', line 875

def send_request(method, **params, &blk)
  id = @request_id += 1
  @running_requests_from_server[id] = blk
  exclusive_write(id: id, method: method, params: params)
end

#send_response(**msg)

[ GitHub ]

  
# File 'lib/typeprof/lsp.rb', line 866

def send_response(**msg)
  @running_requests_from_client.delete(msg[:id])
  exclusive_write(**msg)
end