Module: Ibex::LSP::RequestSupport
- Included in:
- DocumentHandlers, InitializationHandlers, NavigationHandlers, RequestHandlers
- Defined in:
- lib/ibex/lsp/request_support.rb,
sig/ibex/lsp/request_support.rbs
Overview
Shared publication, state, and parameter validation for request handlers.
Instance Method Summary collapse
- #hash_member(value, name) ⇒ lsp_object
- #integer_member(value, name) ⇒ Integer
- #params_hash(value) ⇒ lsp_object
- #publish(publications) ⇒ void
- #require_running! ⇒ void
- #require_state!(state) ⇒ void
- #stale_publication?(uri, version) ⇒ Boolean
- #store ⇒ DocumentStore
- #string_member(value, name) ⇒ String
- #workspace ⇒ Workspace
Instance Method Details
#hash_member(value, name) ⇒ lsp_object
45 46 47 48 49 50 51 52 53 |
# File 'lib/ibex/lsp/request_support.rb', line 45 def hash_member(value, name) member = value[name] if member.is_a?(Hash) result = member #: lsp_object return result end raise ProtocolError.new("#{name} must be an object", code: -32_602) end |
#integer_member(value, name) ⇒ Integer
64 65 66 67 68 69 |
# File 'lib/ibex/lsp/request_support.rb', line 64 def integer_member(value, name) member = value[name] return member if member.is_a?(Integer) raise ProtocolError.new("#{name} must be an integer", code: -32_602) end |
#params_hash(value) ⇒ lsp_object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ibex/lsp/request_support.rb', line 33 def params_hash(value) return {} if value.nil? if value.is_a?(Hash) result = value #: lsp_object return result end raise ProtocolError.new("params must be an object", code: -32_602) end |
#publish(publications) ⇒ void
This method returns an undefined value.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ibex/lsp/request_support.rb', line 10 def publish(publications) publications.each do |publication| version = publication[:version] next if version && stale_publication?(publication.fetch(:uri), version) params = { "uri" => publication.fetch(:uri), "diagnostics" => publication.fetch(:diagnostics) } #: lsp_object params["version"] = version if version @transport.( "jsonrpc" => "2.0", "method" => "textDocument/publishDiagnostics", "params" => params ) end end |
#require_running! ⇒ void
This method returns an undefined value.
79 80 81 |
# File 'lib/ibex/lsp/request_support.rb', line 79 def require_running! require_state!(:running) end |
#require_state!(state) ⇒ void
This method returns an undefined value.
72 73 74 75 76 |
# File 'lib/ibex/lsp/request_support.rb', line 72 def require_state!(state) return if @state == state raise ProtocolError.new("request requires #{state} server state", code: -32_600) end |
#stale_publication?(uri, version) ⇒ Boolean
27 28 29 30 |
# File 'lib/ibex/lsp/request_support.rb', line 27 def stale_publication?(uri, version) path = workspace.path(uri) store.snapshot_for(path)&.fetch(:version) != version end |
#store ⇒ DocumentStore
84 85 86 |
# File 'lib/ibex/lsp/request_support.rb', line 84 def store @store || raise(ProtocolError.new("server is not initialized", code: -32_002)) end |
#string_member(value, name) ⇒ String
56 57 58 59 60 61 |
# File 'lib/ibex/lsp/request_support.rb', line 56 def string_member(value, name) member = value[name] return member if member.is_a?(String) raise ProtocolError.new("#{name} must be a string", code: -32_602) end |
#workspace ⇒ Workspace
89 90 91 |
# File 'lib/ibex/lsp/request_support.rb', line 89 def workspace @workspace || raise(ProtocolError.new("server is not initialized", code: -32_002)) end |