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) ⇒ Hash[String, untyped]
- #integer_member(value, name) ⇒ Integer
- #params_hash(value) ⇒ Hash[String, untyped]
- #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) ⇒ Hash[String, untyped]
41 42 43 44 45 46 |
# File 'lib/ibex/lsp/request_support.rb', line 41 def hash_member(value, name) member = value[name] return member if member.is_a?(Hash) raise ProtocolError.new("#{name} must be an object", code: -32_602) end |
#integer_member(value, name) ⇒ Integer
57 58 59 60 61 62 |
# File 'lib/ibex/lsp/request_support.rb', line 57 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) ⇒ Hash[String, untyped]
33 34 35 36 37 38 |
# File 'lib/ibex/lsp/request_support.rb', line 33 def params_hash(value) return {} if value.nil? return value if value.is_a?(Hash) 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) } #: Hash[String, untyped] 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.
72 73 74 |
# File 'lib/ibex/lsp/request_support.rb', line 72 def require_running! require_state!(:running) end |
#require_state!(state) ⇒ void
This method returns an undefined value.
65 66 67 68 69 |
# File 'lib/ibex/lsp/request_support.rb', line 65 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
77 78 79 |
# File 'lib/ibex/lsp/request_support.rb', line 77 def store @store || raise(ProtocolError.new("server is not initialized", code: -32_002)) end |
#string_member(value, name) ⇒ String
49 50 51 52 53 54 |
# File 'lib/ibex/lsp/request_support.rb', line 49 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
82 83 84 |
# File 'lib/ibex/lsp/request_support.rb', line 82 def workspace @workspace || raise(ProtocolError.new("server is not initialized", code: -32_002)) end |