neovim 0.0.4 → 0.0.5
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/.gitignore +1 -0
- data/.travis.yml +1 -1
- data/README.md +16 -19
- data/lib/neovim.rb +6 -0
- data/lib/neovim/async_session.rb +6 -0
- data/lib/neovim/buffer.rb +9 -0
- data/lib/neovim/current.rb +0 -9
- data/lib/neovim/event_loop.rb +11 -1
- data/lib/neovim/host.rb +9 -2
- data/lib/neovim/logging.rb +50 -0
- data/lib/neovim/manifest.rb +16 -3
- data/lib/neovim/msgpack_stream.rb +8 -0
- data/lib/neovim/version.rb +1 -1
- data/spec/acceptance/neovim-ruby-host_spec.rb +37 -41
- data/spec/helper.rb +14 -2
- data/spec/neovim/async_session_spec.rb +8 -10
- data/spec/neovim/buffer_spec.rb +15 -1
- data/spec/neovim/current_spec.rb +0 -14
- data/spec/neovim/event_loop_spec.rb +6 -8
- data/spec/neovim/host_spec.rb +6 -13
- data/spec/neovim/msgpack_stream_spec.rb +10 -9
- data/spec/neovim/session_spec.rb +22 -21
- data/spec/neovim_spec.rb +11 -10
- data/spec/support.rb +29 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92074f47bd93b7fbca51aa3b74e813adb8b1004c
|
4
|
+
data.tar.gz: 2c19393d6a5c38342bc30350e5c5da352fff101c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c22b67f54f42edcdbc7a062ff972725508c69810627dd51e3c5ece458dd9c1187cc6e87149044dd4786302181297d5ebc3acb8ed4b29a33c069e2c61c0cb52b
|
7
|
+
data.tar.gz: 3c9dc7fc608a08a0db6ed8a9174b93b5487163745661174c883fe2726be02259e448b1e3e8c79bfda25b082d012e27bdc5fc22fed78e2e826f7395faf669a0f8
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -42,34 +42,31 @@ The client's interface is generated at runtime from the `vim_get_api_info` RPC c
|
|
42
42
|
The `neovim-ruby-host` executable can be used to spawn Ruby plugins via the `rpcstart` command. A plugin can be defined like this:
|
43
43
|
|
44
44
|
```ruby
|
45
|
-
# my_plugin.rb
|
45
|
+
# $VIMRUNTIME/rplugin/ruby/my_plugin.rb
|
46
46
|
|
47
47
|
Neovim.plugin do |plug|
|
48
|
-
# Define a command called "
|
49
|
-
#
|
50
|
-
#
|
51
|
-
plug.command(:Add, :nargs => 2, :sync => true) do |nvim, x, y|
|
52
|
-
x + y
|
53
|
-
end
|
54
|
-
|
55
|
-
# Define a command called "SetLine" which sets the current line
|
56
|
-
# This command is asynchronous, so nvim won't wait for a response.
|
48
|
+
# Define a command called "SetLine" which sets the current line to the sum of
|
49
|
+
# two values. This command is executed asynchronously, so the return value is
|
50
|
+
# ignored.
|
57
51
|
plug.command(:SetLine, :nargs => 1) do |nvim, str|
|
58
52
|
nvim.current.line = str
|
59
53
|
end
|
60
|
-
end
|
61
|
-
```
|
62
|
-
|
63
|
-
You can start this plugin via the `rpcstart` nvim function. The resulting channel ID can be used to send requests and notifications to the plugin.
|
64
54
|
|
65
|
-
|
66
|
-
|
55
|
+
# Define a function called "Sum" which sets the current line. This function
|
56
|
+
# is executed synchronously, so the result of the block will be returned to
|
57
|
+
# nvim.
|
58
|
+
plug.function(:Sum, :nargs => 2, :sync => true) do |nvim, x, y|
|
59
|
+
x + y
|
60
|
+
end
|
67
61
|
|
68
|
-
|
69
|
-
|
62
|
+
# Define an autocmd for the BufEnter event on Ruby files.
|
63
|
+
plug.autocmd(:BufEnter, :pattern => "*.rb") do |nvim|
|
64
|
+
nvim.command("echom 'Ruby file, eh?'")
|
65
|
+
end
|
66
|
+
end
|
70
67
|
```
|
71
68
|
|
72
|
-
|
69
|
+
After a call to `:UpdateRemotePlugins`, plugins will be auto-loaded from the `$VIMRUNTIME/rplugin/ruby` directory.
|
73
70
|
|
74
71
|
## Contributing
|
75
72
|
|
data/lib/neovim.rb
CHANGED
data/lib/neovim/async_session.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
require "neovim/logging"
|
1
2
|
require "neovim/request"
|
2
3
|
require "neovim/notification"
|
3
4
|
|
4
5
|
module Neovim
|
5
6
|
class AsyncSession
|
7
|
+
include Logging
|
8
|
+
|
6
9
|
def initialize(msgpack_stream)
|
7
10
|
@msgpack_stream = msgpack_stream
|
8
11
|
@request_id = 0
|
@@ -49,6 +52,9 @@ module Neovim
|
|
49
52
|
end
|
50
53
|
|
51
54
|
@msgpack_stream.run(msg_cb, setup_cb)
|
55
|
+
rescue => e
|
56
|
+
fatal("got unexpected error #{e}")
|
57
|
+
debug(e.backtrace.join("\n"))
|
52
58
|
end
|
53
59
|
end
|
54
60
|
end
|
data/lib/neovim/buffer.rb
CHANGED
@@ -10,5 +10,14 @@ module Neovim
|
|
10
10
|
def lines=(arr)
|
11
11
|
lines[0..-1] = arr
|
12
12
|
end
|
13
|
+
|
14
|
+
def range
|
15
|
+
@range ||= LineRange.new(self, 0, -1)
|
16
|
+
end
|
17
|
+
|
18
|
+
def range=(_range)
|
19
|
+
_end = _range.exclude_end? ? _range.end - 1 : _range.end
|
20
|
+
@range = LineRange.new(self, _range.begin, _end)
|
21
|
+
end
|
13
22
|
end
|
14
23
|
end
|
data/lib/neovim/current.rb
CHANGED
@@ -42,14 +42,5 @@ module Neovim
|
|
42
42
|
tabpage = Tabpage.new(tabpage_index, @session)
|
43
43
|
@session.request(:vim_set_current_tabpage, tabpage)
|
44
44
|
end
|
45
|
-
|
46
|
-
def range
|
47
|
-
@range ||= LineRange.new(buffer, 0, -1)
|
48
|
-
end
|
49
|
-
|
50
|
-
def range=(_range)
|
51
|
-
_end = _range.exclude_end? ? _range.end - 1 : _range.end
|
52
|
-
@range = LineRange.new(buffer, _range.begin, _end)
|
53
|
-
end
|
54
45
|
end
|
55
46
|
end
|
data/lib/neovim/event_loop.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
require "neovim/logging"
|
1
2
|
require "socket"
|
2
3
|
|
3
4
|
module Neovim
|
4
5
|
class EventLoop
|
6
|
+
include Logging
|
7
|
+
|
5
8
|
def self.tcp(host, port)
|
6
9
|
socket = TCPSocket.new(host, port)
|
7
10
|
new(socket, socket)
|
@@ -30,6 +33,7 @@ module Neovim
|
|
30
33
|
def send(data)
|
31
34
|
start = 0
|
32
35
|
size = data.size
|
36
|
+
debug("sending #{data.inspect}")
|
33
37
|
|
34
38
|
begin
|
35
39
|
while start < size
|
@@ -48,9 +52,15 @@ module Neovim
|
|
48
52
|
|
49
53
|
loop do
|
50
54
|
break unless @running
|
51
|
-
|
55
|
+
message = @rd.readpartial(1024 * 16)
|
56
|
+
debug("received #{message.inspect}")
|
57
|
+
message_callback.call(message)
|
52
58
|
end
|
53
59
|
rescue EOFError
|
60
|
+
warn("got EOFError")
|
61
|
+
rescue => e
|
62
|
+
fatal("got unexpected error #{e}")
|
63
|
+
debug(e.backtrace.join("\n"))
|
54
64
|
end
|
55
65
|
end
|
56
66
|
end
|
data/lib/neovim/host.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
require "neovim/logging"
|
1
2
|
require "neovim/manifest"
|
2
3
|
|
3
4
|
module Neovim
|
4
5
|
class Host
|
6
|
+
include Logging
|
7
|
+
|
8
|
+
attr_reader :manifest
|
9
|
+
|
5
10
|
def self.load_from_files(rplugin_paths, target_manifest=Manifest.new)
|
6
11
|
old_manifest = Neovim.__configured_plugin_manifest
|
7
12
|
old_path = Neovim.__configured_plugin_path
|
@@ -21,8 +26,6 @@ module Neovim
|
|
21
26
|
end
|
22
27
|
end
|
23
28
|
|
24
|
-
attr_reader :manifest
|
25
|
-
|
26
29
|
def initialize(manifest)
|
27
30
|
@manifest = manifest
|
28
31
|
@event_loop = EventLoop.stdio
|
@@ -32,10 +35,14 @@ module Neovim
|
|
32
35
|
|
33
36
|
def run
|
34
37
|
callback = Proc.new do |msg|
|
38
|
+
debug("received #{msg.inspect}")
|
35
39
|
@manifest.handle(msg, client)
|
36
40
|
end
|
37
41
|
|
38
42
|
@async_session.run(callback, callback)
|
43
|
+
rescue => e
|
44
|
+
fatal("got unexpected error #{e}")
|
45
|
+
debug(e.backtrace.join("\n"))
|
39
46
|
end
|
40
47
|
|
41
48
|
private
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "logger"
|
2
|
+
require "stringio"
|
3
|
+
|
4
|
+
module Neovim
|
5
|
+
module Logging
|
6
|
+
class << self
|
7
|
+
attr_writer :logger
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.logger
|
11
|
+
return @logger if instance_variable_defined?(:@logger)
|
12
|
+
|
13
|
+
if ENV["NVIM_RUBY_LOG_FILE"]
|
14
|
+
@logger = Logger.new(ENV["NVIM_RUBY_LOG_FILE"])
|
15
|
+
else
|
16
|
+
@logger = Logger.new(STDERR)
|
17
|
+
end
|
18
|
+
|
19
|
+
if ENV["NVIM_RUBY_LOG_LEVEL"]
|
20
|
+
@logger.level = Integer(ENV["NVIM_RUBY_LOG_LEVEL"])
|
21
|
+
else
|
22
|
+
@logger.level = Logger::WARN
|
23
|
+
end
|
24
|
+
|
25
|
+
@logger
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def fatal(msg)
|
31
|
+
logger.fatal(self.class) { msg }
|
32
|
+
end
|
33
|
+
|
34
|
+
def warn(msg)
|
35
|
+
logger.warn(self.class) { msg }
|
36
|
+
end
|
37
|
+
|
38
|
+
def info(msg)
|
39
|
+
logger.info(self.class) { msg }
|
40
|
+
end
|
41
|
+
|
42
|
+
def debug(msg)
|
43
|
+
logger.debug(self.class) { msg }
|
44
|
+
end
|
45
|
+
|
46
|
+
def logger
|
47
|
+
Logging.logger
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/neovim/manifest.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
require "neovim/logging"
|
2
|
+
|
1
3
|
module Neovim
|
2
4
|
class Manifest
|
5
|
+
include Logging
|
6
|
+
|
3
7
|
attr_reader :handlers, :specs
|
4
8
|
|
5
9
|
def initialize
|
@@ -19,16 +23,23 @@ module Neovim
|
|
19
23
|
def handle(msg, client)
|
20
24
|
default_handler = msg.sync? ? default_sync_handler : default_async_handler
|
21
25
|
@handlers.fetch(msg.method_name, default_handler).call(client, msg)
|
26
|
+
rescue => e
|
27
|
+
fatal("got unexpected error #{e}")
|
28
|
+
debug(e.backtrace.join("\n"))
|
22
29
|
end
|
23
30
|
|
24
31
|
private
|
25
32
|
|
26
33
|
def poll_handler
|
27
|
-
@poll_handler ||= Proc.new
|
34
|
+
@poll_handler ||= Proc.new do |_, req|
|
35
|
+
debug("received 'poll' request #{req.inspect}")
|
36
|
+
req.respond("ok")
|
37
|
+
end
|
28
38
|
end
|
29
39
|
|
30
40
|
def specs_handler
|
31
41
|
@specs_handler ||= Proc.new do |_, req|
|
42
|
+
debug("received 'specs' request #{req.inspect}")
|
32
43
|
source = req.arguments.fetch(0)
|
33
44
|
|
34
45
|
if @specs.key?(source)
|
@@ -49,13 +60,15 @@ module Neovim
|
|
49
60
|
|
50
61
|
def wrap_sync(handler)
|
51
62
|
Proc.new do |client, request|
|
52
|
-
|
63
|
+
debug("received #{request.inspect}")
|
64
|
+
request.respond(handler.call(client, *request.arguments[0]))
|
53
65
|
end
|
54
66
|
end
|
55
67
|
|
56
68
|
def wrap_async(handler)
|
57
69
|
Proc.new do |client, notification|
|
58
|
-
|
70
|
+
debug("received #{notification.inspect}")
|
71
|
+
handler.call(client, *notification.arguments[0])
|
59
72
|
end
|
60
73
|
end
|
61
74
|
end
|
@@ -1,7 +1,10 @@
|
|
1
|
+
require "neovim/logging"
|
1
2
|
require "msgpack"
|
2
3
|
|
3
4
|
module Neovim
|
4
5
|
class MsgpackStream
|
6
|
+
include Logging
|
7
|
+
|
5
8
|
def initialize(event_loop)
|
6
9
|
@event_loop = event_loop
|
7
10
|
@unpacker = MessagePack::Unpacker.new
|
@@ -19,6 +22,7 @@ module Neovim
|
|
19
22
|
end
|
20
23
|
|
21
24
|
def send(msg)
|
25
|
+
debug("sending #{msg.inspect}")
|
22
26
|
@event_loop.send(MessagePack.pack(msg))
|
23
27
|
self
|
24
28
|
end
|
@@ -26,11 +30,15 @@ module Neovim
|
|
26
30
|
def run(message_cb, setup_cb=nil)
|
27
31
|
data_cb = Proc.new do |data|
|
28
32
|
@unpacker.feed_each(data) do |msg|
|
33
|
+
debug("received #{msg.inspect}")
|
29
34
|
message_cb.call(msg)
|
30
35
|
end
|
31
36
|
end
|
32
37
|
|
33
38
|
@event_loop.run(data_cb, setup_cb)
|
39
|
+
rescue => e
|
40
|
+
fatal("got unexpected error #{e}")
|
41
|
+
debug(e.backtrace.join("\n"))
|
34
42
|
end
|
35
43
|
end
|
36
44
|
end
|
data/lib/neovim/version.rb
CHANGED
@@ -3,47 +3,43 @@ require "tmpdir"
|
|
3
3
|
|
4
4
|
RSpec.describe "neovim-ruby-host" do
|
5
5
|
it "loads and runs plugins from Ruby source files" do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
x + y
|
13
|
-
end
|
14
|
-
end
|
15
|
-
RUBY
|
16
|
-
|
17
|
-
plugin2_path = File.expand_path("./plugin2.rb")
|
18
|
-
File.write(plugin2_path, <<-RUBY)
|
19
|
-
Neovim.plugin do |plug|
|
20
|
-
plug.command(:AsyncSetLine, :args => 1) do |nvim, str|
|
21
|
-
nvim.current.line = str
|
22
|
-
end
|
23
|
-
end
|
24
|
-
RUBY
|
25
|
-
|
26
|
-
nvim = Neovim.attach_child(["--headless", "-u", "NONE", "-N", "-n"])
|
27
|
-
|
28
|
-
host_exe = File.expand_path("../../../bin/neovim-ruby-host", __FILE__)
|
29
|
-
nvim.command("let host = rpcstart('#{host_exe}', ['#{plugin1_path}', '#{plugin2_path}'])")
|
30
|
-
|
31
|
-
expect(nvim.eval("rpcrequest(host, 'poll')")).to eq("ok")
|
32
|
-
expect(nvim.eval("rpcrequest(host, '#{plugin1_path}:command:SyncAdd', 1, 2)")).to eq(3)
|
33
|
-
|
34
|
-
expect {
|
35
|
-
nvim.eval("rpcnotify(host, '#{plugin2_path}:command:AsyncSetLine', 'foo')")
|
36
|
-
nvim.eval("rpcrequest(host, 'poll')")
|
37
|
-
}.to change { nvim.current.buffer.lines.to_a }.from([""]).to(["foo"])
|
38
|
-
|
39
|
-
expect {
|
40
|
-
nvim.eval("rpcnotify(host, 'Unknown')")
|
41
|
-
}.not_to raise_error
|
42
|
-
|
43
|
-
expect {
|
44
|
-
nvim.eval("call rpcrequest(host, 'Unknown')")
|
45
|
-
}.to raise_error(ArgumentError)
|
6
|
+
plugin1_path = Support.file_path("plugin1.rb")
|
7
|
+
File.write(plugin1_path, <<-RUBY)
|
8
|
+
Neovim.plugin do |plug|
|
9
|
+
plug.command(:SyncAdd, :args => 2, :sync => true) do |nvim, x, y|
|
10
|
+
x + y
|
11
|
+
end
|
46
12
|
end
|
47
|
-
|
13
|
+
RUBY
|
14
|
+
|
15
|
+
plugin2_path = Support.file_path("plugin2.rb")
|
16
|
+
File.write(plugin2_path, <<-RUBY)
|
17
|
+
Neovim.plugin do |plug|
|
18
|
+
plug.command(:AsyncSetLine, :args => 1) do |nvim, str|
|
19
|
+
nvim.current.line = str
|
20
|
+
end
|
21
|
+
end
|
22
|
+
RUBY
|
23
|
+
|
24
|
+
nvim = Neovim.attach_child(["--headless", "-u", "NONE", "-N", "-n"])
|
25
|
+
|
26
|
+
host_exe = File.expand_path("../../../bin/neovim-ruby-host", __FILE__)
|
27
|
+
nvim.command("let host = rpcstart('#{host_exe}', ['#{plugin1_path}', '#{plugin2_path}'])")
|
28
|
+
|
29
|
+
expect(nvim.eval("rpcrequest(host, 'poll')")).to eq("ok")
|
30
|
+
expect(nvim.eval("rpcrequest(host, '#{plugin1_path}:command:SyncAdd', [1, 2])")).to eq(3)
|
31
|
+
|
32
|
+
expect {
|
33
|
+
nvim.eval("rpcnotify(host, '#{plugin2_path}:command:AsyncSetLine', ['foo'])")
|
34
|
+
nvim.eval("rpcrequest(host, 'poll')")
|
35
|
+
}.to change { nvim.current.buffer.lines.to_a }.from([""]).to(["foo"])
|
36
|
+
|
37
|
+
expect {
|
38
|
+
nvim.eval("rpcnotify(host, 'Unknown')")
|
39
|
+
}.not_to raise_error
|
40
|
+
|
41
|
+
expect {
|
42
|
+
nvim.eval("call rpcrequest(host, 'Unknown')")
|
43
|
+
}.to raise_error(ArgumentError)
|
48
44
|
end
|
49
45
|
end
|
data/spec/helper.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require "bundler/setup"
|
2
|
+
require "logger"
|
2
3
|
require "neovim"
|
3
4
|
require "pry"
|
4
5
|
require "timeout"
|
5
6
|
|
7
|
+
require File.expand_path("../support.rb", __FILE__)
|
8
|
+
|
6
9
|
if ENV["REPORT_COVERAGE"]
|
7
10
|
require "coveralls"
|
8
11
|
Coveralls.wear!
|
@@ -12,6 +15,10 @@ Thread.abort_on_exception = true
|
|
12
15
|
|
13
16
|
ENV["NVIM_EXECUTABLE"] = File.expand_path("../../vendor/neovim/build/bin/nvim", __FILE__)
|
14
17
|
|
18
|
+
Neovim.logger = Logger.new(STDERR).tap do |logger|
|
19
|
+
logger.level = ENV.fetch("NVIM_RUBY_LOG_LEVEL", Logger::WARN).to_i
|
20
|
+
end
|
21
|
+
|
15
22
|
RSpec.configure do |config|
|
16
23
|
config.expect_with :rspec do |exp|
|
17
24
|
exp.syntax = :expect
|
@@ -22,7 +29,12 @@ RSpec.configure do |config|
|
|
22
29
|
|
23
30
|
Kernel.srand config.seed
|
24
31
|
|
25
|
-
config.around do |spec|
|
26
|
-
|
32
|
+
config.around(:example) do |spec|
|
33
|
+
Support.clean_workspace
|
34
|
+
Timeout.timeout(2) { spec.run }
|
35
|
+
end
|
36
|
+
|
37
|
+
config.after(:suite) do
|
38
|
+
Support.remove_workspace
|
27
39
|
end
|
28
40
|
end
|
@@ -7,7 +7,7 @@ module Neovim
|
|
7
7
|
stream = MsgpackStream.new(event_loop)
|
8
8
|
async = AsyncSession.new(stream)
|
9
9
|
|
10
|
-
|
10
|
+
server_thread = Thread.new do
|
11
11
|
client = server.accept
|
12
12
|
IO.select(nil, [client])
|
13
13
|
client.write(MessagePack.pack(
|
@@ -25,7 +25,7 @@ module Neovim
|
|
25
25
|
|
26
26
|
request = fiber.resume
|
27
27
|
|
28
|
-
|
28
|
+
server_thread.join
|
29
29
|
|
30
30
|
expect(request).to be_a(Request)
|
31
31
|
expect(request.method_name).to eq("func")
|
@@ -36,7 +36,7 @@ module Neovim
|
|
36
36
|
stream = MsgpackStream.new(event_loop)
|
37
37
|
async = AsyncSession.new(stream)
|
38
38
|
|
39
|
-
|
39
|
+
server_thread = Thread.new do
|
40
40
|
client = server.accept
|
41
41
|
IO.select(nil, [client])
|
42
42
|
client.write(MessagePack.pack(
|
@@ -54,7 +54,7 @@ module Neovim
|
|
54
54
|
|
55
55
|
notification = fiber.resume
|
56
56
|
|
57
|
-
|
57
|
+
server_thread.join
|
58
58
|
|
59
59
|
expect(notification).to be_a(Notification)
|
60
60
|
expect(notification.method_name).to eq("func")
|
@@ -66,7 +66,7 @@ module Neovim
|
|
66
66
|
async = AsyncSession.new(stream)
|
67
67
|
messages = []
|
68
68
|
|
69
|
-
|
69
|
+
server_thread = Thread.new do
|
70
70
|
client = server.accept
|
71
71
|
messages << client.readpartial(1024)
|
72
72
|
|
@@ -83,7 +83,7 @@ module Neovim
|
|
83
83
|
|
84
84
|
expect(fiber.resume).to eq(["error", "result"])
|
85
85
|
|
86
|
-
|
86
|
+
server_thread.join
|
87
87
|
|
88
88
|
expect(messages).to eq(
|
89
89
|
[MessagePack.pack([0, 0, "func", [1, 2, 3]])]
|
@@ -99,10 +99,8 @@ module Neovim
|
|
99
99
|
end
|
100
100
|
|
101
101
|
context "unix" do
|
102
|
-
|
103
|
-
|
104
|
-
let!(:server) { UNIXServer.new("/tmp/#$$.sock") }
|
105
|
-
let!(:event_loop) { EventLoop.unix("/tmp/#$$.sock") }
|
102
|
+
let!(:server) { UNIXServer.new(Support.socket_path) }
|
103
|
+
let!(:event_loop) { EventLoop.unix(Support.socket_path) }
|
106
104
|
|
107
105
|
include_context "async session behavior"
|
108
106
|
end
|
data/spec/neovim/buffer_spec.rb
CHANGED
@@ -12,10 +12,24 @@ module Neovim
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "#lines=" do
|
15
|
-
it "updates the
|
15
|
+
it "updates the buffer's lines" do
|
16
16
|
buffer.lines = ["one", "two"]
|
17
17
|
expect(buffer.lines.to_a).to eq(["one", "two"])
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
describe "#range" do
|
22
|
+
it "returns a LineRange" do
|
23
|
+
expect(buffer.range).to be_a(LineRange)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#range=" do
|
28
|
+
it "updates the buffer's range" do
|
29
|
+
buffer.lines = ["one", "two", "three"]
|
30
|
+
buffer.range = (0..1)
|
31
|
+
expect(buffer.range.to_a).to eq(["one", "two"])
|
32
|
+
end
|
33
|
+
end
|
20
34
|
end
|
21
35
|
end
|
data/spec/neovim/current_spec.rb
CHANGED
@@ -74,19 +74,5 @@ module Neovim
|
|
74
74
|
}.to change { current.tabpage.index }.to(initial_index)
|
75
75
|
end
|
76
76
|
end
|
77
|
-
|
78
|
-
describe "#range" do
|
79
|
-
it "returns the current range" do
|
80
|
-
expect(current.range).to be_a(LineRange)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe "#range=" do
|
85
|
-
it "sets the current range" do
|
86
|
-
current.buffer.lines = ["1", "2", "3"]
|
87
|
-
current.range = (1..2)
|
88
|
-
expect(current.range.to_a).to eq(["2", "3"])
|
89
|
-
end
|
90
|
-
end
|
91
77
|
end
|
92
78
|
end
|
@@ -22,7 +22,7 @@ module Neovim
|
|
22
22
|
it "sends and receives data" do
|
23
23
|
messages = []
|
24
24
|
|
25
|
-
|
25
|
+
server_thread = Thread.new do
|
26
26
|
client = server.accept
|
27
27
|
messages << client.readpartial(1024)
|
28
28
|
|
@@ -37,7 +37,7 @@ module Neovim
|
|
37
37
|
end
|
38
38
|
|
39
39
|
expect(fiber.resume).to eq("OK")
|
40
|
-
|
40
|
+
server_thread.join
|
41
41
|
expect(messages).to eq(["data"])
|
42
42
|
end
|
43
43
|
end
|
@@ -50,10 +50,8 @@ module Neovim
|
|
50
50
|
end
|
51
51
|
|
52
52
|
context "unix" do
|
53
|
-
|
54
|
-
|
55
|
-
let!(:server) { UNIXServer.new("/tmp/#$$.sock") }
|
56
|
-
let!(:event_loop) { EventLoop.unix("/tmp/#$$.sock") }
|
53
|
+
let!(:server) { UNIXServer.new(Support.socket_path) }
|
54
|
+
let!(:event_loop) { EventLoop.unix(Support.socket_path) }
|
57
55
|
|
58
56
|
include_context "socket behavior"
|
59
57
|
end
|
@@ -73,7 +71,7 @@ module Neovim
|
|
73
71
|
event_loop = EventLoop.stdio
|
74
72
|
messages = []
|
75
73
|
|
76
|
-
|
74
|
+
server_thread = Thread.new do
|
77
75
|
messages << srv_stdout.readpartial(1024)
|
78
76
|
srv_stdin.write("OK")
|
79
77
|
end
|
@@ -84,7 +82,7 @@ module Neovim
|
|
84
82
|
end
|
85
83
|
|
86
84
|
expect(fiber.resume).to eq("OK")
|
87
|
-
|
85
|
+
server_thread.join
|
88
86
|
expect(messages).to eq(["data"])
|
89
87
|
ensure
|
90
88
|
STDOUT.reopen(old_stdout)
|
data/spec/neovim/host_spec.rb
CHANGED
@@ -1,19 +1,14 @@
|
|
1
1
|
require "helper"
|
2
|
-
require "tempfile"
|
3
2
|
|
4
3
|
module Neovim
|
5
4
|
RSpec.describe Host do
|
6
5
|
describe ".load_from_files" do
|
7
6
|
it "loads the defined plugins into a manifest" do
|
8
|
-
plug1 =
|
9
|
-
|
10
|
-
f.path
|
11
|
-
end
|
7
|
+
plug1 = Support.file_path("plug1.rb")
|
8
|
+
plug2 = Support.file_path("plug2.rb")
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
f.path
|
16
|
-
end
|
10
|
+
File.write(plug1, "Neovim.plugin")
|
11
|
+
File.write(plug2, "Neovim.plugin; Neovim.plugin")
|
17
12
|
|
18
13
|
manifest = Manifest.new
|
19
14
|
|
@@ -23,10 +18,8 @@ module Neovim
|
|
23
18
|
end
|
24
19
|
|
25
20
|
it "doesn't load plugin code into the global namespace" do
|
26
|
-
plug =
|
27
|
-
|
28
|
-
f.path
|
29
|
-
end
|
21
|
+
plug = Support.file_path("plug.rb")
|
22
|
+
File.write(plug, "class FooClass; end")
|
30
23
|
|
31
24
|
host = Host.load_from_files([plug])
|
32
25
|
expect(Kernel.const_defined?("FooClass")).to be(false)
|
@@ -6,11 +6,11 @@ module Neovim
|
|
6
6
|
shared_context "msgpack stream behavior" do
|
7
7
|
it "sends and receives data" do
|
8
8
|
stream = MsgpackStream.new(event_loop)
|
9
|
-
|
9
|
+
client_messages = []
|
10
10
|
|
11
|
-
|
11
|
+
server_thread = Thread.new do
|
12
12
|
client = server.accept
|
13
|
-
|
13
|
+
client_messages << client.readpartial(1024)
|
14
14
|
|
15
15
|
client.write(MessagePack.pack([2]))
|
16
16
|
client.close
|
@@ -22,8 +22,11 @@ module Neovim
|
|
22
22
|
stream.send([1]).run(msg_cb)
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
server_message = fiber.resume
|
26
|
+
server_thread.join
|
27
|
+
|
28
|
+
expect(server_message).to eq([2])
|
29
|
+
expect(client_messages).to eq([MessagePack.pack([1])])
|
27
30
|
end
|
28
31
|
end
|
29
32
|
|
@@ -35,10 +38,8 @@ module Neovim
|
|
35
38
|
end
|
36
39
|
|
37
40
|
context "unix" do
|
38
|
-
|
39
|
-
|
40
|
-
let!(:server) { UNIXServer.new("/tmp/#$$.sock") }
|
41
|
-
let!(:event_loop) { EventLoop.unix("/tmp/#$$.sock") }
|
41
|
+
let!(:server) { UNIXServer.new(Support.socket_path) }
|
42
|
+
let!(:event_loop) { EventLoop.unix(Support.socket_path) }
|
42
43
|
|
43
44
|
include_context "msgpack stream behavior"
|
44
45
|
end
|
data/spec/neovim/session_spec.rb
CHANGED
@@ -34,23 +34,21 @@ module Neovim
|
|
34
34
|
end
|
35
35
|
|
36
36
|
context "tcp" do
|
37
|
-
let!(:nvim_port)
|
38
|
-
server = TCPServer.new("0.0.0.0", 0)
|
39
|
-
server.addr[1].tap { server.close }
|
40
|
-
end
|
41
|
-
|
37
|
+
let!(:nvim_port) { Support.port }
|
42
38
|
let!(:nvim_pid) do
|
43
|
-
Process.spawn(
|
39
|
+
pid = Process.spawn(
|
44
40
|
{"NVIM_LISTEN_ADDRESS" => "0.0.0.0:#{nvim_port}"},
|
45
41
|
"#{ENV.fetch("NVIM_EXECUTABLE")} --headless -n -u NONE",
|
46
42
|
[:out, :err] => "/dev/null"
|
47
|
-
)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
43
|
+
)
|
44
|
+
|
45
|
+
begin
|
46
|
+
TCPSocket.open("0.0.0.0", nvim_port).close
|
47
|
+
rescue Errno::ECONNREFUSED
|
48
|
+
retry
|
53
49
|
end
|
50
|
+
|
51
|
+
pid
|
54
52
|
end
|
55
53
|
|
56
54
|
after do
|
@@ -69,27 +67,30 @@ module Neovim
|
|
69
67
|
end
|
70
68
|
|
71
69
|
context "unix" do
|
70
|
+
let!(:socket_path) { Support.socket_path }
|
72
71
|
let!(:nvim_pid) do
|
73
|
-
|
74
|
-
|
75
|
-
{"NVIM_LISTEN_ADDRESS" => "/tmp/nvim-#$$.sock"},
|
72
|
+
pid = Process.spawn(
|
73
|
+
{"NVIM_LISTEN_ADDRESS" => socket_path},
|
76
74
|
"#{ENV.fetch("NVIM_EXECUTABLE")} --headless -n -u NONE",
|
77
75
|
[:out, :err] => "/dev/null"
|
78
|
-
)
|
79
|
-
|
80
|
-
|
81
|
-
|
76
|
+
)
|
77
|
+
|
78
|
+
begin
|
79
|
+
UNIXSocket.new(socket_path).close
|
80
|
+
rescue Errno::ENOENT, Errno::ECONNREFUSED
|
81
|
+
retry
|
82
82
|
end
|
83
|
+
|
84
|
+
pid
|
83
85
|
end
|
84
86
|
|
85
87
|
after do
|
86
88
|
Process.kill(:TERM, nvim_pid)
|
87
89
|
Process.waitpid(nvim_pid)
|
88
|
-
FileUtils.rm_f("/tmp/nvim-#$$.sock")
|
89
90
|
end
|
90
91
|
|
91
92
|
let(:session) do
|
92
|
-
event_loop = EventLoop.unix(
|
93
|
+
event_loop = EventLoop.unix(socket_path)
|
93
94
|
stream = MsgpackStream.new(event_loop)
|
94
95
|
async = AsyncSession.new(stream)
|
95
96
|
Session.new(async)
|
data/spec/neovim_spec.rb
CHANGED
@@ -8,19 +8,15 @@ RSpec.describe Neovim do
|
|
8
8
|
|
9
9
|
describe ".attach_tcp" do
|
10
10
|
it "attaches to a TCP socket" do
|
11
|
-
|
12
|
-
port = srv.addr[1]
|
13
|
-
srv.close
|
14
|
-
|
11
|
+
port = Support.port
|
15
12
|
env = {"NVIM_LISTEN_ADDRESS" => "0.0.0.0:#{port}"}
|
16
13
|
pid = Process.spawn(env, nvim_exe, *nvim_argv, [:out, :err] => "/dev/null")
|
17
14
|
|
18
15
|
begin
|
19
|
-
|
16
|
+
TCPSocket.open("0.0.0.0", port).close
|
20
17
|
rescue Errno::ECONNREFUSED
|
21
18
|
retry
|
22
19
|
end
|
23
|
-
wait_socket.close
|
24
20
|
|
25
21
|
begin
|
26
22
|
expect(Neovim.attach_tcp("0.0.0.0", port).strwidth("hi")).to eq(2)
|
@@ -32,16 +28,21 @@ RSpec.describe Neovim do
|
|
32
28
|
|
33
29
|
describe ".attach_unix" do
|
34
30
|
it "attaches to a UNIX socket" do
|
35
|
-
|
36
|
-
env = {"NVIM_LISTEN_ADDRESS" =>
|
31
|
+
socket_path = Support.socket_path
|
32
|
+
env = {"NVIM_LISTEN_ADDRESS" => socket_path}
|
37
33
|
pid = Process.spawn(env, nvim_exe, *nvim_argv, [:out, :err] => "/dev/null")
|
38
34
|
|
39
|
-
|
35
|
+
begin
|
36
|
+
UNIXSocket.new(socket_path).close
|
37
|
+
rescue Errno::ENOENT, Errno::ECONNREFUSED
|
38
|
+
retry
|
39
|
+
end
|
40
40
|
|
41
41
|
begin
|
42
|
-
expect(Neovim.attach_unix(
|
42
|
+
expect(Neovim.attach_unix(socket_path).strwidth("hi")).to eq(2)
|
43
43
|
ensure
|
44
44
|
Process.kill(:TERM, pid)
|
45
|
+
Process.waitpid(pid)
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
data/spec/support.rb
ADDED
@@ -0,0 +1,29 @@
|
|
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
|
+
server.addr[1].tap { server.close }
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.file_path(name)
|
18
|
+
File.join(workspace, name)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.remove_workspace
|
22
|
+
FileUtils.rm_rf(workspace)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.clean_workspace
|
26
|
+
remove_workspace
|
27
|
+
FileUtils.mkdir_p(workspace)
|
28
|
+
end
|
29
|
+
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.0.
|
4
|
+
version: 0.0.5
|
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-
|
11
|
+
date: 2016-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- lib/neovim/event_loop.rb
|
122
122
|
- lib/neovim/host.rb
|
123
123
|
- lib/neovim/line_range.rb
|
124
|
+
- lib/neovim/logging.rb
|
124
125
|
- lib/neovim/manifest.rb
|
125
126
|
- lib/neovim/msgpack_stream.rb
|
126
127
|
- lib/neovim/notification.rb
|
@@ -148,6 +149,7 @@ files:
|
|
148
149
|
- spec/neovim/session_spec.rb
|
149
150
|
- spec/neovim/window_spec.rb
|
150
151
|
- spec/neovim_spec.rb
|
152
|
+
- spec/support.rb
|
151
153
|
homepage: https://github.com/alexgenco/neovim-ruby
|
152
154
|
licenses:
|
153
155
|
- MIT
|
@@ -168,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
170
|
version: '0'
|
169
171
|
requirements: []
|
170
172
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.4.
|
173
|
+
rubygems_version: 2.4.5
|
172
174
|
signing_key:
|
173
175
|
specification_version: 4
|
174
176
|
summary: A Ruby client for Neovim
|
@@ -189,3 +191,4 @@ test_files:
|
|
189
191
|
- spec/neovim/session_spec.rb
|
190
192
|
- spec/neovim/window_spec.rb
|
191
193
|
- spec/neovim_spec.rb
|
194
|
+
- spec/support.rb
|