neovim 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3a9a7f0da47d7d562b10232fe88d5c4ad4fe0d0
4
- data.tar.gz: f12e9d6d73601ca7f5b1650b4c9d35e391f2755d
3
+ metadata.gz: 9fe8a4ab833d55be2946a9a6b9db21771c47fffe
4
+ data.tar.gz: d8c4a84c020b04124978cc4311f43e113bbac1c9
5
5
  SHA512:
6
- metadata.gz: e3f98a53f364aebc4829e8c11dea30f5930b96686ed3bba9691559ec0947825f42d0ad4a33da4658f2cca2c3e298f07434a25c8b218df6e6c4ab22280933dd04
7
- data.tar.gz: d37fd74b9f588da7c09844c7c3c7c6cdd18edba7f15e9115cc5bcb54a06744e70337349841ae81ae8b4f116492529a5fbc86ee5a2b60869cdedc6720fd69ece0
6
+ metadata.gz: bc3418eaa160281fc251f2f57a7e7f5754db4a3f9d7c21d8b29482098556185f4a828d0eb3960f0eb117c352349a0b1077d6471a585ffafec64663bc791978ec
7
+ data.tar.gz: ff1fd3a88fc4b8bcc44024eab6e4eb22999c68810784ea215448432653f7327a06b1a5d6befe3d2e16cf46618e2fc90bebd71951faf1910fa67fc3767b80be10
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
19
  spec/workspace
20
+ vendor/bundle
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.2.1
2
+ - Fix race condition in Fiber handling
3
+ - General improvements to ruby\_provider.rb
4
+
1
5
  # 0.2.0
2
6
  - Backwards incompatible, but we're pre-1.0.0 so going with minor bump instead
3
7
  - Make legacy ruby functions 1-indexed
data/README.md CHANGED
@@ -70,6 +70,8 @@ end
70
70
 
71
71
  After a call to `:UpdateRemotePlugins`, plugins will be auto-loaded from the `$VIMRUNTIME/rplugin/ruby` directory.
72
72
 
73
+ Neovim also supports the legacy Vim commands `:ruby`, `:rubyfile`, and `:rubydo`. A detailed description of their usage can be found with `:help ruby`.
74
+
73
75
  ## Links
74
76
 
75
77
  * Source: <http://github.com/alexgenco/neovim-ruby>
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ namespace :neovim do
13
13
  buffer_docs = []
14
14
  window_docs = []
15
15
  tabpage_docs = []
16
- session = Neovim::Session.child(%w(nvim -u NONE -n -N))
16
+ session = Neovim::Session.child(%w(nvim -u NONE -n))
17
17
 
18
18
  session.request(:vim_get_api_info)[1]["functions"].each do |func|
19
19
  prefix, method_name = func["name"].split("_", 2)
data/lib/neovim/buffer.rb CHANGED
@@ -192,6 +192,10 @@ module Neovim
192
192
  @param [Object] value
193
193
  @return [Object]
194
194
 
195
+ @method del_var(name)
196
+ @param [String] name
197
+ @return [Object]
198
+
195
199
  @method get_option(name)
196
200
  @param [String] name
197
201
  @return [Object]
data/lib/neovim/client.rb CHANGED
@@ -144,6 +144,10 @@ module Neovim
144
144
  @param [Object] value
145
145
  @return [Object]
146
146
 
147
+ @method del_var(name)
148
+ @param [String] name
149
+ @return [Object]
150
+
147
151
  @method get_vvar(name)
148
152
  @param [String] name
149
153
  @return [Object]
@@ -85,7 +85,7 @@ module Neovim
85
85
  yield message if block_given?
86
86
  end
87
87
  rescue EOFError
88
- warn("got EOFError")
88
+ info("got EOFError")
89
89
  rescue => e
90
90
  fatal("got unexpected error #{e}")
91
91
  debug(e.backtrace.join("\n"))
@@ -1,129 +1,103 @@
1
- $__ruby_provider_scope = binding
2
-
3
- class VIM < BasicObject
4
- class << self
5
- attr_accessor :__client
6
- end
7
-
8
- Buffer = ::Neovim::Buffer
9
- Window = ::Neovim::Window
10
-
11
- def self.method_missing(method, *args, &block)
12
- @__client.public_send(method, *args, &block)
13
- end
14
- end
1
+ require "neovim/ruby_provider/vim"
2
+ require "neovim/ruby_provider/buffer_ext"
3
+ require "neovim/ruby_provider/window_ext"
15
4
 
16
5
  module Neovim
17
- # Make +VIM::Buffer.current+ return the current buffer.
18
- class Buffer
19
- def self.current
20
- ::VIM.current.buffer
21
- end
22
-
23
- def self.count
24
- ::VIM.get_buffers.size
25
- end
26
-
27
- def self.[](index)
28
- ::VIM.get_buffers[index]
29
- end
30
- end
31
-
32
- # Make +VIM::Window.current+ return the current buffer.
33
- class Window
34
- def self.current
35
- ::VIM.current.window
36
- end
37
-
38
- def self.count
39
- ::VIM.get_windows.size
40
- end
41
-
42
- def self.[](index)
43
- ::VIM.get_windows[index]
44
- end
45
- end
46
-
6
+ # This class is used to define a +Neovim::Plugin+ to act as a backend for the
7
+ # legacy +:ruby+, +:rubyfile+, and +:rubydo+ Vim commands. It is autoloaded
8
+ # from +nvim+ and not intended to be loaded directly.
47
9
  module RubyProvider
48
- def self.define_plugin!
10
+ def self.__define_plugin!
11
+ Thread.abort_on_exception = true
12
+
49
13
  Neovim.plugin do |plug|
50
- define_ruby_execute(plug)
51
- define_ruby_execute_file(plug)
52
- define_ruby_do_range(plug)
14
+ __define_ruby_execute(plug)
15
+ __define_ruby_execute_file(plug)
16
+ __define_ruby_do_range(plug)
53
17
  end
54
18
  end
55
19
 
56
- def self.define_ruby_execute(plug)
20
+ # Evaluate the provided Ruby code, exposing the +VIM+ constant for
21
+ # interactions with the editor.
22
+ #
23
+ # This is used by the +:ruby+ command.
24
+ def self.__define_ruby_execute(plug)
57
25
  plug.rpc(:ruby_execute, sync: true) do |nvim, ruby|
58
- wrap_client(nvim) do
59
- $__ruby_provider_scope.eval(ruby, __FILE__, __LINE__)
26
+ __wrap_client(nvim) do
27
+ eval(ruby, TOPLEVEL_BINDING, __FILE__, __LINE__)
60
28
  end
61
29
  end
62
30
  end
63
- private_class_method :define_ruby_execute
31
+ private_class_method :__define_ruby_execute
64
32
 
65
- def self.define_ruby_execute_file(plug)
33
+ # Evaluate the provided Ruby file, exposing the +VIM+ constant for
34
+ # interactions with the editor.
35
+ #
36
+ # This is used by the +:rubyfile+ command.
37
+ def self.__define_ruby_execute_file(plug)
66
38
  plug.rpc(:ruby_execute_file, sync: true) do |nvim, path|
67
- wrap_client(nvim) do
68
- $__ruby_provider_scope.eval(File.read(path), __FILE__, __LINE__)
69
- end
39
+ __wrap_client(nvim) { load(path) }
70
40
  end
71
41
  end
72
- private_class_method :define_ruby_execute_file
73
-
74
- def self.define_ruby_do_range(plug)
75
- plug.rpc(:ruby_do_range, sync: true) do |nvim, *args|
76
- wrap_client(nvim) do
77
- start, stop, ruby = args
78
- buffer = nvim.current.buffer
79
-
80
- (start..stop).each_slice(5000) do |linenos|
81
- _start, _stop = linenos[0]-1, linenos[-1]
82
- lines = buffer.get_lines(_start, _stop, true)
83
-
84
- lines.map! do |line|
85
- $__ruby_provider_scope.eval("$_ = #{line.inspect}")
86
- $__ruby_provider_scope.eval(ruby, __FILE__, __LINE__)
87
- $__ruby_provider_scope.eval("$_")
42
+ private_class_method :__define_ruby_execute_file
43
+
44
+ # Evaluate the provided Ruby code over each line of a range. The contents
45
+ # of the current line can be accessed and modified via the +$_+ variable.
46
+ #
47
+ # Since this method evaluates each line in the local binding, all local
48
+ # variables and methods are available to the user. Thus the +__+ prefix
49
+ # obfuscation.
50
+ #
51
+ # This is used by the +:rubydo+ command.
52
+ def self.__define_ruby_do_range(__plug)
53
+ __plug.rpc(:ruby_do_range, sync: true) do |__nvim, *__args|
54
+ __wrap_client(__nvim) do
55
+ __start, __stop, __ruby = __args
56
+ __buffer = __nvim.get_current_buffer
57
+
58
+ __update_lines_in_chunks(__buffer, __start, __stop, 5000) do |__lines|
59
+ __lines.map do |__line|
60
+ $_ = __line
61
+ eval(__ruby, binding, __FILE__, __LINE__)
62
+ $_
88
63
  end
89
-
90
- buffer.set_lines(_start, _stop, true, lines)
91
64
  end
92
65
  end
93
66
  end
94
67
  end
95
- private_class_method :define_ruby_do_range
68
+ private_class_method :__define_ruby_do_range
96
69
 
97
- def self.wrap_client(__client)
98
- with_globals(__client) do
99
- with_vim_constant(__client) do
100
- with_redirect_streams(__client) do
70
+ # @api private
71
+ def self.__wrap_client(client)
72
+ __with_globals(client) do
73
+ __with_vim_constant(client) do
74
+ __with_redirect_streams(client) do
101
75
  yield
102
76
  end
103
77
  end
104
78
  end
105
79
  nil
106
80
  end
107
- private_class_method :wrap_client
81
+ private_class_method :__wrap_client
108
82
 
109
- def self.with_globals(client)
110
- $curbuf = client.current.buffer
111
- $curwin = client.current.window
83
+ # @api private
84
+ def self.__with_globals(client)
85
+ $curbuf = client.get_current_buffer
86
+ $curwin = client.get_current_window
112
87
  yield
113
88
  end
114
- private_class_method :with_globals
89
+ private_class_method :__with_globals
115
90
 
116
- def self.with_vim_constant(client)
91
+ # @api private
92
+ def self.__with_vim_constant(client)
117
93
  ::VIM.__client = client
118
94
  yield
119
95
  end
120
- private_class_method :with_vim_constant
121
-
122
- def self.with_redirect_streams(client)
123
- @with_redirect_streams ||= begin
124
- old_out_write = $stdout.method(:write)
125
- old_err_write = $stderr.method(:write)
96
+ private_class_method :__with_vim_constant
126
97
 
98
+ # @api private
99
+ def self.__with_redirect_streams(client)
100
+ @__with_redirect_streams ||= begin
127
101
  $stdout.define_singleton_method(:write) do |string|
128
102
  client.out_write(string)
129
103
  end
@@ -137,8 +111,19 @@ module Neovim
137
111
 
138
112
  yield
139
113
  end
140
- private_class_method :with_redirect_streams
114
+ private_class_method :__with_redirect_streams
115
+
116
+ # @api private
117
+ def self.__update_lines_in_chunks(buffer, start, stop, size)
118
+ (start..stop).each_slice(size) do |linenos|
119
+ _start, _stop = linenos[0]-1, linenos[-1]
120
+ lines = buffer.get_lines(_start, _stop, true)
121
+
122
+ buffer.set_lines(_start, _stop, true, yield(lines))
123
+ end
124
+ end
125
+ private_class_method :__update_lines_in_chunks
141
126
  end
142
127
  end
143
128
 
144
- Neovim::RubyProvider.define_plugin!
129
+ Neovim::RubyProvider.__define_plugin!
@@ -0,0 +1,17 @@
1
+ require "neovim/ruby_provider/vim"
2
+
3
+ module Neovim
4
+ class Buffer
5
+ def self.current
6
+ ::VIM.get_current_buffer
7
+ end
8
+
9
+ def self.count
10
+ ::VIM.get_buffers.size
11
+ end
12
+
13
+ def self.[](index)
14
+ ::VIM.get_buffers[index]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ require "neovim/buffer"
2
+ require "neovim/window"
3
+
4
+ class VIM < BasicObject
5
+ Buffer = ::Neovim::Buffer
6
+ Window = ::Neovim::Window
7
+
8
+ def self.__client=(client)
9
+ @__client = client
10
+ end
11
+
12
+ def self.method_missing(method, *args, &block)
13
+ @__client.public_send(method, *args, &block)
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ require "neovim/ruby_provider/vim"
2
+
3
+ module Neovim
4
+ class Window
5
+ def self.current
6
+ ::VIM.get_current_window
7
+ end
8
+
9
+ def self.count
10
+ ::VIM.get_windows.size
11
+ end
12
+
13
+ def self.[](index)
14
+ ::VIM.get_windows[index]
15
+ end
16
+ end
17
+ end
@@ -57,6 +57,7 @@ module Neovim
57
57
  def initialize(async_session)
58
58
  @async_session = async_session
59
59
  @pending_messages = []
60
+ @main_thread = Thread.current
60
61
  @main_fiber = Fiber.current
61
62
  @running = false
62
63
  end
@@ -117,15 +118,17 @@ module Neovim
117
118
  # @return [Object] The response from the RPC call
118
119
  # @raise [ArgumentError] An error returned from +nvim+
119
120
  def request(method, *args)
120
- if Fiber.current == @main_fiber
121
- debug("handling blocking request")
122
- err, res = stopped_request(method, *args)
123
- else
124
- debug("yielding request to fiber")
125
- err, res = running_request(method, *args)
121
+ main_thread_only do
122
+ if Fiber.current == @main_fiber
123
+ debug("handling blocking request")
124
+ err, res = stopped_request(method, *args)
125
+ else
126
+ debug("yielding request to fiber")
127
+ err, res = running_request(method, *args)
128
+ end
129
+
130
+ err ? raise(ArgumentError, err) : res
126
131
  end
127
-
128
- err ? raise(ArgumentError, err) : res
129
132
  end
130
133
 
131
134
  # Make an RPC notification.
@@ -134,8 +137,10 @@ module Neovim
134
137
  # @param *args [Array] The RPC method arguments
135
138
  # @return [nil]
136
139
  def notify(method, *args)
137
- @async_session.notify(method, *args)
138
- nil
140
+ main_thread_only do
141
+ @async_session.notify(method, *args)
142
+ nil
143
+ end
139
144
  end
140
145
 
141
146
  # Stop the event loop.
@@ -185,5 +190,16 @@ module Neovim
185
190
 
186
191
  [error, result]
187
192
  end
193
+
194
+ def main_thread_only
195
+ if Thread.current == @main_thread
196
+ yield if block_given?
197
+ else
198
+ raise(
199
+ "A Ruby plugin attempted to call neovim outside of the main thread, " +
200
+ "which is not yet supported by the neovim gem."
201
+ )
202
+ end
203
+ end
188
204
  end
189
205
  end
@@ -17,6 +17,10 @@ module Neovim
17
17
  @param [Object] value
18
18
  @return [Object]
19
19
 
20
+ @method del_var(name)
21
+ @param [String] name
22
+ @return [Object]
23
+
20
24
  @method get_window
21
25
  @return [Window]
22
26
 
@@ -1,3 +1,3 @@
1
1
  module Neovim
2
- VERSION = Gem::Version.new("0.2.0")
2
+ VERSION = Gem::Version.new("0.2.1")
3
3
  end
data/lib/neovim/window.rb CHANGED
@@ -99,6 +99,10 @@ module Neovim
99
99
  @param [Object] value
100
100
  @return [Object]
101
101
 
102
+ @method del_var(name)
103
+ @param [String] name
104
+ @return [Object]
105
+
102
106
  @method get_option(name)
103
107
  @param [String] name
104
108
  @return [Object]
data/neovim.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^spec/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_dependency "msgpack", "~> 0.7"
20
+ spec.add_dependency "msgpack", "~> 1.0"
21
21
 
22
22
  spec.add_development_dependency "bundler"
23
23
  spec.add_development_dependency "rake"
@@ -28,7 +28,7 @@ RSpec.describe "neovim-ruby-host" do
28
28
  end
29
29
  RUBY
30
30
 
31
- nvim = Neovim.attach_child(["nvim", "--headless", "-u", "NONE", "-N", "-n"])
31
+ nvim = Neovim.attach_child(["nvim", "-u", "NONE", "-n"])
32
32
 
33
33
  host_exe = File.expand_path("../../../bin/neovim-ruby-host", __FILE__)
34
34
  nvim.command("let host = rpcstart('#{host_exe}', ['#{plugin1_path}', '#{plugin2_path}'])")
@@ -1,16 +1,22 @@
1
1
  require "helper"
2
2
 
3
3
  RSpec.describe "ruby_provider" do
4
- let(:nvim) do
5
- Neovim.attach_child(["nvim", "--headless", "-u", "NONE", "-N", "-n"])
4
+ let!(:nvim) do
5
+ Neovim.attach_child(["nvim", "-u", "NONE", "-n"])
6
6
  end
7
7
 
8
- before do
8
+ around do |spec|
9
9
  provider_path = Support.file_path("provider.rb")
10
10
  File.write(provider_path, "require 'neovim/ruby_provider'")
11
11
  host_exe = File.expand_path("../../../bin/neovim-ruby-host", __FILE__)
12
12
  nvim.current.buffer.lines = ["line1", "line2"]
13
13
  nvim.command("let host = rpcstart('#{host_exe}', ['#{provider_path}'])")
14
+
15
+ begin
16
+ spec.run
17
+ ensure
18
+ nvim.command("call rpcstop(host) | qa!")
19
+ end
14
20
  end
15
21
 
16
22
  describe "ruby_execute" do
@@ -36,60 +42,6 @@ RSpec.describe "ruby_provider" do
36
42
  }.to change { nvim.current.buffer.lines.to_a }.to(["line"])
37
43
  end
38
44
 
39
- it "exposes VIM::Buffer.current" do
40
- expect {
41
- ruby = "VIM::Buffer.current.lines = ['line']".inspect
42
- nvim.eval("rpcrequest(host, 'ruby_execute', #{ruby})")
43
- }.to change { nvim.current.buffer.lines.to_a }.to(["line"])
44
- end
45
-
46
- it "exposes VIM::Buffer.count" do
47
- ruby = "VIM.set_var('count', VIM::Buffer.count)".inspect
48
- nvim.eval("rpcrequest(host, 'ruby_execute', #{ruby})")
49
- expect(nvim.get_var("count")).to eq(1)
50
-
51
- nvim.command("tabe")
52
-
53
- ruby = "VIM.set_var('count', VIM::Buffer.count)".inspect
54
- nvim.eval("rpcrequest(host, 'ruby_execute', #{ruby})")
55
- expect(nvim.get_var("count")).to eq(2)
56
- end
57
-
58
- it "exposes VIM::Buffer[]" do
59
- expect {
60
- ruby = "VIM::Buffer[0].lines = ['line']".inspect
61
- nvim.eval("rpcrequest(host, 'ruby_execute', #{ruby})")
62
- }.to change { nvim.current.buffer.lines.to_a }.to(["line"])
63
- end
64
-
65
- it "exposes VIM::Window.current" do
66
- nvim.command("vsplit")
67
- expect {
68
- ruby = "VIM::Window.current.width = 12".inspect
69
- nvim.eval("rpcrequest(host, 'ruby_execute', #{ruby})")
70
- }.to change { nvim.current.window.width }.to(12)
71
- end
72
-
73
- it "exposes VIM::Window.count" do
74
- ruby = "VIM.set_var('count', VIM::Window.count)".inspect
75
- nvim.eval("rpcrequest(host, 'ruby_execute', #{ruby})")
76
- expect(nvim.get_var("count")).to eq(1)
77
-
78
- nvim.command("vsplit")
79
-
80
- ruby = "VIM.set_var('count', VIM::Window.count)".inspect
81
- nvim.eval("rpcrequest(host, 'ruby_execute', #{ruby})")
82
- expect(nvim.get_var("count")).to eq(2)
83
- end
84
-
85
- it "exposes VIM::Window[]" do
86
- nvim.command("vsplit")
87
- expect {
88
- ruby = "VIM::Window[0].width = 12".inspect
89
- nvim.eval("rpcrequest(host, 'ruby_execute', #{ruby})")
90
- }.to change { nvim.current.window.width }.to(12)
91
- end
92
-
93
45
  it "persists state between requests" do
94
46
  nvim.eval("rpcrequest(host, 'ruby_execute', 'def foo; VIM.command(\"let g:called = 1\"); end')")
95
47
  expect { nvim.get_var("called") }.to raise_error(/key not found/i)
@@ -125,71 +77,24 @@ RSpec.describe "ruby_provider" do
125
77
  }.to change { nvim.current.buffer.lines.to_a }.to(["line"])
126
78
  end
127
79
 
128
- it "exposes VIM::Buffer.current" do
129
- File.write(script_path, "VIM::Buffer.current.lines = ['line']")
130
-
131
- expect {
132
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
133
- }.to change { nvim.current.buffer.lines.to_a }.to(["line"])
134
- end
135
-
136
- it "exposes VIM::Buffer.count" do
137
- File.write(script_path, "VIM.set_var('count', VIM::Buffer.count)")
138
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
139
- expect(nvim.get_var("count")).to eq(1)
140
-
141
- nvim.command("tabe")
142
-
143
- File.write(script_path, "VIM.set_var('count', VIM::Buffer.count)")
80
+ it "persists state between requests" do
81
+ File.write(script_path, "def foo; VIM.command(\"let g:called = 1\"); end")
144
82
  nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
145
- expect(nvim.get_var("count")).to eq(2)
146
- end
147
-
148
- it "exposes VIM::Buffer[]" do
149
- File.write(script_path, "VIM::Buffer[0].lines = ['line']")
150
-
151
- expect {
152
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
153
- }.to change { nvim.current.buffer.lines.to_a }.to(["line"])
154
- end
155
-
156
- it "exposes VIM::Window.current" do
157
- nvim.command("vsplit")
158
- File.write(script_path, "VIM::Window.current.width = 12")
83
+ expect { nvim.get_var("called") }.to raise_error(/key not found/i)
159
84
 
160
- expect {
161
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
162
- }.to change { nvim.current.window.width }.to(12)
85
+ nvim.eval("rpcrequest(host, 'ruby_execute', 'foo')")
86
+ expect(nvim.get_var("called")).to be(1)
163
87
  end
164
88
 
165
- it "exposes VIM::Window.count" do
166
- File.write(script_path, "VIM.set_var('count', VIM::Window.count)")
167
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
168
- expect(nvim.get_var("count")).to eq(1)
169
-
170
- nvim.command("vsplit")
89
+ it "can run the same file multiple times" do
90
+ nvim.set_var("called", 0)
91
+ File.write(script_path, "VIM.command(\"let g:called += 1\")")
171
92
 
172
- File.write(script_path, "VIM.set_var('count', VIM::Window.count)")
173
93
  nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
174
- expect(nvim.get_var("count")).to eq(2)
175
- end
176
-
177
- it "exposes VIM::Window[]" do
178
- nvim.command("vsplit")
179
- File.write(script_path, "VIM::Window[0].width = 12")
180
-
181
- expect {
182
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
183
- }.to change { nvim.current.window.width }.to(12)
184
- end
94
+ expect(nvim.get_var("called")).to be(1)
185
95
 
186
- it "persists state between requests" do
187
- File.write(script_path, "def foo; VIM.command(\"let g:called = 1\"); end")
188
96
  nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
189
- expect { nvim.get_var("called") }.to raise_error(/key not found/i)
190
-
191
- nvim.eval("rpcrequest(host, 'ruby_execute', 'foo')")
192
- expect(nvim.get_var("called")).to be(1)
97
+ expect(nvim.get_var("called")).to be(2)
193
98
  end
194
99
  end
195
100
 
@@ -201,5 +106,15 @@ RSpec.describe "ruby_provider" do
201
106
  nvim.eval("rpcrequest(host, 'ruby_do_range', 2, 3, '$_.upcase!; 42')")
202
107
  }.to change { nvim.current.buffer.lines.to_a }.to(["a", "B", "C", "d"])
203
108
  end
109
+
110
+ it "handles large amounts of lines" do
111
+ xs = Array.new(6000, "x")
112
+ ys = Array.new(6000, "y")
113
+ nvim.current.buffer.lines = xs
114
+
115
+ expect {
116
+ nvim.eval("rpcrequest(host, 'ruby_do_range', 1, 6000, '$_.succ!')")
117
+ }.to change { nvim.current.buffer.lines.to_a }.to(ys)
118
+ end
204
119
  end
205
120
  end
@@ -2,7 +2,7 @@ require "helper"
2
2
 
3
3
  module Neovim
4
4
  RSpec.describe Buffer do
5
- let(:client) { Neovim.attach_child(["nvim", "--headless", "-n", "-u", "NONE"]) }
5
+ let(:client) { Neovim.attach_child(["nvim", "-n", "-u", "NONE"]) }
6
6
  let(:buffer) { client.current.buffer }
7
7
 
8
8
  describe "#lines" do
@@ -2,7 +2,7 @@ require "helper"
2
2
 
3
3
  module Neovim
4
4
  RSpec.describe LineRange do
5
- let(:client) { Neovim.attach_child(["nvim", "--headless", "-n", "-u", "NONE"]) }
5
+ let(:client) { Neovim.attach_child(["nvim", "-n", "-u", "NONE"]) }
6
6
  let(:buffer) { client.current.buffer }
7
7
  let(:line_range) { LineRange.new(buffer, 0, 3) }
8
8
  let(:sub_range) { LineRange.new(buffer, 1, 2) }
@@ -0,0 +1,34 @@
1
+ require "helper"
2
+ require "neovim/ruby_provider/buffer_ext"
3
+
4
+ module Neovim
5
+ RSpec.describe Buffer do
6
+ let!(:nvim) do
7
+ Neovim.attach_child(["nvim", "-u", "NONE", "-n"]).tap do |nvim|
8
+ stub_const("::VIM", nvim)
9
+ end
10
+ end
11
+
12
+ describe ".current" do
13
+ it "returns the current buffer from the global VIM client" do
14
+ expect(Buffer.current).to eq(nvim.get_current_buffer)
15
+ end
16
+ end
17
+
18
+ describe ".count" do
19
+ it "returns the current buffer count from the global VIM client" do
20
+ expect {
21
+ nvim.command("new")
22
+ }.to change { Buffer.count }.by(1)
23
+ end
24
+ end
25
+
26
+ describe ".[]" do
27
+ it "returns the buffer from the global VIM client at the given index" do
28
+ expect(Buffer[0]).to eq(nvim.get_current_buffer)
29
+ nvim.command("new")
30
+ expect(Buffer[1]).to eq(nvim.get_current_buffer)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ require "helper"
2
+ require "neovim/ruby_provider/window_ext"
3
+
4
+ module Neovim
5
+ RSpec.describe Window do
6
+ let!(:nvim) do
7
+ Neovim.attach_child(["nvim", "-u", "NONE", "-n"]).tap do |nvim|
8
+ stub_const("::VIM", nvim)
9
+ end
10
+ end
11
+
12
+ describe ".current" do
13
+ it "returns the current window from the global VIM client" do
14
+ expect(Window.current).to eq(nvim.get_current_window)
15
+ end
16
+ end
17
+
18
+ describe ".count" do
19
+ it "returns the current window count from the global VIM client" do
20
+ expect {
21
+ nvim.command("new")
22
+ }.to change { Window.count }.by(1)
23
+ end
24
+ end
25
+
26
+ describe ".[]" do
27
+ it "returns the window from the global VIM client at the given index" do
28
+ expect(Window[0]).to eq(nvim.get_current_window)
29
+ nvim.command("tabnew")
30
+ expect(Window[1]).to eq(nvim.get_current_window)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -31,6 +31,12 @@ module Neovim
31
31
  session.request(:vim_set_current_line, large_str)
32
32
  expect(session.request(:vim_get_current_line)).to eq(large_str)
33
33
  end
34
+
35
+ it "fails outside of the main thread" do
36
+ expect {
37
+ Thread.new { session.request(:vim_strwidth, "foo") }.join
38
+ }.to raise_error(/outside of the main thread/)
39
+ end
34
40
  end
35
41
 
36
42
  describe "#notify" do
@@ -49,6 +55,12 @@ module Neovim
49
55
  session.notify(:vim_set_current_line, large_str)
50
56
  expect(session.request(:vim_get_current_line)).to eq(large_str)
51
57
  end
58
+
59
+ it "fails outside of the main thread" do
60
+ expect {
61
+ Thread.new { session.notify(:vim_set_current_line, "foo") }.join
62
+ }.to raise_error(/outside of the main thread/)
63
+ end
52
64
  end
53
65
 
54
66
  describe "#run" do
@@ -87,7 +99,7 @@ module Neovim
87
99
  let!(:nvim_pid) do
88
100
  pid = Process.spawn(
89
101
  {"NVIM_LISTEN_ADDRESS" => "0.0.0.0:#{nvim_port}"},
90
- "nvim --headless -n -u NONE",
102
+ "nvim --embed -n -u NONE",
91
103
  [:out, :err] => "/dev/null"
92
104
  )
93
105
 
@@ -105,7 +117,7 @@ module Neovim
105
117
  Process.waitpid(nvim_pid)
106
118
  end
107
119
 
108
- let(:session) { Session.tcp("0.0.0.0", nvim_port) }
120
+ let!(:session) { Session.tcp("0.0.0.0", nvim_port) }
109
121
  include_context "session behavior"
110
122
  end
111
123
 
@@ -114,7 +126,7 @@ module Neovim
114
126
  let!(:nvim_pid) do
115
127
  pid = Process.spawn(
116
128
  {"NVIM_LISTEN_ADDRESS" => socket_path},
117
- "nvim --headless -n -u NONE",
129
+ "nvim --embed -n -u NONE",
118
130
  [:out, :err] => "/dev/null"
119
131
  )
120
132
 
@@ -132,12 +144,12 @@ module Neovim
132
144
  Process.waitpid(nvim_pid)
133
145
  end
134
146
 
135
- let(:session) { Session.unix(socket_path) }
147
+ let!(:session) { Session.unix(socket_path) }
136
148
  include_context "session behavior"
137
149
  end
138
150
 
139
151
  context "child" do
140
- let(:session) { Session.child(["nvim", "-n", "-u", "NONE"]) }
152
+ let!(:session) { Session.child(["nvim", "-n", "-u", "NONE"]) }
141
153
  include_context "session behavior"
142
154
  end
143
155
  end
@@ -2,7 +2,7 @@ require "helper"
2
2
 
3
3
  module Neovim
4
4
  RSpec.describe Window do
5
- let(:client) { Neovim.attach_child(["nvim", "--headless", "-n", "-u", "NONE"]) }
5
+ let(:client) { Neovim.attach_child(["nvim", "-n", "-u", "NONE"]) }
6
6
  let(:window) { client.current.window }
7
7
 
8
8
  describe "if_ruby compatibility" do
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 --headless -u NONE -i NONE -N -n) }
4
+ let(:nvim_argv) { %w(nvim --embed -u NONE -i NONE -n) }
5
5
 
6
6
  describe ".attach_tcp" do
7
7
  it "attaches to a TCP socket" do
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neovim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
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-08 00:00:00.000000000 Z
11
+ date: 2016-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.7'
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.7'
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '3.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.0'
83
83
  description:
@@ -88,9 +88,9 @@ executables:
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
- - .coveralls.yml
92
- - .gitignore
93
- - .travis.yml
91
+ - ".coveralls.yml"
92
+ - ".gitignore"
93
+ - ".travis.yml"
94
94
  - CHANGELOG.md
95
95
  - Gemfile
96
96
  - LICENSE.txt
@@ -118,6 +118,9 @@ files:
118
118
  - lib/neovim/remote_object.rb
119
119
  - lib/neovim/request.rb
120
120
  - lib/neovim/ruby_provider.rb
121
+ - lib/neovim/ruby_provider/buffer_ext.rb
122
+ - lib/neovim/ruby_provider/vim.rb
123
+ - lib/neovim/ruby_provider/window_ext.rb
121
124
  - lib/neovim/session.rb
122
125
  - lib/neovim/tabpage.rb
123
126
  - lib/neovim/version.rb
@@ -138,6 +141,8 @@ files:
138
141
  - spec/neovim/msgpack_stream_spec.rb
139
142
  - spec/neovim/plugin_spec.rb
140
143
  - spec/neovim/remote_object_spec.rb
144
+ - spec/neovim/ruby_provider/buffer_ext_spec.rb
145
+ - spec/neovim/ruby_provider/window_ext_spec.rb
141
146
  - spec/neovim/session_spec.rb
142
147
  - spec/neovim/window_spec.rb
143
148
  - spec/neovim_spec.rb
@@ -152,17 +157,17 @@ require_paths:
152
157
  - lib
153
158
  required_ruby_version: !ruby/object:Gem::Requirement
154
159
  requirements:
155
- - - '>='
160
+ - - ">="
156
161
  - !ruby/object:Gem::Version
157
162
  version: '0'
158
163
  required_rubygems_version: !ruby/object:Gem::Requirement
159
164
  requirements:
160
- - - '>='
165
+ - - ">="
161
166
  - !ruby/object:Gem::Version
162
167
  version: '0'
163
168
  requirements: []
164
169
  rubyforge_project:
165
- rubygems_version: 2.0.14.1
170
+ rubygems_version: 2.4.5
166
171
  signing_key:
167
172
  specification_version: 4
168
173
  summary: A Ruby client for Neovim
@@ -182,6 +187,8 @@ test_files:
182
187
  - spec/neovim/msgpack_stream_spec.rb
183
188
  - spec/neovim/plugin_spec.rb
184
189
  - spec/neovim/remote_object_spec.rb
190
+ - spec/neovim/ruby_provider/buffer_ext_spec.rb
191
+ - spec/neovim/ruby_provider/window_ext_spec.rb
185
192
  - spec/neovim/session_spec.rb
186
193
  - spec/neovim/window_spec.rb
187
194
  - spec/neovim_spec.rb