Module: Lsp::LanguageServer
- Defined in:
- lib/lsp.rb
Constant Summary collapse
- LanguageServerError =
Class.new(StandardError)
- NotImplementedError =
Class.new(LanguageServerError)
Instance Attribute Summary collapse
-
#language_server ⇒ Object
writeonly
Sets the attribute language_server.
Instance Method Summary collapse
- #handle_initialize(request) ⇒ Object
- #handle_text_document_definition(request) ⇒ Object
- #handle_text_document_did_open ⇒ Object
- #handle_text_document_hover(request) ⇒ Object
- #notify(method_name, params) ⇒ Object
- #request(id, method_name, params) ⇒ Object
- #to_result(obj) ⇒ Object
Instance Attribute Details
#language_server=(value) ⇒ Object (writeonly)
Sets the attribute language_server
161 162 163 |
# File 'lib/lsp.rb', line 161 def language_server=(value) @language_server = value end |
Instance Method Details
#handle_initialize(request) ⇒ Object
171 172 173 |
# File 'lib/lsp.rb', line 171 def handle_initialize(request) raise NotImplementedError end |
#handle_text_document_definition(request) ⇒ Object
167 168 169 |
# File 'lib/lsp.rb', line 167 def handle_text_document_definition(request) raise NotImplementedError end |
#handle_text_document_did_open ⇒ Object
175 176 177 |
# File 'lib/lsp.rb', line 175 def handle_text_document_did_open raise NotImplementedError end |
#handle_text_document_hover(request) ⇒ Object
163 164 165 |
# File 'lib/lsp.rb', line 163 def handle_text_document_hover(request) raise NotImplementedError end |
#notify(method_name, params) ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/lsp.rb', line 142 def notify(method_name, params) case method_name when "textDocument/didOpen" handle_text_document_did_open end rescue NotImplementedError end |
#request(id, method_name, params) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/lsp.rb', line 96 def request(id, method_name, params) response = case method_name when "textDocument/hover" handle_text_document_hover( TextDocumentPositionParams.new( TextDocumentIdentifier.new( URI(params.fetch(:textDocument).fetch(:uri))), Position.from_hash(params.fetch(:position)))) when "textDocument/definition" handle_text_document_definition( TextDocumentPositionParams.new( TextDocumentIdentifier.new( URI(params.fetch(:textDocument).fetch(:uri))), Position.from_hash(params.fetch(:position)))) when "initialize" handle_initialize( InitializeRequest.new( URI(params.fetch(:rootUri)))) when "textDocument/completion" handle_text_document_completion( TextDocumentPositionParams.new( TextDocumentIdentifier.new( URI(params.fetch(:textDocument).fetch(:uri))), Position.from_hash(params.fetch(:position)))) when "textDocument/didChange" handle_text_document_did_change( DidChangeTextDocumentParams.new( VersionedTextDocumentIdentifier.new( URI(params.fetch(:textDocument).fetch(:uri)), params.fetch(:textDocument).fetch(:version)), params.fetch(:contentChanges).map do |contentChange| next if contentChange[:range] TextDocumentContentChangeEvent.new( contentChange.fetch(:text)) end.compact)) else ResponseMessage.new(nil, ResponseError::MethodNotFound.new) end @language_server.response( id, to_result(response.result), to_result(response.error)) rescue NotImplementedError ResponseMessage.new(nil, ResponseError::MethodNotFound.new) end |
#to_result(obj) ⇒ Object
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/lsp.rb', line 150 def to_result(obj) case obj when Array obj.map {|elem| to_result(elem) } when NilClass nil else obj.to_h end end |