neovim 0.2.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +10 -0
- data/lib/neovim/current.rb +19 -2
- data/lib/neovim/host.rb +3 -11
- data/lib/neovim/host/loader.rb +0 -2
- data/lib/neovim/line_range.rb +14 -2
- data/lib/neovim/plugin.rb +1 -4
- data/lib/neovim/plugin/dsl.rb +6 -14
- data/lib/neovim/plugin/handler.rb +2 -9
- data/lib/neovim/ruby_provider.rb +9 -15
- data/lib/neovim/session.rb +23 -70
- data/lib/neovim/session/api.rb +61 -0
- data/lib/neovim/session/event_loop.rb +108 -0
- data/lib/neovim/session/notification.rb +19 -0
- data/lib/neovim/session/request.rb +31 -0
- data/lib/neovim/session/rpc.rb +95 -0
- data/lib/neovim/session/serializer.rb +62 -0
- data/lib/neovim/version.rb +1 -1
- data/neovim.gemspec +1 -1
- data/spec/acceptance/neovim-ruby-host_spec.rb +0 -5
- data/spec/acceptance/ruby_provider_spec.rb +35 -3
- data/spec/helper.rb +33 -2
- data/spec/neovim/host_spec.rb +1 -1
- data/spec/neovim/plugin_spec.rb +2 -2
- data/spec/neovim/session/api_spec.rb +46 -0
- data/spec/neovim/session/event_loop_spec.rb +99 -0
- data/spec/neovim/session/rpc_spec.rb +108 -0
- data/spec/neovim/session/serializer_spec.rb +48 -0
- data/spec/neovim/session_spec.rb +1 -1
- metadata +16 -18
- data/lib/neovim/api.rb +0 -80
- data/lib/neovim/async_session.rb +0 -119
- data/lib/neovim/event_loop.rb +0 -128
- data/lib/neovim/msgpack_stream.rb +0 -80
- data/lib/neovim/notification.rb +0 -17
- data/lib/neovim/request.rb +0 -29
- data/spec/neovim/api_spec.rb +0 -44
- data/spec/neovim/async_session_spec.rb +0 -106
- data/spec/neovim/event_loop_spec.rb +0 -97
- data/spec/neovim/msgpack_stream_spec.rb +0 -46
- data/spec/support.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e51184d65bdcfaf91be38f7ed8f794d1971e2bcd
|
4
|
+
data.tar.gz: e5900e2d8a0849a2b7c195a701d07b4270ccf4e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 908119d756874c8d76e42056e2a99e009c0dc19dde6c865e9d0cbee9e33b4b1c485d08e9bf54fbfdf374f00518461122c3fe66b5119612b56afb6383319e5a9b
|
7
|
+
data.tar.gz: 097c4a2565b01b6b6cb785601de2f526ec3c7b091f7fcd054b2ab87ea5d05acb27815f8abda84b665bcbc9e1ba4dde1883ed4fc88249d34cbafd2f26eab09f5a
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# 0.3.0
|
2
|
+
- Mark `Plugin::DSL#rpc` private
|
3
|
+
- Rename Session constants:
|
4
|
+
- `Neovim::EventLoop` -> `Neovim::Session::EventLoop`
|
5
|
+
- `Neovim::MsgpackStream` -> `Neovim::Session::Serializer`
|
6
|
+
- `Neovim::AsyncSession` -> `Neovim::Session::RPC`
|
7
|
+
- `Neovim::API` -> `Neovim::Session::API`
|
8
|
+
- `Neovim::Request` -> `Neovim::Session::Request`
|
9
|
+
- `Neovim::Notification` -> `Neovim::Session::Notification`
|
10
|
+
|
1
11
|
# 0.2.5
|
2
12
|
- Optimize remote function lookup
|
3
13
|
- Fix bug where $curbuf and $curwin weren't persisting instance state between
|
data/lib/neovim/current.rb
CHANGED
@@ -3,27 +3,32 @@ require "neovim/tabpage"
|
|
3
3
|
require "neovim/window"
|
4
4
|
|
5
5
|
module Neovim
|
6
|
-
# Support for +
|
6
|
+
# Support for +Client#current+ chaining.
|
7
7
|
#
|
8
8
|
# @see Client#current
|
9
|
-
# @api private
|
10
9
|
class Current
|
11
10
|
def initialize(session)
|
12
11
|
@session = session
|
13
12
|
@range = (0..-1)
|
14
13
|
end
|
15
14
|
|
15
|
+
# Get the line under the cursor.
|
16
|
+
#
|
16
17
|
# @return [String]
|
17
18
|
def line
|
18
19
|
@session.request(:vim_get_current_line)
|
19
20
|
end
|
20
21
|
|
22
|
+
# Set the line under the cursor.
|
23
|
+
#
|
21
24
|
# @param line [String] The target line contents.
|
22
25
|
# @return [String]
|
23
26
|
def line=(line)
|
24
27
|
@session.request(:vim_set_current_line, line)
|
25
28
|
end
|
26
29
|
|
30
|
+
# Get the active buffer.
|
31
|
+
#
|
27
32
|
# @return [Buffer]
|
28
33
|
def buffer
|
29
34
|
@session.request(:vim_get_current_buffer).tap do |buf|
|
@@ -31,34 +36,46 @@ module Neovim
|
|
31
36
|
end
|
32
37
|
end
|
33
38
|
|
39
|
+
# Set the active buffer.
|
40
|
+
#
|
34
41
|
# @param buffer [Buffer, Fixnum] The target buffer or index.
|
35
42
|
# @return [Buffer, Fixnum]
|
36
43
|
def buffer=(buffer)
|
37
44
|
@session.request(:vim_set_current_buffer, buffer)
|
38
45
|
end
|
39
46
|
|
47
|
+
# Get the active window.
|
48
|
+
#
|
40
49
|
# @return [Window]
|
41
50
|
def window
|
42
51
|
@session.request(:vim_get_current_window)
|
43
52
|
end
|
44
53
|
|
54
|
+
# Set the active window.
|
55
|
+
#
|
45
56
|
# @param window [Window, Fixnum] The target window or index.
|
46
57
|
# @return [Window, Fixnum]
|
47
58
|
def window=(window)
|
48
59
|
@session.request(:vim_set_current_window, window)
|
49
60
|
end
|
50
61
|
|
62
|
+
# Get the active tabpage.
|
63
|
+
#
|
51
64
|
# @return [Tabpage]
|
52
65
|
def tabpage
|
53
66
|
@session.request(:vim_get_current_tabpage)
|
54
67
|
end
|
55
68
|
|
69
|
+
# Set the active tabpage.
|
70
|
+
#
|
56
71
|
# @param tabpage [Tabpage, Fixnum] The target tabpage or index.
|
57
72
|
# @return [Tabpage, Fixnum]
|
58
73
|
def tabpage=(tabpage)
|
59
74
|
@session.request(:vim_set_current_tabpage, tabpage)
|
60
75
|
end
|
61
76
|
|
77
|
+
# Set the current line range of the current buffer.
|
78
|
+
#
|
62
79
|
# @param range [Range] The target range
|
63
80
|
def range=(range)
|
64
81
|
@range = range
|
data/lib/neovim/host.rb
CHANGED
@@ -9,10 +9,6 @@ module Neovim
|
|
9
9
|
attr_reader :handlers, :specs
|
10
10
|
|
11
11
|
# Initialize and populate a +Host+ from a list of plugin paths.
|
12
|
-
#
|
13
|
-
# @param rplugin_paths [Array<String>]
|
14
|
-
# @return [Host]
|
15
|
-
# @see Loader#load
|
16
12
|
def self.load_from_files(rplugin_paths, options={})
|
17
13
|
session = options.fetch(:session) { Session.stdio }
|
18
14
|
client = options.fetch(:client) { Client.new(session) }
|
@@ -30,8 +26,6 @@ module Neovim
|
|
30
26
|
end
|
31
27
|
|
32
28
|
# Register a +Plugin+ to receive +Host+ messages.
|
33
|
-
#
|
34
|
-
# @param plugin [Plugin]
|
35
29
|
def register(plugin)
|
36
30
|
plugin.handlers.each do |handler|
|
37
31
|
@handlers[handler.qualified_name] = wrap_plugin_handler(handler)
|
@@ -41,8 +35,6 @@ module Neovim
|
|
41
35
|
end
|
42
36
|
|
43
37
|
# Run the event loop, passing received messages to the appropriate handler.
|
44
|
-
#
|
45
|
-
# @return [void]
|
46
38
|
def run
|
47
39
|
@session.run { |msg| handle(msg) }
|
48
40
|
rescue => e
|
@@ -52,9 +44,6 @@ module Neovim
|
|
52
44
|
|
53
45
|
# Handle messages received from the host. Sends a +Neovim::Client+ along
|
54
46
|
# with the message to be used in plugin callbacks.
|
55
|
-
#
|
56
|
-
# @param message [Neovim::Request, Neovim::Notification]
|
57
|
-
# @param client [Neovim::Client]
|
58
47
|
def handle(message)
|
59
48
|
debug("received #{message.inspect}")
|
60
49
|
|
@@ -102,9 +91,12 @@ module Neovim
|
|
102
91
|
debug("received #{message.inspect}")
|
103
92
|
args = message.arguments.flatten(1)
|
104
93
|
result = handler.call(client, *args)
|
94
|
+
|
105
95
|
message.respond(result) if message.sync?
|
106
96
|
rescue => e
|
107
97
|
warn("got unexpected error #{e.inspect}")
|
98
|
+
debug(e.backtrace.join("\n"))
|
99
|
+
|
108
100
|
message.error(e.message) if message.sync?
|
109
101
|
end
|
110
102
|
end
|
data/lib/neovim/host/loader.rb
CHANGED
@@ -9,8 +9,6 @@ module Neovim
|
|
9
9
|
# Load the provided Ruby files while temporarily overriding
|
10
10
|
# +Neovim.plugin+ to expose the remote plugin DSL and register the result
|
11
11
|
# to the host.
|
12
|
-
#
|
13
|
-
# @param paths [Array<String>]
|
14
12
|
def load(paths)
|
15
13
|
paths.each do |path|
|
16
14
|
override_plugin_method(path) do
|
data/lib/neovim/line_range.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
module Neovim
|
2
2
|
# Provide an enumerable interface for dealing with ranges of lines.
|
3
|
-
#
|
4
|
-
# @api private
|
5
3
|
class LineRange
|
6
4
|
include Enumerable
|
7
5
|
|
@@ -11,17 +9,23 @@ module Neovim
|
|
11
9
|
@end = _end
|
12
10
|
end
|
13
11
|
|
12
|
+
# Resolve to an array of lines as strings.
|
13
|
+
#
|
14
14
|
# @return [Array<String>]
|
15
15
|
def to_a
|
16
16
|
@buffer.get_line_slice(@begin, @end, true, true)
|
17
17
|
end
|
18
18
|
|
19
|
+
# Yield each line in the range.
|
20
|
+
#
|
19
21
|
# @yield [String] The current line
|
20
22
|
# @return [Array<String>]
|
21
23
|
def each(&block)
|
22
24
|
to_a.each(&block)
|
23
25
|
end
|
24
26
|
|
27
|
+
# Access the line at the given index within the range.
|
28
|
+
#
|
25
29
|
# @overload [](index)
|
26
30
|
# @param index [Fixnum]
|
27
31
|
#
|
@@ -60,6 +64,8 @@ module Neovim
|
|
60
64
|
end
|
61
65
|
alias_method :slice, :[]
|
62
66
|
|
67
|
+
# Set the line at the given index within the range.
|
68
|
+
#
|
63
69
|
# @overload []=(index, string)
|
64
70
|
# @param index [Fixnum]
|
65
71
|
# @param string [String]
|
@@ -107,18 +113,24 @@ module Neovim
|
|
107
113
|
end
|
108
114
|
end
|
109
115
|
|
116
|
+
# Replace the range of lines.
|
117
|
+
#
|
110
118
|
# @param other [Array] The replacement lines
|
111
119
|
def replace(other)
|
112
120
|
self[0..-1] = other
|
113
121
|
self
|
114
122
|
end
|
115
123
|
|
124
|
+
# Insert line(s) at the given index within the range.
|
125
|
+
#
|
116
126
|
# @param index [Fixnum]
|
117
127
|
# @param lines [String]
|
118
128
|
def insert(index, lines)
|
119
129
|
@buffer.insert(index, Array(lines))
|
120
130
|
end
|
121
131
|
|
132
|
+
# Delete the line at the given index within the range.
|
133
|
+
#
|
122
134
|
# @param index [Fixnum]
|
123
135
|
def delete(index)
|
124
136
|
@buffer.del_line(abs_line(index))
|
data/lib/neovim/plugin.rb
CHANGED
@@ -7,9 +7,6 @@ module Neovim
|
|
7
7
|
attr_reader :source
|
8
8
|
|
9
9
|
# Entrypoint to the +Neovim.plugin+ DSL.
|
10
|
-
#
|
11
|
-
# @param source [String] The path of the plugin file.
|
12
|
-
# @yield [DSL] The receiver of DSL methods.
|
13
10
|
def self.from_config_block(source)
|
14
11
|
new(source).tap do |instance|
|
15
12
|
yield DSL.new(instance) if block_given?
|
@@ -21,7 +18,7 @@ module Neovim
|
|
21
18
|
@source = source
|
22
19
|
end
|
23
20
|
|
24
|
-
#
|
21
|
+
# Return specs used by +nvim+ to register plugins.
|
25
22
|
def specs
|
26
23
|
@handlers.inject([]) do |acc, handler|
|
27
24
|
handler.qualified? ? acc + [handler.to_spec] : acc
|
data/lib/neovim/plugin/dsl.rb
CHANGED
@@ -66,23 +66,15 @@ module Neovim
|
|
66
66
|
register_handler(:autocmd, event, options, block)
|
67
67
|
end
|
68
68
|
|
69
|
-
|
70
|
-
#
|
71
|
-
# This can be used to directly expose an RPC call without a namespace.
|
72
|
-
# This is used primarily for exposing legacy ruby provider calls.
|
73
|
-
#
|
74
|
-
# @option options [Boolean] :sync (false) Whether +nvim+ should receive
|
75
|
-
# the return value of the block.
|
76
|
-
def rpc(name, options={}, &block)
|
77
|
-
sync = options.delete(:sync)
|
69
|
+
private
|
78
70
|
|
79
|
-
|
80
|
-
|
81
|
-
|
71
|
+
# Directly define a synchronous RPC call without a namespace. This is
|
72
|
+
# used for exposing legacy ruby provider calls, and not meant to be used
|
73
|
+
# publicly in plugin definitions.
|
74
|
+
def rpc(name, &block)
|
75
|
+
@plugin.handlers.push(Handler.unqualified(name, block))
|
82
76
|
end
|
83
77
|
|
84
|
-
private
|
85
|
-
|
86
78
|
def register_handler(type, name, _options, block)
|
87
79
|
if type == :autocmd
|
88
80
|
options = _options.dup
|
@@ -4,15 +4,8 @@ module Neovim
|
|
4
4
|
class Handler
|
5
5
|
attr_reader :block
|
6
6
|
|
7
|
-
def self.unqualified(name,
|
8
|
-
new(
|
9
|
-
nil,
|
10
|
-
nil,
|
11
|
-
name,
|
12
|
-
sync,
|
13
|
-
options.merge(:qualified => false),
|
14
|
-
block
|
15
|
-
)
|
7
|
+
def self.unqualified(name, block)
|
8
|
+
new(nil, nil, name, true, {:qualified => false}, block)
|
16
9
|
end
|
17
10
|
|
18
11
|
def initialize(source, type, name, sync, options, block)
|
data/lib/neovim/ruby_provider.rb
CHANGED
@@ -5,7 +5,7 @@ require "neovim/ruby_provider/window_ext"
|
|
5
5
|
module Neovim
|
6
6
|
# This class is used to define a +Neovim::Plugin+ to act as a backend for the
|
7
7
|
# legacy +:ruby+, +:rubyfile+, and +:rubydo+ Vim commands. It is autoloaded
|
8
|
-
# from +nvim+ and not intended to be
|
8
|
+
# from +nvim+ and not intended to be required directly.
|
9
9
|
#
|
10
10
|
# @api private
|
11
11
|
module RubyProvider
|
@@ -24,7 +24,7 @@ module Neovim
|
|
24
24
|
#
|
25
25
|
# This is used by the +:ruby+ command.
|
26
26
|
def self.__define_ruby_execute(plug)
|
27
|
-
plug.
|
27
|
+
plug.__send__(:rpc, :ruby_execute) do |nvim, ruby|
|
28
28
|
__wrap_client(nvim) do
|
29
29
|
eval(ruby, TOPLEVEL_BINDING, __FILE__, __LINE__)
|
30
30
|
end
|
@@ -37,7 +37,7 @@ module Neovim
|
|
37
37
|
#
|
38
38
|
# This is used by the +:rubyfile+ command.
|
39
39
|
def self.__define_ruby_execute_file(plug)
|
40
|
-
plug.
|
40
|
+
plug.__send__(:rpc, :ruby_execute_file) do |nvim, path|
|
41
41
|
__wrap_client(nvim) { load(path) }
|
42
42
|
end
|
43
43
|
end
|
@@ -52,7 +52,7 @@ module Neovim
|
|
52
52
|
#
|
53
53
|
# This is used by the +:rubydo+ command.
|
54
54
|
def self.__define_ruby_do_range(__plug)
|
55
|
-
__plug.
|
55
|
+
__plug.__send__(:rpc, :ruby_do_range) do |__nvim, *__args|
|
56
56
|
__wrap_client(__nvim) do
|
57
57
|
__start, __stop, __ruby = __args
|
58
58
|
__buffer = __nvim.get_current_buffer
|
@@ -69,7 +69,6 @@ module Neovim
|
|
69
69
|
end
|
70
70
|
private_class_method :__define_ruby_do_range
|
71
71
|
|
72
|
-
# @api private
|
73
72
|
def self.__wrap_client(client)
|
74
73
|
__with_globals(client) do
|
75
74
|
__with_vim_constant(client) do
|
@@ -82,34 +81,30 @@ module Neovim
|
|
82
81
|
end
|
83
82
|
private_class_method :__wrap_client
|
84
83
|
|
85
|
-
# @api private
|
86
84
|
def self.__with_globals(client)
|
87
85
|
@__buffer_cache ||= {}
|
88
86
|
@__window_cache ||= {}
|
89
87
|
|
90
|
-
|
91
|
-
__winnr = client.evaluate("winnr()")
|
88
|
+
bufnr, winnr = client.evaluate("[bufnr('%'), winnr()]")
|
92
89
|
|
93
|
-
$curbuf = @__buffer_cache.fetch(
|
94
|
-
@__buffer_cache[
|
90
|
+
$curbuf = @__buffer_cache.fetch(bufnr) do
|
91
|
+
@__buffer_cache[bufnr] = client.get_current_buffer
|
95
92
|
end
|
96
93
|
|
97
|
-
$curwin = @__window_cache.fetch(
|
98
|
-
@__window_cache[
|
94
|
+
$curwin = @__window_cache.fetch(winnr) do
|
95
|
+
@__window_cache[winnr] = client.get_current_window
|
99
96
|
end
|
100
97
|
|
101
98
|
yield
|
102
99
|
end
|
103
100
|
private_class_method :__with_globals
|
104
101
|
|
105
|
-
# @api private
|
106
102
|
def self.__with_vim_constant(client)
|
107
103
|
::VIM.__client = client
|
108
104
|
yield
|
109
105
|
end
|
110
106
|
private_class_method :__with_vim_constant
|
111
107
|
|
112
|
-
# @api private
|
113
108
|
def self.__with_redirect_streams(client)
|
114
109
|
@__with_redirect_streams ||= begin
|
115
110
|
$stdout.define_singleton_method(:write) do |string|
|
@@ -127,7 +122,6 @@ module Neovim
|
|
127
122
|
end
|
128
123
|
private_class_method :__with_redirect_streams
|
129
124
|
|
130
|
-
# @api private
|
131
125
|
def self.__update_lines_in_chunks(buffer, start, stop, size)
|
132
126
|
(start..stop).each_slice(size) do |linenos|
|
133
127
|
_start, _stop = linenos[0]-1, linenos[-1]
|
data/lib/neovim/session.rb
CHANGED
@@ -1,63 +1,47 @@
|
|
1
|
-
require "neovim/api"
|
2
|
-
require "neovim/async_session"
|
3
|
-
require "neovim/event_loop"
|
4
1
|
require "neovim/logging"
|
5
|
-
require "neovim/
|
2
|
+
require "neovim/session/api"
|
3
|
+
require "neovim/session/event_loop"
|
4
|
+
require "neovim/session/rpc"
|
5
|
+
require "neovim/session/serializer"
|
6
6
|
require "fiber"
|
7
7
|
|
8
8
|
module Neovim
|
9
|
-
# Wraps
|
9
|
+
# Wraps a +Session::RPC+ in a synchronous API using +Fiber+s.
|
10
10
|
#
|
11
11
|
# @api private
|
12
12
|
class Session
|
13
13
|
include Logging
|
14
14
|
|
15
15
|
# Connect to a TCP socket.
|
16
|
-
#
|
17
|
-
# @param host [String] The hostname or IP address
|
18
|
-
# @param port [Fixnum] The port
|
19
|
-
# @return [Session]
|
20
|
-
# @see EventLoop.tcp
|
21
16
|
def self.tcp(host, port)
|
22
17
|
from_event_loop(EventLoop.tcp(host, port))
|
23
18
|
end
|
24
19
|
|
25
20
|
# Connect to a UNIX domain socket.
|
26
|
-
#
|
27
|
-
# @param socket_path [String] The socket path
|
28
|
-
# @return [Session]
|
29
|
-
# @see EventLoop.unix
|
30
21
|
def self.unix(socket_path)
|
31
22
|
from_event_loop(EventLoop.unix(socket_path))
|
32
23
|
end
|
33
24
|
|
34
25
|
# Spawn and connect to a child +nvim+ process.
|
35
|
-
#
|
36
|
-
# @param argv [Array] The arguments to pass to the spawned process
|
37
|
-
# @return [Session]
|
38
|
-
# @see EventLoop.child
|
39
26
|
def self.child(argv)
|
40
27
|
from_event_loop(EventLoop.child(argv))
|
41
28
|
end
|
42
29
|
|
43
30
|
# Connect to the current process's standard streams. This is used to
|
44
31
|
# promote the current process to a Ruby plugin host.
|
45
|
-
#
|
46
|
-
# @return [Session]
|
47
|
-
# @see EventLoop.stdio
|
48
32
|
def self.stdio
|
49
33
|
from_event_loop(EventLoop.stdio)
|
50
34
|
end
|
51
35
|
|
52
36
|
def self.from_event_loop(event_loop)
|
53
|
-
|
54
|
-
|
55
|
-
new(
|
37
|
+
serializer = Serializer.new(event_loop)
|
38
|
+
rpc = RPC.new(serializer)
|
39
|
+
new(rpc)
|
56
40
|
end
|
57
41
|
private_class_method :from_event_loop
|
58
42
|
|
59
|
-
def initialize(
|
60
|
-
@
|
43
|
+
def initialize(rpc)
|
44
|
+
@rpc = rpc
|
61
45
|
@pending_messages = []
|
62
46
|
@main_thread = Thread.current
|
63
47
|
@main_fiber = Fiber.current
|
@@ -66,31 +50,19 @@ module Neovim
|
|
66
50
|
|
67
51
|
# Return the +nvim+ API as described in the +vim_get_api_info+ call.
|
68
52
|
# Defaults to empty API information.
|
69
|
-
#
|
70
|
-
# @return [API]
|
71
|
-
# @see API.null
|
72
53
|
def api
|
73
54
|
@api ||= API.null
|
74
55
|
end
|
75
56
|
|
76
57
|
# Discover the +nvim+ API as described in the +vim_get_api_info+ call,
|
77
58
|
# propagating it down to lower layers of the stack.
|
78
|
-
#
|
79
|
-
# @return [API]
|
80
|
-
# @see API
|
81
59
|
def discover_api
|
82
60
|
@api = API.new(request(:vim_get_api_info)).tap do |api|
|
83
|
-
@
|
61
|
+
@rpc.serializer.register_types(api, self)
|
84
62
|
end
|
85
63
|
end
|
86
64
|
|
87
65
|
# Run the event loop, handling messages in a +Fiber+.
|
88
|
-
#
|
89
|
-
# @yield [Object]
|
90
|
-
# @return [void]
|
91
|
-
# @see AsyncSession#run
|
92
|
-
# @see MsgpackStream#run
|
93
|
-
# @see EventLoop#run
|
94
66
|
def run
|
95
67
|
@running = true
|
96
68
|
|
@@ -100,7 +72,7 @@ module Neovim
|
|
100
72
|
|
101
73
|
return unless @running
|
102
74
|
|
103
|
-
@
|
75
|
+
@rpc.run do |message|
|
104
76
|
Fiber.new { yield message if block_given? }.resume
|
105
77
|
end
|
106
78
|
ensure
|
@@ -117,11 +89,6 @@ module Neovim
|
|
117
89
|
# If this method is called outside a callback, write to the stream and
|
118
90
|
# run the event loop until a response is received. Messages received
|
119
91
|
# in the meantime are enqueued to be handled later.
|
120
|
-
#
|
121
|
-
# @param method [String, Symbol] The RPC method name
|
122
|
-
# @param *args [Array] The RPC method arguments
|
123
|
-
# @return [Object] The response from the RPC call
|
124
|
-
# @raise [ArgumentError] An error returned from +nvim+
|
125
92
|
def request(method, *args)
|
126
93
|
main_thread_only do
|
127
94
|
if Fiber.current == @main_fiber
|
@@ -136,48 +103,34 @@ module Neovim
|
|
136
103
|
end
|
137
104
|
end
|
138
105
|
|
139
|
-
# Make an RPC notification.
|
140
|
-
#
|
141
|
-
# @param method [String, Symbol] The RPC method name
|
142
|
-
# @param *args [Array] The RPC method arguments
|
143
|
-
# @return [nil]
|
106
|
+
# Make an RPC notification. +nvim+ will not block waiting for a response.
|
144
107
|
def notify(method, *args)
|
145
108
|
main_thread_only do
|
146
|
-
@
|
109
|
+
@rpc.notify(method, *args)
|
147
110
|
nil
|
148
111
|
end
|
149
112
|
end
|
150
113
|
|
151
|
-
#
|
152
|
-
|
153
|
-
|
154
|
-
|
114
|
+
# Return the channel ID if registered via +vim_get_api_info+.
|
115
|
+
def channel_id
|
116
|
+
api.channel_id
|
117
|
+
end
|
118
|
+
|
155
119
|
def stop
|
156
120
|
@running = false
|
157
|
-
@
|
121
|
+
@rpc.stop
|
158
122
|
end
|
159
123
|
|
160
|
-
# Shut down the event loop.
|
161
|
-
#
|
162
|
-
# @return [void]
|
163
|
-
# @see EventLoop#shutdown
|
164
124
|
def shutdown
|
165
125
|
@running = false
|
166
|
-
@
|
167
|
-
end
|
168
|
-
|
169
|
-
# Return the channel ID if registered via +vim_get_api_info+.
|
170
|
-
#
|
171
|
-
# @return [Fixnum, nil]
|
172
|
-
def channel_id
|
173
|
-
api.channel_id
|
126
|
+
@rpc.shutdown
|
174
127
|
end
|
175
128
|
|
176
129
|
private
|
177
130
|
|
178
131
|
def running_request(method, *args)
|
179
132
|
fiber = Fiber.current
|
180
|
-
@
|
133
|
+
@rpc.request(method, *args) do |err, res|
|
181
134
|
fiber.resume(err, res)
|
182
135
|
end
|
183
136
|
Fiber.yield
|
@@ -186,7 +139,7 @@ module Neovim
|
|
186
139
|
def stopped_request(method, *args)
|
187
140
|
error, result = nil
|
188
141
|
|
189
|
-
@
|
142
|
+
@rpc.request(method, *args) do |err, res|
|
190
143
|
error, result = err, res
|
191
144
|
stop
|
192
145
|
end.run do |message|
|