Class: Neovim::Remote
Direct Known Subclasses
Defined Under Namespace
Classes: Disconnected, Message, ResponseError
Constant Summary
Constants included from Logging
Logging::DEFAULT_LEVEL, Logging::LEVELS
Class Method Summary collapse
- .open(conntype, *args, **kwargs) ⇒ Object
- .open_conn(conntype, *args, **kwargs) ⇒ Object
- .start(plugins, *args) ⇒ Object
- .start_client(*args) ⇒ Object
Instance Method Summary collapse
- #client_methods ⇒ Object
- #client_name ⇒ Object
- #client_type ⇒ Object
-
#initialize(plugins, conn) ⇒ Remote
constructor
A new instance of Remote.
- #notify(method, *args) ⇒ Object
- #request(method, *args) ⇒ Object
- #run(until_id = nil) ⇒ Object
- #start ⇒ Object
Methods included from Logging
Constructor Details
#initialize(plugins, conn) ⇒ Remote
Returns a new instance of Remote.
143 144 145 146 147 148 149 |
# File 'lib/neovim/remote.rb', line 143 def initialize plugins, conn @conn = conn @request_id = 0 @responses = {} @plugins = {} @plugins.update plugins if plugins end |
Class Method Details
.open(conntype, *args, **kwargs) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/neovim/remote.rb', line 116 def open conntype, *args, **kwargs open_conn conntype, *args, **kwargs do |conn| i = new nil, conn yield i end end |
.open_conn(conntype, *args, **kwargs) ⇒ Object
108 109 110 111 112 |
# File 'lib/neovim/remote.rb', line 108 def open_conn conntype, *args, **kwargs conntype.open_files *args, **kwargs do |conn| yield conn end end |
.start(plugins, *args) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/neovim/remote.rb', line 123 def start plugins, *args open_logfile do log :info, "Starting", args: $* open_conn *args do |conn| i = new plugins, conn yield i end ensure log :info, "Leaving" end end |
.start_client(*args) ⇒ Object
135 136 137 138 139 |
# File 'lib/neovim/remote.rb', line 135 def start_client *args start nil, *args do |i| yield i.start end end |
Instance Method Details
#client_methods ⇒ Object
166 167 168 169 170 171 172 173 |
# File 'lib/neovim/remote.rb', line 166 def client_methods l = @plugins.values.reject { |p| p.type } if l.notempty? then r = {} l.each { |p| p. { |name,opts| r[ name] = opts } } r end end |
#client_name ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/neovim/remote.rb', line 151 def client_name l = @plugins.values.select { |p| p.type } if l.notempty? then l.map! { |p| p.type } l.uniq! name = l.join "-" log :info, "Client Name", name: name "ruby-#{name}-host" else "ruby-client" end end |
#client_type ⇒ Object
164 |
# File 'lib/neovim/remote.rb', line 164 def client_type ; self.class.plain_name.downcase ; end |
#notify(method, *args) ⇒ Object
240 241 242 |
# File 'lib/neovim/remote.rb', line 240 def notify method, *args put Message::Notification[ method, args] end |
#request(method, *args) ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/neovim/remote.rb', line 226 def request method, *args rid = @request_id = @request_id.succ put Message::Request[ rid, method, args] @responses[ rid] = nil run rid r = @responses.delete rid if r.error then t, e = *r.error t = @conn.error t raise ResponseError, "#{t}: #{e}" end r.value end |
#run(until_id = nil) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/neovim/remote.rb', line 181 def run until_id = nil loop do if @deferred and @conn.client then d, @deferred = @deferred, nil d.each { |p| p.call } end = get case when Message::Response then if @responses.key? .request_id then @responses[ .request_id] = else log :warning, "Dropped response", .request_id end when Message::Request, Message::Notification then h = find_handler .method_name if h then p = proc do begin log :debug1, "Calling handler", name: .method_name, args: .arguments r = h.execute @conn.client, *.arguments log :debug1, "Handler result", result: r rescue e = [ 0, $!.to_s] log_exception :error end put Message::Response[ .request_id, e, r] if .respond_to? :request_id end if @conn.client or not h.needs_client? then p.call else log :info, "Deferred handler for", name: .method_name @deferred ||= [] @deferred.push p end else if .respond_to? :request_id then put Message::Response[ .request_id, [0, "No handler #{.method_name}."], nil] end end end break if until_id and @responses[ until_id] end end |
#start ⇒ Object
176 177 178 179 |
# File 'lib/neovim/remote.rb', line 176 def start @conn.start self @conn.client end |