Class: Neovim::EventLoop Private

Inherits:
Object show all
Includes:
Logging
Defined in:
lib/neovim/event_loop.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary

Constants included from Logging

Logging::TIMESTAMP_FORMAT

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, logger, logger=

Constructor Details

#initialize(connection) ⇒ EventLoop

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of EventLoop.



26
27
28
29
30
# File 'lib/neovim/event_loop.rb', line 26

def initialize(connection)
  @running = false
  @shutdown = false
  @connection = connection
end

Class Method Details

.child(argv) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



18
19
20
# File 'lib/neovim/event_loop.rb', line 18

def self.child(argv)
  new Connection.child(argv)
end

.stdioObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
# File 'lib/neovim/event_loop.rb', line 22

def self.stdio
  new Connection.stdio
end

.tcp(host, port) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/neovim/event_loop.rb', line 10

def self.tcp(host, port)
  new Connection.tcp(host, port)
end

.unix(path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
# File 'lib/neovim/event_loop.rb', line 14

def self.unix(path)
  new Connection.unix(path)
end

Instance Method Details

#notify(method, *args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



66
67
68
69
# File 'lib/neovim/event_loop.rb', line 66

def notify(method, *args)
  log(:debug) { {name: method, arguments: args} }
  write(:notification, method, args)
end

#register_types(api, session) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/neovim/event_loop.rb', line 94

def register_types(api, session)
  api.types.each do |type, info|
    id = info.fetch("id")
    klass = Neovim.const_get(type)
    log(:debug) { {type: type, id: id} }

    @connection.register_type(id) do |index|
      klass.new(index, session, api)
    end
  end
end

#request(request_id, method, *args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/neovim/event_loop.rb', line 42

def request(request_id, method, *args)
  log(:debug) do
    {
      request_id: request_id,
      method: method,
      arguments: args
    }
  end

  write(:request, request_id, method, args)
end

#respond(request_id, return_value, error) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/neovim/event_loop.rb', line 54

def respond(request_id, return_value, error)
  log(:debug) do
    {
      request_id: request_id,
      return_value: return_value,
      error: error
    }
  end

  write(:response, request_id, error, return_value)
end

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/neovim/event_loop.rb', line 71

def run
  @running = true
  last_value = nil

  loop do
    break unless @running
    break if @shutdown

    begin
      last_value = yield(read)
    rescue EOFError, Errno::EPIPE => e
      log_exception(:debug, e, __method__)
      shutdown
    rescue => e
      log_exception(:error, e, __method__)
    end
  end

  last_value
ensure
  @connection.close if @shutdown
end

#shutdownObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



36
37
38
39
40
# File 'lib/neovim/event_loop.rb', line 36

def shutdown
  @running = false
  @shutdown = true
  @connection.close
end

#stopObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



32
33
34
# File 'lib/neovim/event_loop.rb', line 32

def stop
  @running = false
end