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
data/spec/helper.rb
CHANGED
@@ -3,8 +3,7 @@ require "neovim"
|
|
3
3
|
require "pry"
|
4
4
|
require "stringio"
|
5
5
|
require "timeout"
|
6
|
-
|
7
|
-
require File.expand_path("../support.rb", __FILE__)
|
6
|
+
require "fileutils"
|
8
7
|
|
9
8
|
if ENV["REPORT_COVERAGE"]
|
10
9
|
require "coveralls"
|
@@ -50,4 +49,36 @@ RSpec.configure do |config|
|
|
50
49
|
Kernel.srand config.seed
|
51
50
|
end
|
52
51
|
|
52
|
+
module Support
|
53
|
+
def self.workspace
|
54
|
+
File.expand_path("../workspace", __FILE__)
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.socket_path
|
58
|
+
file_path("nvim.sock")
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.port
|
62
|
+
server = TCPServer.new("0.0.0.0", 0)
|
63
|
+
|
64
|
+
begin
|
65
|
+
server.addr[1]
|
66
|
+
ensure
|
67
|
+
server.close
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.file_path(name)
|
72
|
+
File.join(workspace, name)
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.setup_workspace
|
76
|
+
FileUtils.mkdir_p(workspace)
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.teardown_workspace
|
80
|
+
FileUtils.rm_rf(workspace)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
53
84
|
Thread.abort_on_exception = true
|
data/spec/neovim/host_spec.rb
CHANGED
data/spec/neovim/plugin_spec.rb
CHANGED
@@ -67,7 +67,7 @@ module Neovim
|
|
67
67
|
cmd_block = Proc.new {}
|
68
68
|
|
69
69
|
plugin = Plugin.from_config_block("source") do |plug|
|
70
|
-
plug.rpc
|
70
|
+
plug.__send__(:rpc, "Foo", &cmd_block)
|
71
71
|
end
|
72
72
|
|
73
73
|
expect(plugin.handlers.size).to be(1)
|
@@ -98,7 +98,7 @@ module Neovim
|
|
98
98
|
|
99
99
|
it "doesn't include specs for top-level RPCs" do
|
100
100
|
plugin = Plugin.from_config_block("source") do |plug|
|
101
|
-
plug.rpc
|
101
|
+
plug.__send__(:rpc, "Foo")
|
102
102
|
end
|
103
103
|
|
104
104
|
expect(plugin.specs).to eq([])
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
module Neovim
|
4
|
+
class Session
|
5
|
+
RSpec.describe API do
|
6
|
+
describe ".null" do
|
7
|
+
it "returns an empty API object" do
|
8
|
+
api = API.null
|
9
|
+
|
10
|
+
expect(api.types).to be_empty
|
11
|
+
expect(api.functions).to be_empty
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#function" do
|
16
|
+
it "returns a corresponding Function object" do
|
17
|
+
api = API.new(
|
18
|
+
[nil, {"functions" => [
|
19
|
+
{"name" => "vim_strwidth", "async" => false}
|
20
|
+
]}]
|
21
|
+
)
|
22
|
+
|
23
|
+
function = api.function("vim_strwidth")
|
24
|
+
expect(function).to be_a(API::Function)
|
25
|
+
expect(function.name).to eq("vim_strwidth")
|
26
|
+
expect(function.async).to be(false)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#functions_with_prefix" do
|
31
|
+
it "returns relevant functions" do
|
32
|
+
api = API.new(
|
33
|
+
[nil, {"functions" => [
|
34
|
+
{"name" => "vim_strwidth"},
|
35
|
+
{"name" => "buffer_get_lines"}
|
36
|
+
]}]
|
37
|
+
)
|
38
|
+
|
39
|
+
functions = api.functions_with_prefix("vim_")
|
40
|
+
expect(functions.size).to be(1)
|
41
|
+
expect(functions.first.name).to eq("vim_strwidth")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "socket"
|
3
|
+
|
4
|
+
module Neovim
|
5
|
+
class Session
|
6
|
+
RSpec.describe EventLoop do
|
7
|
+
shared_context "socket behavior" do
|
8
|
+
it "sends and receives data" do
|
9
|
+
request = nil
|
10
|
+
|
11
|
+
server_thread = Thread.new do
|
12
|
+
client = server.accept
|
13
|
+
request = client.readpartial(1024)
|
14
|
+
|
15
|
+
client.write("res")
|
16
|
+
client.close
|
17
|
+
server.close
|
18
|
+
end
|
19
|
+
|
20
|
+
response = nil
|
21
|
+
event_loop.write("req").run do |msg|
|
22
|
+
response = msg
|
23
|
+
event_loop.stop
|
24
|
+
end
|
25
|
+
|
26
|
+
server_thread.join
|
27
|
+
event_loop.shutdown
|
28
|
+
expect(request).to eq("req")
|
29
|
+
expect(response).to eq("res")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "tcp" do
|
34
|
+
let!(:server) { TCPServer.new("0.0.0.0", 0) }
|
35
|
+
let!(:event_loop) { EventLoop.tcp("0.0.0.0", server.addr[1]) }
|
36
|
+
|
37
|
+
include_context "socket behavior"
|
38
|
+
end
|
39
|
+
|
40
|
+
context "unix" do
|
41
|
+
let!(:server) { UNIXServer.new(Support.socket_path) }
|
42
|
+
let!(:event_loop) { EventLoop.unix(Support.socket_path) }
|
43
|
+
|
44
|
+
include_context "socket behavior"
|
45
|
+
end
|
46
|
+
|
47
|
+
context "stdio" do
|
48
|
+
it "sends and receives data" do
|
49
|
+
old_stdout = STDOUT.dup
|
50
|
+
old_stdin = STDIN.dup
|
51
|
+
|
52
|
+
begin
|
53
|
+
srv_stdout, cl_stdout = IO.pipe
|
54
|
+
cl_stdin, srv_stdin = IO.pipe
|
55
|
+
|
56
|
+
STDOUT.reopen(cl_stdout)
|
57
|
+
STDIN.reopen(cl_stdin)
|
58
|
+
|
59
|
+
event_loop = EventLoop.stdio
|
60
|
+
request = nil
|
61
|
+
|
62
|
+
server_thread = Thread.new do
|
63
|
+
request = srv_stdout.readpartial(1024)
|
64
|
+
srv_stdin.write("res")
|
65
|
+
end
|
66
|
+
|
67
|
+
response = nil
|
68
|
+
event_loop.write("req").run do |msg|
|
69
|
+
response = msg
|
70
|
+
event_loop.stop
|
71
|
+
end
|
72
|
+
|
73
|
+
server_thread.join
|
74
|
+
expect(request).to eq("req")
|
75
|
+
expect(response).to eq("res")
|
76
|
+
ensure
|
77
|
+
STDOUT.reopen(old_stdout)
|
78
|
+
STDIN.reopen(old_stdin)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "child" do
|
84
|
+
it "sends and receives data" do
|
85
|
+
event_loop = EventLoop.child(["nvim", "-n", "-u", "NONE"])
|
86
|
+
input = MessagePack.pack([0, 0, :vim_strwidth, ["hi"]])
|
87
|
+
|
88
|
+
response = nil
|
89
|
+
event_loop.write(input).run do |msg|
|
90
|
+
response = msg
|
91
|
+
event_loop.shutdown
|
92
|
+
end
|
93
|
+
|
94
|
+
expect(response).to eq(MessagePack.pack([1, 0, nil, 2]))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
module Neovim
|
4
|
+
class Session
|
5
|
+
RSpec.describe RPC do
|
6
|
+
shared_context "rpc behavior" do
|
7
|
+
it "receives requests" do
|
8
|
+
serializer = Serializer.new(event_loop)
|
9
|
+
rpc = RPC.new(serializer)
|
10
|
+
|
11
|
+
server_thread = Thread.new do
|
12
|
+
client = server.accept
|
13
|
+
client.write(
|
14
|
+
MessagePack.pack(
|
15
|
+
[0, 123, "func", [1, 2, 3]]
|
16
|
+
)
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
request = nil
|
21
|
+
rpc.run do |msg|
|
22
|
+
request = msg
|
23
|
+
rpc.shutdown
|
24
|
+
end
|
25
|
+
|
26
|
+
server_thread.join
|
27
|
+
|
28
|
+
expect(request).to be_a(Request)
|
29
|
+
expect(request.method_name).to eq("func")
|
30
|
+
expect(request.arguments).to eq([1, 2, 3])
|
31
|
+
end
|
32
|
+
|
33
|
+
it "receives notifications" do
|
34
|
+
serializer = Serializer.new(event_loop)
|
35
|
+
rpc = RPC.new(serializer)
|
36
|
+
|
37
|
+
server_thread = Thread.new do
|
38
|
+
client = server.accept
|
39
|
+
client.write(
|
40
|
+
MessagePack.pack(
|
41
|
+
[2, "func", [1, 2, 3]]
|
42
|
+
)
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
notification = nil
|
47
|
+
rpc.run do |message|
|
48
|
+
notification = message
|
49
|
+
rpc.shutdown
|
50
|
+
end
|
51
|
+
|
52
|
+
server_thread.join
|
53
|
+
|
54
|
+
expect(notification).to be_a(Notification)
|
55
|
+
expect(notification.method_name).to eq("func")
|
56
|
+
expect(notification.arguments).to eq([1, 2, 3])
|
57
|
+
end
|
58
|
+
|
59
|
+
it "receives responses to requests" do
|
60
|
+
serializer = Serializer.new(event_loop)
|
61
|
+
rpc = RPC.new(serializer)
|
62
|
+
request = nil
|
63
|
+
|
64
|
+
server_thread = Thread.new do
|
65
|
+
client = server.accept
|
66
|
+
request = client.readpartial(1024)
|
67
|
+
|
68
|
+
client.write(
|
69
|
+
MessagePack.pack(
|
70
|
+
[1, 0, [0, "error"], "result"]
|
71
|
+
)
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
error, result = nil
|
76
|
+
rpc.request("func", 1, 2, 3) do |err, res|
|
77
|
+
error, result = err, res
|
78
|
+
rpc.shutdown
|
79
|
+
end.run
|
80
|
+
|
81
|
+
expect(error).to eq("error")
|
82
|
+
expect(result).to eq("result")
|
83
|
+
|
84
|
+
server_thread.join
|
85
|
+
rpc.shutdown
|
86
|
+
|
87
|
+
expect(request).to eq(
|
88
|
+
MessagePack.pack([0, 0, "func", [1, 2, 3]])
|
89
|
+
)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "tcp" do
|
94
|
+
let!(:server) { TCPServer.new("0.0.0.0", 0) }
|
95
|
+
let!(:event_loop) { EventLoop.tcp("0.0.0.0", server.addr[1]) }
|
96
|
+
|
97
|
+
include_context "rpc behavior"
|
98
|
+
end
|
99
|
+
|
100
|
+
context "unix" do
|
101
|
+
let!(:server) { UNIXServer.new(Support.socket_path) }
|
102
|
+
let!(:event_loop) { EventLoop.unix(Support.socket_path) }
|
103
|
+
|
104
|
+
include_context "rpc behavior"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "socket"
|
2
|
+
require "helper"
|
3
|
+
|
4
|
+
module Neovim
|
5
|
+
class Session
|
6
|
+
RSpec.describe Serializer do
|
7
|
+
shared_context "serializer behavior" do
|
8
|
+
it "sends and receives data" do
|
9
|
+
serializer = Serializer.new(event_loop)
|
10
|
+
request = nil
|
11
|
+
|
12
|
+
server_thread = Thread.new do
|
13
|
+
client = server.accept
|
14
|
+
request = client.readpartial(1024)
|
15
|
+
|
16
|
+
client.write(MessagePack.pack(["res"]))
|
17
|
+
client.close
|
18
|
+
server.close
|
19
|
+
end
|
20
|
+
|
21
|
+
response = nil
|
22
|
+
serializer.write(["req"]).run do |message|
|
23
|
+
response = message
|
24
|
+
serializer.shutdown
|
25
|
+
end
|
26
|
+
|
27
|
+
server_thread.join
|
28
|
+
expect(request).to eq(MessagePack.pack(["req"]))
|
29
|
+
expect(response).to eq(["res"])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "tcp" do
|
34
|
+
let!(:server) { TCPServer.new("0.0.0.0", 0) }
|
35
|
+
let!(:event_loop) { EventLoop.tcp("0.0.0.0", server.addr[1]) }
|
36
|
+
|
37
|
+
include_context "serializer behavior"
|
38
|
+
end
|
39
|
+
|
40
|
+
context "unix" do
|
41
|
+
let!(:server) { UNIXServer.new(Support.socket_path) }
|
42
|
+
let!(:event_loop) { EventLoop.unix(Support.socket_path) }
|
43
|
+
|
44
|
+
include_context "serializer behavior"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/spec/neovim/session_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neovim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Genco
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -100,28 +100,28 @@ files:
|
|
100
100
|
- bin/mp2j
|
101
101
|
- bin/neovim-ruby-host
|
102
102
|
- lib/neovim.rb
|
103
|
-
- lib/neovim/api.rb
|
104
|
-
- lib/neovim/async_session.rb
|
105
103
|
- lib/neovim/buffer.rb
|
106
104
|
- lib/neovim/client.rb
|
107
105
|
- lib/neovim/current.rb
|
108
|
-
- lib/neovim/event_loop.rb
|
109
106
|
- lib/neovim/host.rb
|
110
107
|
- lib/neovim/host/loader.rb
|
111
108
|
- lib/neovim/line_range.rb
|
112
109
|
- lib/neovim/logging.rb
|
113
|
-
- lib/neovim/msgpack_stream.rb
|
114
|
-
- lib/neovim/notification.rb
|
115
110
|
- lib/neovim/plugin.rb
|
116
111
|
- lib/neovim/plugin/dsl.rb
|
117
112
|
- lib/neovim/plugin/handler.rb
|
118
113
|
- lib/neovim/remote_object.rb
|
119
|
-
- lib/neovim/request.rb
|
120
114
|
- lib/neovim/ruby_provider.rb
|
121
115
|
- lib/neovim/ruby_provider/buffer_ext.rb
|
122
116
|
- lib/neovim/ruby_provider/vim.rb
|
123
117
|
- lib/neovim/ruby_provider/window_ext.rb
|
124
118
|
- lib/neovim/session.rb
|
119
|
+
- lib/neovim/session/api.rb
|
120
|
+
- lib/neovim/session/event_loop.rb
|
121
|
+
- lib/neovim/session/notification.rb
|
122
|
+
- lib/neovim/session/request.rb
|
123
|
+
- lib/neovim/session/rpc.rb
|
124
|
+
- lib/neovim/session/serializer.rb
|
125
125
|
- lib/neovim/tabpage.rb
|
126
126
|
- lib/neovim/version.rb
|
127
127
|
- lib/neovim/window.rb
|
@@ -129,24 +129,23 @@ files:
|
|
129
129
|
- spec/acceptance/neovim-ruby-host_spec.rb
|
130
130
|
- spec/acceptance/ruby_provider_spec.rb
|
131
131
|
- spec/helper.rb
|
132
|
-
- spec/neovim/api_spec.rb
|
133
|
-
- spec/neovim/async_session_spec.rb
|
134
132
|
- spec/neovim/buffer_spec.rb
|
135
133
|
- spec/neovim/client_spec.rb
|
136
134
|
- spec/neovim/current_spec.rb
|
137
|
-
- spec/neovim/event_loop_spec.rb
|
138
135
|
- spec/neovim/host/loader_spec.rb
|
139
136
|
- spec/neovim/host_spec.rb
|
140
137
|
- spec/neovim/line_range_spec.rb
|
141
|
-
- spec/neovim/msgpack_stream_spec.rb
|
142
138
|
- spec/neovim/plugin_spec.rb
|
143
139
|
- spec/neovim/remote_object_spec.rb
|
144
140
|
- spec/neovim/ruby_provider/buffer_ext_spec.rb
|
145
141
|
- spec/neovim/ruby_provider/window_ext_spec.rb
|
142
|
+
- spec/neovim/session/api_spec.rb
|
143
|
+
- spec/neovim/session/event_loop_spec.rb
|
144
|
+
- spec/neovim/session/rpc_spec.rb
|
145
|
+
- spec/neovim/session/serializer_spec.rb
|
146
146
|
- spec/neovim/session_spec.rb
|
147
147
|
- spec/neovim/window_spec.rb
|
148
148
|
- spec/neovim_spec.rb
|
149
|
-
- spec/support.rb
|
150
149
|
homepage: https://github.com/alexgenco/neovim-ruby
|
151
150
|
licenses:
|
152
151
|
- MIT
|
@@ -175,22 +174,21 @@ test_files:
|
|
175
174
|
- spec/acceptance/neovim-ruby-host_spec.rb
|
176
175
|
- spec/acceptance/ruby_provider_spec.rb
|
177
176
|
- spec/helper.rb
|
178
|
-
- spec/neovim/api_spec.rb
|
179
|
-
- spec/neovim/async_session_spec.rb
|
180
177
|
- spec/neovim/buffer_spec.rb
|
181
178
|
- spec/neovim/client_spec.rb
|
182
179
|
- spec/neovim/current_spec.rb
|
183
|
-
- spec/neovim/event_loop_spec.rb
|
184
180
|
- spec/neovim/host/loader_spec.rb
|
185
181
|
- spec/neovim/host_spec.rb
|
186
182
|
- spec/neovim/line_range_spec.rb
|
187
|
-
- spec/neovim/msgpack_stream_spec.rb
|
188
183
|
- spec/neovim/plugin_spec.rb
|
189
184
|
- spec/neovim/remote_object_spec.rb
|
190
185
|
- spec/neovim/ruby_provider/buffer_ext_spec.rb
|
191
186
|
- spec/neovim/ruby_provider/window_ext_spec.rb
|
187
|
+
- spec/neovim/session/api_spec.rb
|
188
|
+
- spec/neovim/session/event_loop_spec.rb
|
189
|
+
- spec/neovim/session/rpc_spec.rb
|
190
|
+
- spec/neovim/session/serializer_spec.rb
|
192
191
|
- spec/neovim/session_spec.rb
|
193
192
|
- spec/neovim/window_spec.rb
|
194
193
|
- spec/neovim_spec.rb
|
195
|
-
- spec/support.rb
|
196
194
|
has_rdoc:
|