neovim 0.0.6 → 0.1.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 +4 -19
- data/CHANGELOG.md +9 -0
- data/README.md +2 -2
- data/Rakefile +1 -25
- data/bin/j2mp +1 -1
- data/bin/mp2j +1 -1
- data/bin/neovim-ruby-host +9 -0
- data/lib/neovim.rb +5 -7
- data/lib/neovim/async_session.rb +2 -1
- data/lib/neovim/buffer.rb +112 -0
- data/lib/neovim/client.rb +4 -2
- data/lib/neovim/current.rb +9 -1
- data/lib/neovim/event_loop.rb +8 -4
- data/lib/neovim/host.rb +3 -1
- data/lib/neovim/line_range.rb +34 -10
- data/lib/neovim/logging.rb +29 -20
- data/lib/neovim/manifest.rb +9 -3
- data/lib/neovim/plugin.rb +3 -1
- data/lib/neovim/plugin/dsl.rb +14 -0
- data/lib/neovim/plugin/handler.rb +24 -5
- data/lib/neovim/ruby_provider.rb +138 -0
- data/lib/neovim/session.rb +14 -5
- data/lib/neovim/version.rb +1 -1
- data/lib/neovim/window.rb +52 -59
- data/spec/acceptance/neovim-ruby-host_spec.rb +6 -1
- data/spec/acceptance/ruby_provider_spec.rb +76 -0
- data/spec/helper.rb +13 -19
- data/spec/neovim/async_session_spec.rb +19 -15
- data/spec/neovim/buffer_spec.rb +127 -1
- data/spec/neovim/client_spec.rb +1 -1
- data/spec/neovim/current_spec.rb +9 -1
- data/spec/neovim/event_loop_spec.rb +20 -21
- data/spec/neovim/host_spec.rb +1 -1
- data/spec/neovim/line_range_spec.rb +73 -9
- data/spec/neovim/manifest_spec.rb +26 -0
- data/spec/neovim/msgpack_stream_spec.rb +8 -8
- data/spec/neovim/plugin_spec.rb +41 -0
- data/spec/neovim/remote_object_spec.rb +3 -3
- data/spec/neovim/session_spec.rb +68 -29
- data/spec/neovim/window_spec.rb +47 -24
- data/spec/neovim_spec.rb +3 -5
- data/spec/support.rb +1 -2
- metadata +5 -3
- data/.gitmodules +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6807525e36364dd7a60d2e24a3e5ad3b5c370d88
|
4
|
+
data.tar.gz: 59a4fcb659bf1f7f9d2d210aace08b099abb55df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c19a0766059f4202ce10e4251ee6b88d4db7534c6623c9aec4273386e3af67e92fe2564410f29a5cc8575e71cc488da631b7b6b93a1fcc85aca5492ac9be28e
|
7
|
+
data.tar.gz: a941792a2f0b00aac4e7b3af6c738835fc1f682e989829fe4af665802276684aad5ad64cf392e5d5234f211acbb64454dbc4cf3d694f9f051f3cbaef4c43787e
|
data/.travis.yml
CHANGED
@@ -9,25 +9,10 @@ rvm:
|
|
9
9
|
- 2.0.0
|
10
10
|
- 2.1.0
|
11
11
|
- 2.2.0
|
12
|
+
- 2.3.0
|
12
13
|
|
13
|
-
|
14
|
-
-
|
15
|
-
- osx
|
16
|
-
|
17
|
-
addons:
|
18
|
-
apt:
|
19
|
-
packages:
|
20
|
-
- libtool
|
21
|
-
- autoconf
|
22
|
-
- automake
|
23
|
-
- cmake
|
24
|
-
- libncurses5-dev
|
25
|
-
- g++
|
26
|
-
- pkg-config
|
27
|
-
|
28
|
-
cache:
|
29
|
-
- apt
|
30
|
-
- bundler
|
14
|
+
before_install:
|
15
|
+
- eval "$(curl -Ss https://raw.githubusercontent.com/neovim/bot-ci/master/scripts/travis-setup.sh) nightly-x64"
|
31
16
|
|
32
17
|
env: REPORT_COVERAGE=1
|
33
|
-
script: bundle exec rake spec
|
18
|
+
script: bundle exec rake --trace spec
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# 0.1.0
|
2
|
+
- Add --version, -V to neovim-ruby-host executable
|
3
|
+
- Update object interfaces to be compatible with Vim :ruby API
|
4
|
+
- `NVIM_RUBY_LOG_LEVEL` now takes strings, e.g. `DEBUG`
|
5
|
+
- Add `rpc` plugin DSL method for exposing top-level functions
|
6
|
+
- Add `ruby_provider.rb` for Vim :ruby API compatibility
|
7
|
+
- Remove Cursor class
|
8
|
+
- Remove vendored `neovim`
|
9
|
+
|
1
10
|
# 0.0.6
|
2
11
|
- Update Session with improved Fiber coordination
|
3
12
|
- Documentation
|
data/README.md
CHANGED
@@ -48,8 +48,8 @@ The `neovim-ruby-host` executable can be used to spawn Ruby plugins via the `rpc
|
|
48
48
|
# $VIMRUNTIME/rplugin/ruby/my_plugin.rb
|
49
49
|
|
50
50
|
Neovim.plugin do |plug|
|
51
|
-
# Define a command called "SetLine" which sets the
|
52
|
-
#
|
51
|
+
# Define a command called "SetLine" which sets the contents of the current
|
52
|
+
# line. This command is executed asynchronously, so the return value is
|
53
53
|
# ignored.
|
54
54
|
plug.command(:SetLine, :nargs => 1) do |nvim, str|
|
55
55
|
nvim.current.line = str
|
data/Rakefile
CHANGED
@@ -3,31 +3,7 @@ require "rspec/core/rake_task"
|
|
3
3
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
5
5
|
|
6
|
-
namespace :spec do
|
7
|
-
desc "Build Neovim and run specs on CI"
|
8
|
-
task :ci => ["neovim:build", :spec]
|
9
|
-
end
|
10
|
-
|
11
6
|
namespace :neovim do
|
12
|
-
vendor = File.expand_path("../vendor/neovim", __FILE__)
|
13
|
-
|
14
|
-
desc "Build Neovim"
|
15
|
-
task :build do
|
16
|
-
sh "git submodule update --init && " +
|
17
|
-
"cd #{vendor} && " +
|
18
|
-
"make distclean && " +
|
19
|
-
"make"
|
20
|
-
end
|
21
|
-
|
22
|
-
desc "Update vendored Neovim revision"
|
23
|
-
task :update do
|
24
|
-
sh "git submodule update --init && " +
|
25
|
-
"cd #{vendor} && " +
|
26
|
-
"make distclean && " +
|
27
|
-
"git pull origin master && " +
|
28
|
-
"make"
|
29
|
-
end
|
30
|
-
|
31
7
|
desc "Generate Neovim remote API docs"
|
32
8
|
task :generate_docs do
|
33
9
|
require "neovim"
|
@@ -37,7 +13,7 @@ namespace :neovim do
|
|
37
13
|
buffer_docs = []
|
38
14
|
window_docs = []
|
39
15
|
tabpage_docs = []
|
40
|
-
session = Neovim::Session.child(%w(-u NONE -n -N))
|
16
|
+
session = Neovim::Session.child(%w(nvim -u NONE -n -N))
|
41
17
|
|
42
18
|
session.request(:vim_get_api_info)[1]["functions"].each do |func|
|
43
19
|
prefix, method_name = func["name"].split("_", 2)
|
data/bin/j2mp
CHANGED
data/bin/mp2j
CHANGED
data/bin/neovim-ruby-host
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require "neovim"
|
3
3
|
|
4
|
+
ARGV.each do |arg|
|
5
|
+
break if arg == "--"
|
6
|
+
|
7
|
+
if ["--version", "-V"].include?(arg)
|
8
|
+
puts Neovim::VERSION
|
9
|
+
exit(0)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
4
13
|
if STDIN.tty?
|
5
14
|
abort("Can't run neovim-ruby-host interactively.")
|
6
15
|
else
|
data/lib/neovim.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
require "neovim/async_session"
|
2
1
|
require "neovim/client"
|
3
|
-
require "neovim/event_loop"
|
4
2
|
require "neovim/host"
|
5
|
-
require "neovim/msgpack_stream"
|
6
3
|
require "neovim/session"
|
7
4
|
require "neovim/plugin"
|
5
|
+
require "neovim/version"
|
8
6
|
|
9
7
|
# The main entrypoint to the +Neovim+ gem. It allows you to connect to a
|
10
8
|
# running +nvim+ instance programmatically or define a remote plugin to be
|
@@ -27,7 +25,7 @@ require "neovim/plugin"
|
|
27
25
|
# Neovim.attach_unix("/tmp/nvim.sock") # => Neovim::Client
|
28
26
|
#
|
29
27
|
# @example Spawn and connect to a child +nvim+ process
|
30
|
-
# Neovim.attach_child(["
|
28
|
+
# Neovim.attach_child(["nvim", "--embed"]) # => Neovim::Client
|
31
29
|
#
|
32
30
|
# @example Define a Ruby plugin
|
33
31
|
# # ~/.config/nvim/rplugin/ruby/plugin.rb
|
@@ -73,7 +71,7 @@ module Neovim
|
|
73
71
|
# @return [Client]
|
74
72
|
# @see Session.tcp
|
75
73
|
def self.attach_tcp(host, port)
|
76
|
-
Client.new
|
74
|
+
Client.new Session.tcp(host, port)
|
77
75
|
end
|
78
76
|
|
79
77
|
# Connect to a running +nvim+ instance over a UNIX domain socket.
|
@@ -82,7 +80,7 @@ module Neovim
|
|
82
80
|
# @return [Client]
|
83
81
|
# @see Session.unix
|
84
82
|
def self.attach_unix(socket_path)
|
85
|
-
Client.new
|
83
|
+
Client.new Session.unix(socket_path)
|
86
84
|
end
|
87
85
|
|
88
86
|
# Spawn and connect to a child +nvim+ process.
|
@@ -91,7 +89,7 @@ module Neovim
|
|
91
89
|
# @return [Client]
|
92
90
|
# @see Session.child
|
93
91
|
def self.attach_child(argv=[])
|
94
|
-
Client.new
|
92
|
+
Client.new Session.child(argv)
|
95
93
|
end
|
96
94
|
|
97
95
|
# Define an +nvim+ remote plugin using the plugin DSL.
|
data/lib/neovim/async_session.rb
CHANGED
@@ -101,7 +101,8 @@ module Neovim
|
|
101
101
|
|
102
102
|
def handle_response(payload)
|
103
103
|
reqid, (_, error), result = payload
|
104
|
-
@pending_requests.delete(reqid).
|
104
|
+
callback = @pending_requests.delete(reqid) || Proc.new {}
|
105
|
+
callback.call(error, result)
|
105
106
|
end
|
106
107
|
|
107
108
|
def handle_notification(payload, callback)
|
data/lib/neovim/buffer.rb
CHANGED
@@ -38,6 +38,105 @@ module Neovim
|
|
38
38
|
@range = LineRange.new(self, _range.begin, _end)
|
39
39
|
end
|
40
40
|
|
41
|
+
# Get the buffer name.
|
42
|
+
#
|
43
|
+
# @return [String]
|
44
|
+
def name
|
45
|
+
get_name
|
46
|
+
end
|
47
|
+
|
48
|
+
# Get the buffer index.
|
49
|
+
#
|
50
|
+
# @return [Fixnum]
|
51
|
+
def number
|
52
|
+
get_number
|
53
|
+
end
|
54
|
+
|
55
|
+
# Get the number of lines.
|
56
|
+
#
|
57
|
+
# @return [Fixnum]
|
58
|
+
def count
|
59
|
+
lines.to_a.size
|
60
|
+
end
|
61
|
+
|
62
|
+
# Get the number of lines.
|
63
|
+
#
|
64
|
+
# @return [Fixnum]
|
65
|
+
def length
|
66
|
+
count
|
67
|
+
end
|
68
|
+
|
69
|
+
# Get the line at the given index.
|
70
|
+
#
|
71
|
+
# @param index [Fixnum]
|
72
|
+
# @return [String]
|
73
|
+
def [](index)
|
74
|
+
lines[index]
|
75
|
+
end
|
76
|
+
|
77
|
+
# Set the line at the given index.
|
78
|
+
#
|
79
|
+
# @param index [Fixnum]
|
80
|
+
# @param str [String]
|
81
|
+
# @return [String]
|
82
|
+
def []=(index, str)
|
83
|
+
lines[index] = str
|
84
|
+
end
|
85
|
+
|
86
|
+
# Delete the line at the given index.
|
87
|
+
#
|
88
|
+
# @param index [Fixnum]
|
89
|
+
# @return [void]
|
90
|
+
def delete(index)
|
91
|
+
lines.delete(index)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Append a line after the given index.
|
95
|
+
#
|
96
|
+
# @param index [Fixnum]
|
97
|
+
# @param str [String]
|
98
|
+
# @return [String]
|
99
|
+
def append(index, str)
|
100
|
+
lines[index, 1] = [lines[index], str]
|
101
|
+
str
|
102
|
+
end
|
103
|
+
|
104
|
+
# Get the current line of an active buffer.
|
105
|
+
#
|
106
|
+
# @return [String, nil]
|
107
|
+
def line
|
108
|
+
if active?
|
109
|
+
@session.request(:vim_get_current_line)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# Set the current line of an active buffer.
|
114
|
+
#
|
115
|
+
# @param str [String]
|
116
|
+
# @return [String, nil]
|
117
|
+
def line=(str)
|
118
|
+
if active?
|
119
|
+
@session.request(:vim_set_current_line, str)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Get the current line number of an active buffer.
|
124
|
+
#
|
125
|
+
# @return [Fixnum, nil]
|
126
|
+
def line_number
|
127
|
+
if active?
|
128
|
+
window = @session.request(:vim_get_current_window)
|
129
|
+
@session.request(:window_get_cursor, window)[0]
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# Determine if the buffer is active.
|
134
|
+
#
|
135
|
+
# @return [Boolean]
|
136
|
+
def active?
|
137
|
+
@session.request(:vim_get_current_buffer) == self
|
138
|
+
end
|
139
|
+
|
41
140
|
# The following methods are dynamically generated.
|
42
141
|
=begin
|
43
142
|
@method line_count
|
@@ -63,6 +162,12 @@ module Neovim
|
|
63
162
|
@param [Boolean] include_end
|
64
163
|
@return [Array<String>]
|
65
164
|
|
165
|
+
@method get_lines(start, end, strict_indexing)
|
166
|
+
@param [Fixnum] start
|
167
|
+
@param [Fixnum] end
|
168
|
+
@param [Boolean] strict_indexing
|
169
|
+
@return [Array<String>]
|
170
|
+
|
66
171
|
@method set_line_slice(start, end, include_start, include_end, replacement)
|
67
172
|
@param [Fixnum] start
|
68
173
|
@param [Fixnum] end
|
@@ -71,6 +176,13 @@ module Neovim
|
|
71
176
|
@param [Array<String>] replacement
|
72
177
|
@return [void]
|
73
178
|
|
179
|
+
@method set_lines(start, end, strict_indexing, replacement)
|
180
|
+
@param [Fixnum] start
|
181
|
+
@param [Fixnum] end
|
182
|
+
@param [Boolean] strict_indexing
|
183
|
+
@param [Array<String>] replacement
|
184
|
+
@return [void]
|
185
|
+
|
74
186
|
@method get_var(name)
|
75
187
|
@param [String] name
|
76
188
|
@return [Object]
|
data/lib/neovim/client.rb
CHANGED
@@ -13,6 +13,8 @@ module Neovim
|
|
13
13
|
attr_reader :session
|
14
14
|
|
15
15
|
def initialize(session)
|
16
|
+
session.discover_api
|
17
|
+
|
16
18
|
@session = session
|
17
19
|
@api = session.api
|
18
20
|
end
|
@@ -20,7 +22,7 @@ module Neovim
|
|
20
22
|
# Intercept method calls and delegate to appropriate RPC methods.
|
21
23
|
def method_missing(method_name, *args)
|
22
24
|
if func = @api.function("vim_#{method_name}")
|
23
|
-
func.call(session, *args)
|
25
|
+
func.call(@session, *args)
|
24
26
|
else
|
25
27
|
super
|
26
28
|
end
|
@@ -45,7 +47,7 @@ module Neovim
|
|
45
47
|
# client.current.line = "New line"
|
46
48
|
# @see Current
|
47
49
|
def current
|
48
|
-
Current.new(@session)
|
50
|
+
@current ||= Current.new(@session)
|
49
51
|
end
|
50
52
|
|
51
53
|
private
|
data/lib/neovim/current.rb
CHANGED
@@ -8,6 +8,7 @@ module Neovim
|
|
8
8
|
class Current
|
9
9
|
def initialize(session)
|
10
10
|
@session = session
|
11
|
+
@range = (0..-1)
|
11
12
|
end
|
12
13
|
|
13
14
|
# @return [String]
|
@@ -23,7 +24,9 @@ module Neovim
|
|
23
24
|
|
24
25
|
# @return [Buffer]
|
25
26
|
def buffer
|
26
|
-
@session.request(:vim_get_current_buffer)
|
27
|
+
@session.request(:vim_get_current_buffer).tap do |buf|
|
28
|
+
buf.range = @range
|
29
|
+
end
|
27
30
|
end
|
28
31
|
|
29
32
|
# @param buffer [Buffer, Fixnum] The target buffer or index.
|
@@ -53,5 +56,10 @@ module Neovim
|
|
53
56
|
def tabpage=(tabpage)
|
54
57
|
@session.request(:vim_set_current_tabpage, tabpage)
|
55
58
|
end
|
59
|
+
|
60
|
+
# @param range [Range] The target range
|
61
|
+
def range=(range)
|
62
|
+
@range = range
|
63
|
+
end
|
56
64
|
end
|
57
65
|
end
|
data/lib/neovim/event_loop.rb
CHANGED
@@ -32,8 +32,7 @@ module Neovim
|
|
32
32
|
# @param argv [Array] The arguments to pass to the spawned process
|
33
33
|
# @return [EventLoop]
|
34
34
|
def self.child(argv)
|
35
|
-
|
36
|
-
io = IO.popen(argv, "rb+")
|
35
|
+
io = IO.popen(argv | ["--embed"], "rb+")
|
37
36
|
new(io)
|
38
37
|
end
|
39
38
|
|
@@ -104,8 +103,13 @@ module Neovim
|
|
104
103
|
# @return [void]
|
105
104
|
def shutdown
|
106
105
|
stop
|
107
|
-
|
108
|
-
|
106
|
+
|
107
|
+
[@rd, @wr].each do |io|
|
108
|
+
begin
|
109
|
+
io.close
|
110
|
+
rescue IOError
|
111
|
+
end
|
112
|
+
end
|
109
113
|
end
|
110
114
|
end
|
111
115
|
end
|
data/lib/neovim/host.rb
CHANGED
@@ -49,6 +49,8 @@ module Neovim
|
|
49
49
|
#
|
50
50
|
# @return [void]
|
51
51
|
def run
|
52
|
+
@session.discover_api
|
53
|
+
|
52
54
|
@session.run do |msg|
|
53
55
|
debug("received #{msg.inspect}")
|
54
56
|
@manifest.handle(msg, client)
|
@@ -61,7 +63,7 @@ module Neovim
|
|
61
63
|
private
|
62
64
|
|
63
65
|
def client
|
64
|
-
@client ||= Client.new(@session
|
66
|
+
@client ||= Client.new(@session)
|
65
67
|
end
|
66
68
|
end
|
67
69
|
end
|
data/lib/neovim/line_range.rb
CHANGED
@@ -38,14 +38,21 @@ module Neovim
|
|
38
38
|
# line_range[0, 2] # => ["first", "second"]
|
39
39
|
def [](pos, len=nil)
|
40
40
|
case pos
|
41
|
-
when
|
42
|
-
|
43
|
-
|
41
|
+
when Range
|
42
|
+
LineRange.new(
|
43
|
+
@buffer,
|
44
|
+
abs_line(pos.begin),
|
45
|
+
abs_line(pos.exclude_end? ? pos.end - 1 : pos.end)
|
46
|
+
)
|
44
47
|
else
|
45
48
|
if len
|
46
|
-
LineRange.new(
|
49
|
+
LineRange.new(
|
50
|
+
@buffer,
|
51
|
+
abs_line(pos),
|
52
|
+
abs_line(pos + len -1)
|
53
|
+
)
|
47
54
|
else
|
48
|
-
@buffer.get_line(pos)
|
55
|
+
@buffer.get_line(abs_line(pos))
|
49
56
|
end
|
50
57
|
end
|
51
58
|
end
|
@@ -75,19 +82,25 @@ module Neovim
|
|
75
82
|
pos, len = target
|
76
83
|
|
77
84
|
case pos
|
78
|
-
when
|
85
|
+
when Range
|
79
86
|
@buffer.set_line_slice(
|
80
|
-
pos.begin,
|
81
|
-
pos.end,
|
87
|
+
abs_line(pos.begin),
|
88
|
+
abs_line(pos.end),
|
82
89
|
true,
|
83
90
|
!pos.exclude_end?,
|
84
91
|
val
|
85
92
|
)
|
86
93
|
else
|
87
94
|
if len
|
88
|
-
@buffer.set_line_slice(
|
95
|
+
@buffer.set_line_slice(
|
96
|
+
abs_line(pos),
|
97
|
+
abs_line(pos + len),
|
98
|
+
true,
|
99
|
+
false,
|
100
|
+
val
|
101
|
+
)
|
89
102
|
else
|
90
|
-
@buffer.set_line(pos, val)
|
103
|
+
@buffer.set_line(abs_line(pos), val)
|
91
104
|
end
|
92
105
|
end
|
93
106
|
end
|
@@ -97,5 +110,16 @@ module Neovim
|
|
97
110
|
self[0..-1] = other
|
98
111
|
self
|
99
112
|
end
|
113
|
+
|
114
|
+
# @param index [Fixnum]
|
115
|
+
def delete(index)
|
116
|
+
@buffer.del_line(abs_line(index))
|
117
|
+
end
|
118
|
+
|
119
|
+
private
|
120
|
+
|
121
|
+
def abs_line(n)
|
122
|
+
n < 0 ? (@end + n + 1) : @begin + n
|
123
|
+
end
|
100
124
|
end
|
101
125
|
end
|