neovim 0.2.2 → 0.2.3
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 -1
- data/CHANGELOG.md +5 -0
- data/README.md +5 -7
- data/Rakefile +16 -0
- data/lib/neovim.rb +9 -23
- data/lib/neovim/api.rb +1 -0
- data/lib/neovim/async_session.rb +3 -1
- data/lib/neovim/buffer.rb +5 -1
- data/lib/neovim/client.rb +4 -5
- data/lib/neovim/current.rb +2 -0
- data/lib/neovim/event_loop.rb +15 -2
- data/lib/neovim/host.rb +85 -41
- data/lib/neovim/host/loader.rb +39 -0
- data/lib/neovim/line_range.rb +8 -0
- data/lib/neovim/logging.rb +1 -0
- data/lib/neovim/msgpack_stream.rb +4 -2
- data/lib/neovim/notification.rb +1 -0
- data/lib/neovim/plugin.rb +1 -0
- data/lib/neovim/request.rb +1 -0
- data/lib/neovim/ruby_provider.rb +2 -0
- data/lib/neovim/session.rb +3 -1
- data/lib/neovim/version.rb +1 -1
- data/spec/helper.rb +1 -0
- data/spec/neovim/buffer_spec.rb +20 -0
- data/spec/neovim/client_spec.rb +1 -0
- data/spec/neovim/current_spec.rb +1 -0
- data/spec/neovim/host/loader_spec.rb +47 -0
- data/spec/neovim/host_spec.rb +116 -28
- data/spec/neovim/line_range_spec.rb +43 -1
- data/spec/neovim/remote_object_spec.rb +6 -3
- data/spec/neovim/ruby_provider/buffer_ext_spec.rb +2 -0
- data/spec/neovim/ruby_provider/window_ext_spec.rb +2 -0
- data/spec/neovim/session_spec.rb +3 -2
- data/spec/neovim/window_spec.rb +14 -3
- data/spec/neovim_spec.rb +16 -13
- metadata +6 -5
- data/lib/neovim/manifest.rb +0 -89
- data/spec/neovim/manifest_spec.rb +0 -137
data/spec/neovim/session_spec.rb
CHANGED
@@ -99,7 +99,7 @@ module Neovim
|
|
99
99
|
let!(:nvim_pid) do
|
100
100
|
pid = Process.spawn(
|
101
101
|
{"NVIM_LISTEN_ADDRESS" => "0.0.0.0:#{nvim_port}"},
|
102
|
-
"nvim --
|
102
|
+
"nvim --headless -n -u NONE",
|
103
103
|
[:out, :err] => "/dev/null"
|
104
104
|
)
|
105
105
|
|
@@ -126,7 +126,7 @@ module Neovim
|
|
126
126
|
let!(:nvim_pid) do
|
127
127
|
pid = Process.spawn(
|
128
128
|
{"NVIM_LISTEN_ADDRESS" => socket_path},
|
129
|
-
"nvim --
|
129
|
+
"nvim --headless -n -u NONE",
|
130
130
|
[:out, :err] => "/dev/null"
|
131
131
|
)
|
132
132
|
|
@@ -151,6 +151,7 @@ module Neovim
|
|
151
151
|
context "child" do
|
152
152
|
let!(:session) { Session.child(["nvim", "-n", "-u", "NONE"]) }
|
153
153
|
include_context "session behavior"
|
154
|
+
after { session.shutdown }
|
154
155
|
end
|
155
156
|
end
|
156
157
|
end
|
data/spec/neovim/window_spec.rb
CHANGED
@@ -4,6 +4,7 @@ module Neovim
|
|
4
4
|
RSpec.describe Window do
|
5
5
|
let(:client) { Neovim.attach_child(["nvim", "-n", "-u", "NONE"]) }
|
6
6
|
let(:window) { client.current.window }
|
7
|
+
after { client.shutdown }
|
7
8
|
|
8
9
|
describe "if_ruby compatibility" do
|
9
10
|
describe "#buffer" do
|
@@ -51,12 +52,22 @@ module Neovim
|
|
51
52
|
end
|
52
53
|
|
53
54
|
describe "#cursor=" do
|
54
|
-
it "
|
55
|
+
it "uses 1-index for line numbers" do
|
55
56
|
window.buffer.lines = ["one", "two"]
|
57
|
+
client.command("normal G")
|
56
58
|
|
57
59
|
expect {
|
58
|
-
window.cursor = [
|
59
|
-
}.to change {
|
60
|
+
window.cursor = [1, 2]
|
61
|
+
}.to change { client.current.line }.from("two").to("one")
|
62
|
+
end
|
63
|
+
|
64
|
+
it "uses 0-index for column numbers" do
|
65
|
+
window.buffer.lines = ["one", "two"]
|
66
|
+
window.cursor = [1, 1]
|
67
|
+
|
68
|
+
expect {
|
69
|
+
client.command("normal ix")
|
70
|
+
}.to change { client.current.line }.to("oxne")
|
60
71
|
end
|
61
72
|
end
|
62
73
|
end
|
data/spec/neovim_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "helper"
|
2
2
|
|
3
3
|
RSpec.describe Neovim do
|
4
|
-
let(:nvim_argv) { %w(nvim --
|
4
|
+
let(:nvim_argv) { %w(nvim --headless -u NONE -i NONE -n) }
|
5
5
|
|
6
6
|
describe ".attach_tcp" do
|
7
7
|
it "attaches to a TCP socket" do
|
@@ -47,23 +47,26 @@ RSpec.describe Neovim do
|
|
47
47
|
|
48
48
|
describe ".attach_child" do
|
49
49
|
it "spawns and attaches to a child process" do
|
50
|
-
|
50
|
+
begin
|
51
|
+
client = Neovim.attach_child(nvim_argv)
|
52
|
+
expect(client.strwidth("hi")).to eq(2)
|
53
|
+
ensure
|
54
|
+
client.shutdown
|
55
|
+
end
|
51
56
|
end
|
52
57
|
end
|
53
58
|
|
54
|
-
describe ".
|
55
|
-
it "
|
56
|
-
|
57
|
-
|
58
|
-
mock_path = "/source/path"
|
59
|
-
|
60
|
-
allow(Neovim).to receive(:__configured_plugin_path).and_return(mock_path)
|
61
|
-
allow(Neovim).to receive(:__configured_plugin_manifest).and_return(mock_manifest)
|
59
|
+
describe ".start_host" do
|
60
|
+
it "loads and runs a Host" do
|
61
|
+
paths = ["/foo", "/bar"]
|
62
|
+
host = double(:host)
|
62
63
|
|
63
|
-
expect(Neovim::
|
64
|
-
|
64
|
+
expect(Neovim::Host).to receive(:load_from_files).
|
65
|
+
with(paths).
|
66
|
+
and_return(host)
|
65
67
|
|
66
|
-
|
68
|
+
expect(host).to receive(:run)
|
69
|
+
Neovim.start_host(paths)
|
67
70
|
end
|
68
71
|
end
|
69
72
|
end
|
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.2.
|
4
|
+
version: 0.2.3
|
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-07-
|
11
|
+
date: 2016-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -107,9 +107,9 @@ files:
|
|
107
107
|
- lib/neovim/current.rb
|
108
108
|
- lib/neovim/event_loop.rb
|
109
109
|
- lib/neovim/host.rb
|
110
|
+
- lib/neovim/host/loader.rb
|
110
111
|
- lib/neovim/line_range.rb
|
111
112
|
- lib/neovim/logging.rb
|
112
|
-
- lib/neovim/manifest.rb
|
113
113
|
- lib/neovim/msgpack_stream.rb
|
114
114
|
- lib/neovim/notification.rb
|
115
115
|
- lib/neovim/plugin.rb
|
@@ -135,9 +135,9 @@ files:
|
|
135
135
|
- spec/neovim/client_spec.rb
|
136
136
|
- spec/neovim/current_spec.rb
|
137
137
|
- spec/neovim/event_loop_spec.rb
|
138
|
+
- spec/neovim/host/loader_spec.rb
|
138
139
|
- spec/neovim/host_spec.rb
|
139
140
|
- spec/neovim/line_range_spec.rb
|
140
|
-
- spec/neovim/manifest_spec.rb
|
141
141
|
- spec/neovim/msgpack_stream_spec.rb
|
142
142
|
- spec/neovim/plugin_spec.rb
|
143
143
|
- spec/neovim/remote_object_spec.rb
|
@@ -181,9 +181,9 @@ test_files:
|
|
181
181
|
- spec/neovim/client_spec.rb
|
182
182
|
- spec/neovim/current_spec.rb
|
183
183
|
- spec/neovim/event_loop_spec.rb
|
184
|
+
- spec/neovim/host/loader_spec.rb
|
184
185
|
- spec/neovim/host_spec.rb
|
185
186
|
- spec/neovim/line_range_spec.rb
|
186
|
-
- spec/neovim/manifest_spec.rb
|
187
187
|
- spec/neovim/msgpack_stream_spec.rb
|
188
188
|
- spec/neovim/plugin_spec.rb
|
189
189
|
- spec/neovim/remote_object_spec.rb
|
@@ -193,3 +193,4 @@ test_files:
|
|
193
193
|
- spec/neovim/window_spec.rb
|
194
194
|
- spec/neovim_spec.rb
|
195
195
|
- spec/support.rb
|
196
|
+
has_rdoc:
|
data/lib/neovim/manifest.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
require "neovim/logging"
|
2
|
-
|
3
|
-
module Neovim
|
4
|
-
class Manifest
|
5
|
-
include Logging
|
6
|
-
|
7
|
-
attr_reader :handlers, :specs
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@handlers = {"poll" => poll_handler, "specs" => specs_handler}
|
11
|
-
@specs = {}
|
12
|
-
end
|
13
|
-
|
14
|
-
# Register a +Plugin+ to receive +Host+ messages.
|
15
|
-
#
|
16
|
-
# @param plugin [Plugin]
|
17
|
-
def register(plugin)
|
18
|
-
plugin.handlers.each do |handler|
|
19
|
-
wrapped_handler = handler.sync? ? wrap_sync(handler) : wrap_async(handler)
|
20
|
-
@handlers[handler.qualified_name] = wrapped_handler
|
21
|
-
end
|
22
|
-
|
23
|
-
@specs[plugin.source] = plugin.specs
|
24
|
-
end
|
25
|
-
|
26
|
-
# Handle messages received from the host. Sends a +Neovim::Client+ along
|
27
|
-
# with the message to be used in plugin callbacks.
|
28
|
-
#
|
29
|
-
# @param message [Neovim::Request, Neovim::Notification]
|
30
|
-
# @param client [Neovim::Client]
|
31
|
-
def handle(message, client)
|
32
|
-
default_handler = message.sync? ? default_sync_handler : default_async_handler
|
33
|
-
@handlers.fetch(message.method_name, default_handler).call(client, message)
|
34
|
-
rescue => e
|
35
|
-
fatal("got unexpected error #{e}")
|
36
|
-
debug(e.backtrace.join("\n"))
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def poll_handler
|
42
|
-
@poll_handler ||= Proc.new do |_, req|
|
43
|
-
debug("received 'poll' request #{req.inspect}")
|
44
|
-
req.respond("ok")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def specs_handler
|
49
|
-
@specs_handler ||= Proc.new do |_, req|
|
50
|
-
debug("received 'specs' request #{req.inspect}")
|
51
|
-
source = req.arguments.fetch(0)
|
52
|
-
|
53
|
-
if @specs.key?(source)
|
54
|
-
req.respond(@specs.fetch(source))
|
55
|
-
else
|
56
|
-
req.error("Unknown plugin #{source}")
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def default_sync_handler
|
62
|
-
@default_sync_handler ||= Proc.new { |_, req| req.error("Unknown request #{req.method_name}") }
|
63
|
-
end
|
64
|
-
|
65
|
-
def default_async_handler
|
66
|
-
@default_async_handler ||= Proc.new {}
|
67
|
-
end
|
68
|
-
|
69
|
-
def wrap_sync(handler)
|
70
|
-
Proc.new do |client, request|
|
71
|
-
begin
|
72
|
-
debug("received #{request.inspect}")
|
73
|
-
args = request.arguments.flatten(1)
|
74
|
-
request.respond(handler.call(client, *args))
|
75
|
-
rescue => e
|
76
|
-
request.error(e.message)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def wrap_async(handler)
|
82
|
-
Proc.new do |client, notification|
|
83
|
-
debug("received #{notification.inspect}")
|
84
|
-
args = notification.arguments.flatten(1)
|
85
|
-
handler.call(client, *args)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
@@ -1,137 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
module Neovim
|
4
|
-
RSpec.describe Manifest do
|
5
|
-
it "has a default poll handler" do
|
6
|
-
manifest = Manifest.new
|
7
|
-
expect(manifest.handlers["poll"]).to respond_to(:call)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "has default specs" do
|
11
|
-
manifest = Manifest.new
|
12
|
-
expect(manifest.specs).to eq({})
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "#register" do
|
16
|
-
it "adds specs" do
|
17
|
-
manifest = Manifest.new
|
18
|
-
|
19
|
-
plugin = Plugin.from_config_block("source") do |plug|
|
20
|
-
plug.command(:Foo)
|
21
|
-
end
|
22
|
-
|
23
|
-
expect {
|
24
|
-
manifest.register(plugin)
|
25
|
-
}.to change { manifest.specs }.from({}).to("source" => plugin.specs)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "adds plugin handlers" do
|
29
|
-
manifest = Manifest.new
|
30
|
-
|
31
|
-
plugin = Plugin.from_config_block("source") do |plug|
|
32
|
-
plug.command(:Foo)
|
33
|
-
end
|
34
|
-
|
35
|
-
expect {
|
36
|
-
manifest.register(plugin)
|
37
|
-
}.to change {
|
38
|
-
manifest.handlers["source:command:Foo"]
|
39
|
-
}.from(nil).to(kind_of(Proc))
|
40
|
-
end
|
41
|
-
|
42
|
-
it "doesn't add top-level RPCs to specs" do
|
43
|
-
manifest = Manifest.new
|
44
|
-
|
45
|
-
plugin = Plugin.from_config_block("source") do |plug|
|
46
|
-
plug.rpc(:Foo)
|
47
|
-
end
|
48
|
-
|
49
|
-
expect {
|
50
|
-
manifest.register(plugin)
|
51
|
-
}.to change { manifest.specs }.from({}).to("source" => [])
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "#handle" do
|
56
|
-
it "calls the poll handler" do
|
57
|
-
manifest = Manifest.new
|
58
|
-
message = double(:message, :method_name => "poll", :sync? => true)
|
59
|
-
client = double(:client)
|
60
|
-
|
61
|
-
expect(message).to receive(:respond).with("ok")
|
62
|
-
manifest.handle(message, client)
|
63
|
-
end
|
64
|
-
|
65
|
-
it "calls the specs handler" do
|
66
|
-
manifest = Manifest.new
|
67
|
-
plugin = Plugin.from_config_block("source") do |plug|
|
68
|
-
plug.command(:Foo)
|
69
|
-
end
|
70
|
-
manifest.register(plugin)
|
71
|
-
|
72
|
-
message = double(:message, :method_name => "specs", :sync? => true, :arguments => ["source"])
|
73
|
-
|
74
|
-
expect(message).to receive(:respond).with(plugin.specs)
|
75
|
-
manifest.handle(message, double(:client))
|
76
|
-
end
|
77
|
-
|
78
|
-
it "calls a plugin sync handler" do
|
79
|
-
manifest = Manifest.new
|
80
|
-
plugin = Plugin.from_config_block("source") do |plug|
|
81
|
-
plug.command(:Foo, :sync => true) { |client, arg| [client, arg] }
|
82
|
-
end
|
83
|
-
manifest.register(plugin)
|
84
|
-
|
85
|
-
message = double(:message, :method_name => "source:command:Foo", :sync? => true, :arguments => [:arg])
|
86
|
-
client = double(:client)
|
87
|
-
|
88
|
-
expect(message).to receive(:respond).with([client, :arg])
|
89
|
-
manifest.handle(message, client)
|
90
|
-
end
|
91
|
-
|
92
|
-
it "rescues plugin sync handler exceptions" do
|
93
|
-
manifest = Manifest.new
|
94
|
-
plugin = Plugin.from_config_block("source") do |plug|
|
95
|
-
plug.command(:Foo, :sync => true) { raise "BOOM" }
|
96
|
-
end
|
97
|
-
manifest.register(plugin)
|
98
|
-
|
99
|
-
message = double(:message, :method_name => "source:command:Foo", :sync? => true, :arguments => [])
|
100
|
-
client = double(:client)
|
101
|
-
|
102
|
-
expect(message).to receive(:error).with("BOOM")
|
103
|
-
manifest.handle(message, client)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "calls a plugin async handler" do
|
107
|
-
manifest = Manifest.new
|
108
|
-
async_proc = Proc.new {}
|
109
|
-
plugin = Plugin.from_config_block("source") do |plug|
|
110
|
-
plug.command(:Foo, &async_proc)
|
111
|
-
end
|
112
|
-
manifest.register(plugin)
|
113
|
-
|
114
|
-
message = double(:message, :method_name => "source:command:Foo", :sync? => false, :arguments => [:arg])
|
115
|
-
client = double(:client)
|
116
|
-
|
117
|
-
expect(async_proc).to receive(:call).with(client, :arg)
|
118
|
-
manifest.handle(message, client)
|
119
|
-
end
|
120
|
-
|
121
|
-
it "calls a default sync handler" do
|
122
|
-
manifest = Manifest.new
|
123
|
-
message = double(:message, :method_name => "foobar", :sync? => true)
|
124
|
-
|
125
|
-
expect(message).to receive(:error).with("Unknown request foobar")
|
126
|
-
manifest.handle(message, double(:client))
|
127
|
-
end
|
128
|
-
|
129
|
-
it "calls a default async handler" do
|
130
|
-
manifest = Manifest.new
|
131
|
-
message = double(:message, :method_name => "foobar", :sync? => false)
|
132
|
-
|
133
|
-
manifest.handle(message, double(:client))
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|