Class: Neovim::Session
- Inherits:
-
Object
- Object
- Neovim::Session
- Defined in:
- lib/neovim/session.rb
Overview
Wraps an AsyncSession in a synchronous API using Fibers.
Class Method Summary collapse
-
.child(argv) ⇒ Session
Spawn and connect to a child
nvimprocess. -
.stdio ⇒ Session
Connect to the current process’s standard streams.
-
.tcp(host, port) ⇒ Session
Connect to a TCP socket.
-
.unix(socket_path) ⇒ Session
Connect to a UNIX domain socket.
Instance Method Summary collapse
-
#api ⇒ API
Return the
nvimAPI as described in thevim_get_api_infocall. -
#discover_api ⇒ self
Discover the
nvimAPI as described in thevim_get_api_infocall. -
#initialize(async_session) ⇒ Session
constructor
A new instance of Session.
-
#notify(method, *args) ⇒ nil
Make an RPC notification.
-
#request(method, *args) ⇒ Object
Make an RPC request and return its response.
-
#run {|Object| ... } ⇒ void
Run the event loop, handling messages in a
Fiber. -
#shutdown ⇒ void
Shut down the event loop.
-
#stop ⇒ void
Stop the event loop.
Constructor Details
#initialize(async_session) ⇒ Session
Returns a new instance of Session.
51 52 53 54 55 56 |
# File 'lib/neovim/session.rb', line 51 def initialize(async_session) @async_session = async_session @pending_messages = [] @in_handler = false @running = false end |
Class Method Details
.child(argv) ⇒ Session
Spawn and connect to a child nvim process.
31 32 33 |
# File 'lib/neovim/session.rb', line 31 def self.child(argv) from_event_loop(EventLoop.child(argv)) end |
.stdio ⇒ Session
Connect to the current process’s standard streams. This is used to promote the current process to a Ruby plugin host.
40 41 42 |
# File 'lib/neovim/session.rb', line 40 def self.stdio from_event_loop(EventLoop.stdio) end |
Instance Method Details
#api ⇒ API
Return the nvim API as described in the vim_get_api_info call. Defaults to empty API information.
63 64 65 |
# File 'lib/neovim/session.rb', line 63 def api @api ||= API.null end |
#discover_api ⇒ self
Discover the nvim API as described in the vim_get_api_info call.
71 72 73 74 |
# File 'lib/neovim/session.rb', line 71 def discover_api @api = API.new(request(:vim_get_api_info)) self end |
#notify(method, *args) ⇒ nil
Make an RPC notification
129 130 131 132 |
# File 'lib/neovim/session.rb', line 129 def notify(method, *args) @async_session.notify(method, *args) nil end |
#request(method, *args) ⇒ Object
Make an RPC request and return its response.
If this method is called inside a callback, we are already inside a Fiber handler. In that case, we write to the stream and yield the Fiber. Once the response is received, resume the Fiber and return the result.
If this method is called outside a callback, write to the stream and run the event loop until a response is received. Messages received in the meantime are enqueued to be handled later.
114 115 116 117 118 119 120 121 122 |
# File 'lib/neovim/session.rb', line 114 def request(method, *args) if @in_handler err, res = running_request(method, *args) else err, res = stopped_request(method, *args) end err ? raise(ArgumentError, err) : res end |
#run {|Object| ... } ⇒ void
This method returns an undefined value.
Run the event loop, handling messages in a Fiber.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/neovim/session.rb', line 83 def run @running = true while = @pending_messages.shift in_handler_fiber { yield if block_given? } end return unless @running @async_session.run(self) do || in_handler_fiber { yield if block_given? } end ensure stop end |
#shutdown ⇒ void
This method returns an undefined value.
Shut down the event loop
147 148 149 150 |
# File 'lib/neovim/session.rb', line 147 def shutdown @running = false @async_session.shutdown end |
#stop ⇒ void
This method returns an undefined value.
Stop the event loop
138 139 140 141 |
# File 'lib/neovim/session.rb', line 138 def stop @running = false @async_session.stop end |