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
- .new(config, reader, writer) ⇒ Server constructor
Instance Attribute Summary
- #open_texts readonly
- #root_uri rw
- #running_requests_from_client readonly
- #signature_enabled rw
- #sigs readonly
- #typeprof_config readonly
Instance Method Summary
- #exclusive_write(**json)
- #run
- #send_notification(method, params = nil)
- #send_request(method, **params, &blk)
- #send_response(**msg)
Helpers
- Included
Constructor Details
.new(config, reader, writer) ⇒ Server
# File 'lib/typeprof/lsp.rb', line 843
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 856
attr_reader :typeprof_config, :open_texts, :sigs, :running_requests_from_client
#root_uri (rw)
[ GitHub ]# File 'lib/typeprof/lsp.rb', line 857
attr_accessor :root_uri, :signature_enabled
#running_requests_from_client (readonly)
[ GitHub ]# File 'lib/typeprof/lsp.rb', line 856
attr_reader :typeprof_config, :open_texts, :sigs, :running_requests_from_client
#signature_enabled (rw)
[ GitHub ]# File 'lib/typeprof/lsp.rb', line 857
attr_accessor :root_uri, :signature_enabled
#sigs (readonly)
[ GitHub ]# File 'lib/typeprof/lsp.rb', line 856
attr_reader :typeprof_config, :open_texts, :sigs, :running_requests_from_client
#typeprof_config (readonly)
[ GitHub ]# File 'lib/typeprof/lsp.rb', line 856
attr_reader :typeprof_config, :open_texts, :sigs, :running_requests_from_client
Instance Method Details
#exclusive_write(**json)
[ GitHub ]# File 'lib/typeprof/lsp.rb', line 903
def exclusive_write(**json) @tx_mutex.synchronize do @writer.write(**json) end end
#run
[ GitHub ]# File 'lib/typeprof/lsp.rb', line 859
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 rescue => e msg = "Tyeprof fatal error: #{e.}" send_notification( 'window/showMessage', type: MessageType::Error, message: msg ) send_notification( 'window/logMessage', type: MessageType::Error, message: "#{msg} Backtrace: #{e.backtrace}" ) send_notification('typeprof.showErrorStatus') retry end
#send_notification(method, params = nil)
[ GitHub ]# File 'lib/typeprof/lsp.rb', line 893
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 897
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 888
def send_response(**msg) @running_requests_from_client.delete(msg[:id]) exclusive_write(**msg) end