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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/CHANGELOG.md +10 -0
  4. data/lib/neovim/current.rb +19 -2
  5. data/lib/neovim/host.rb +3 -11
  6. data/lib/neovim/host/loader.rb +0 -2
  7. data/lib/neovim/line_range.rb +14 -2
  8. data/lib/neovim/plugin.rb +1 -4
  9. data/lib/neovim/plugin/dsl.rb +6 -14
  10. data/lib/neovim/plugin/handler.rb +2 -9
  11. data/lib/neovim/ruby_provider.rb +9 -15
  12. data/lib/neovim/session.rb +23 -70
  13. data/lib/neovim/session/api.rb +61 -0
  14. data/lib/neovim/session/event_loop.rb +108 -0
  15. data/lib/neovim/session/notification.rb +19 -0
  16. data/lib/neovim/session/request.rb +31 -0
  17. data/lib/neovim/session/rpc.rb +95 -0
  18. data/lib/neovim/session/serializer.rb +62 -0
  19. data/lib/neovim/version.rb +1 -1
  20. data/neovim.gemspec +1 -1
  21. data/spec/acceptance/neovim-ruby-host_spec.rb +0 -5
  22. data/spec/acceptance/ruby_provider_spec.rb +35 -3
  23. data/spec/helper.rb +33 -2
  24. data/spec/neovim/host_spec.rb +1 -1
  25. data/spec/neovim/plugin_spec.rb +2 -2
  26. data/spec/neovim/session/api_spec.rb +46 -0
  27. data/spec/neovim/session/event_loop_spec.rb +99 -0
  28. data/spec/neovim/session/rpc_spec.rb +108 -0
  29. data/spec/neovim/session/serializer_spec.rb +48 -0
  30. data/spec/neovim/session_spec.rb +1 -1
  31. metadata +16 -18
  32. data/lib/neovim/api.rb +0 -80
  33. data/lib/neovim/async_session.rb +0 -119
  34. data/lib/neovim/event_loop.rb +0 -128
  35. data/lib/neovim/msgpack_stream.rb +0 -80
  36. data/lib/neovim/notification.rb +0 -17
  37. data/lib/neovim/request.rb +0 -29
  38. data/spec/neovim/api_spec.rb +0 -44
  39. data/spec/neovim/async_session_spec.rb +0 -106
  40. data/spec/neovim/event_loop_spec.rb +0 -97
  41. data/spec/neovim/msgpack_stream_spec.rb +0 -46
  42. data/spec/support.rb +0 -33
@@ -1,44 +0,0 @@
1
- require "helper"
2
-
3
- module Neovim
4
- RSpec.describe API do
5
- describe ".null" do
6
- it "returns an empty API object" do
7
- api = API.null
8
-
9
- expect(api.types).to be_empty
10
- expect(api.functions).to be_empty
11
- end
12
- end
13
-
14
- describe "#function" do
15
- it "returns a corresponding Function object" do
16
- api = API.new(
17
- [nil, {"functions" => [
18
- {"name" => "vim_strwidth", "async" => false}
19
- ]}]
20
- )
21
-
22
- function = api.function("vim_strwidth")
23
- expect(function).to be_a(API::Function)
24
- expect(function.name).to eq("vim_strwidth")
25
- expect(function.async).to be(false)
26
- end
27
- end
28
-
29
- describe "#functions_with_prefix" do
30
- it "returns relevant functions" do
31
- api = API.new(
32
- [nil, {"functions" => [
33
- {"name" => "vim_strwidth"},
34
- {"name" => "buffer_get_lines"}
35
- ]}]
36
- )
37
-
38
- functions = api.functions_with_prefix("vim_")
39
- expect(functions.size).to be(1)
40
- expect(functions.first.name).to eq("vim_strwidth")
41
- end
42
- end
43
- end
44
- end
@@ -1,106 +0,0 @@
1
- require "helper"
2
-
3
- module Neovim
4
- RSpec.describe AsyncSession do
5
- shared_context "async session behavior" do
6
- it "receives requests" do
7
- stream = MsgpackStream.new(event_loop)
8
- async_session = AsyncSession.new(stream)
9
-
10
- server_thread = Thread.new do
11
- client = server.accept
12
- client.write(
13
- MessagePack.pack(
14
- [0, 123, "func", [1, 2, 3]]
15
- )
16
- )
17
- end
18
-
19
- request = nil
20
- async_session.run do |msg|
21
- request = msg
22
- async_session.shutdown
23
- end
24
-
25
- server_thread.join
26
-
27
- expect(request).to be_a(Request)
28
- expect(request.method_name).to eq("func")
29
- expect(request.arguments).to eq([1, 2, 3])
30
- end
31
-
32
- it "receives notifications" do
33
- stream = MsgpackStream.new(event_loop)
34
- async_session = AsyncSession.new(stream)
35
-
36
- server_thread = Thread.new do
37
- client = server.accept
38
- client.write(
39
- MessagePack.pack(
40
- [2, "func", [1, 2, 3]]
41
- )
42
- )
43
- end
44
-
45
- notification = nil
46
- async_session.run do |message|
47
- notification = message
48
- async_session.shutdown
49
- end
50
-
51
- server_thread.join
52
-
53
- expect(notification).to be_a(Notification)
54
- expect(notification.method_name).to eq("func")
55
- expect(notification.arguments).to eq([1, 2, 3])
56
- end
57
-
58
- it "receives responses to requests" do
59
- stream = MsgpackStream.new(event_loop)
60
- async_session = AsyncSession.new(stream)
61
- request = nil
62
-
63
- server_thread = Thread.new do
64
- client = server.accept
65
- request = client.readpartial(1024)
66
-
67
- client.write(
68
- MessagePack.pack(
69
- [1, 0, [0, "error"], "result"]
70
- )
71
- )
72
- end
73
-
74
- error, result = nil
75
- async_session.request("func", 1, 2, 3) do |err, res|
76
- error, result = err, res
77
- async_session.shutdown
78
- end.run
79
-
80
- expect(error).to eq("error")
81
- expect(result).to eq("result")
82
-
83
- server_thread.join
84
- async_session.shutdown
85
-
86
- expect(request).to eq(
87
- MessagePack.pack([0, 0, "func", [1, 2, 3]])
88
- )
89
- end
90
- end
91
-
92
- context "tcp" do
93
- let!(:server) { TCPServer.new("0.0.0.0", 0) }
94
- let!(:event_loop) { EventLoop.tcp("0.0.0.0", server.addr[1]) }
95
-
96
- include_context "async session behavior"
97
- end
98
-
99
- context "unix" do
100
- let!(:server) { UNIXServer.new(Support.socket_path) }
101
- let!(:event_loop) { EventLoop.unix(Support.socket_path) }
102
-
103
- include_context "async session behavior"
104
- end
105
- end
106
- end
@@ -1,97 +0,0 @@
1
- require "helper"
2
- require "socket"
3
-
4
- module Neovim
5
- RSpec.describe EventLoop do
6
- shared_context "socket behavior" do
7
- it "sends and receives data" do
8
- request = nil
9
-
10
- server_thread = Thread.new do
11
- client = server.accept
12
- request = client.readpartial(1024)
13
-
14
- client.write("res")
15
- client.close
16
- server.close
17
- end
18
-
19
- response = nil
20
- event_loop.write("req").run do |msg|
21
- response = msg
22
- event_loop.stop
23
- end
24
-
25
- server_thread.join
26
- event_loop.shutdown
27
- expect(request).to eq("req")
28
- expect(response).to eq("res")
29
- end
30
- end
31
-
32
- context "tcp" do
33
- let!(:server) { TCPServer.new("0.0.0.0", 0) }
34
- let!(:event_loop) { EventLoop.tcp("0.0.0.0", server.addr[1]) }
35
-
36
- include_context "socket behavior"
37
- end
38
-
39
- context "unix" do
40
- let!(:server) { UNIXServer.new(Support.socket_path) }
41
- let!(:event_loop) { EventLoop.unix(Support.socket_path) }
42
-
43
- include_context "socket behavior"
44
- end
45
-
46
- context "stdio" do
47
- it "sends and receives data" do
48
- old_stdout = STDOUT.dup
49
- old_stdin = STDIN.dup
50
-
51
- begin
52
- srv_stdout, cl_stdout = IO.pipe
53
- cl_stdin, srv_stdin = IO.pipe
54
-
55
- STDOUT.reopen(cl_stdout)
56
- STDIN.reopen(cl_stdin)
57
-
58
- event_loop = EventLoop.stdio
59
- request = nil
60
-
61
- server_thread = Thread.new do
62
- request = srv_stdout.readpartial(1024)
63
- srv_stdin.write("res")
64
- end
65
-
66
- response = nil
67
- event_loop.write("req").run do |msg|
68
- response = msg
69
- event_loop.stop
70
- end
71
-
72
- server_thread.join
73
- expect(request).to eq("req")
74
- expect(response).to eq("res")
75
- ensure
76
- STDOUT.reopen(old_stdout)
77
- STDIN.reopen(old_stdin)
78
- end
79
- end
80
- end
81
-
82
- context "child" do
83
- it "sends and receives data" do
84
- event_loop = EventLoop.child(["nvim", "-n", "-u", "NONE"])
85
- input = MessagePack.pack([0, 0, :vim_strwidth, ["hi"]])
86
-
87
- response = nil
88
- event_loop.write(input).run do |msg|
89
- response = msg
90
- event_loop.shutdown
91
- end
92
-
93
- expect(response).to eq(MessagePack.pack([1, 0, nil, 2]))
94
- end
95
- end
96
- end
97
- end
@@ -1,46 +0,0 @@
1
- require "socket"
2
- require "helper"
3
-
4
- module Neovim
5
- RSpec.describe MsgpackStream do
6
- shared_context "msgpack stream behavior" do
7
- it "sends and receives data" do
8
- msgpack_stream = MsgpackStream.new(event_loop)
9
- request = nil
10
-
11
- server_thread = Thread.new do
12
- client = server.accept
13
- request = client.readpartial(1024)
14
-
15
- client.write(MessagePack.pack(["res"]))
16
- client.close
17
- server.close
18
- end
19
-
20
- response = nil
21
- msgpack_stream.write(["req"]).run do |message|
22
- response = message
23
- msgpack_stream.shutdown
24
- end
25
-
26
- server_thread.join
27
- expect(request).to eq(MessagePack.pack(["req"]))
28
- expect(response).to eq(["res"])
29
- end
30
- end
31
-
32
- context "tcp" do
33
- let!(:server) { TCPServer.new("0.0.0.0", 0) }
34
- let!(:event_loop) { EventLoop.tcp("0.0.0.0", server.addr[1]) }
35
-
36
- include_context "msgpack stream behavior"
37
- end
38
-
39
- context "unix" do
40
- let!(:server) { UNIXServer.new(Support.socket_path) }
41
- let!(:event_loop) { EventLoop.unix(Support.socket_path) }
42
-
43
- include_context "msgpack stream behavior"
44
- end
45
- end
46
- end
@@ -1,33 +0,0 @@
1
- require "fileutils"
2
-
3
- module Support
4
- def self.workspace
5
- File.expand_path("../workspace", __FILE__)
6
- end
7
-
8
- def self.socket_path
9
- file_path("nvim.sock")
10
- end
11
-
12
- def self.port
13
- server = TCPServer.new("0.0.0.0", 0)
14
-
15
- begin
16
- server.addr[1]
17
- ensure
18
- server.close
19
- end
20
- end
21
-
22
- def self.file_path(name)
23
- File.join(workspace, name)
24
- end
25
-
26
- def self.setup_workspace
27
- FileUtils.mkdir_p(workspace)
28
- end
29
-
30
- def self.teardown_workspace
31
- FileUtils.rm_rf(workspace)
32
- end
33
- end