neovim 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +1 -1
  5. data/CHANGELOG.md +6 -0
  6. data/Rakefile +14 -3
  7. data/lib/neovim.rb +10 -1
  8. data/lib/neovim/buffer.rb +2 -0
  9. data/lib/neovim/client.rb +2 -0
  10. data/lib/neovim/executable.rb +33 -0
  11. data/lib/neovim/ruby_provider.rb +32 -58
  12. data/lib/neovim/ruby_provider/vim.rb +15 -1
  13. data/lib/neovim/tabpage.rb +3 -0
  14. data/lib/neovim/version.rb +1 -1
  15. data/lib/neovim/window.rb +3 -0
  16. data/script/acceptance_tests +46 -0
  17. data/script/generate_docs +8 -1
  18. data/spec/acceptance/rplugin_spec.vim +19 -0
  19. data/spec/acceptance/ruby_spec.vim +94 -0
  20. data/spec/acceptance/rubydo_spec.vim +66 -0
  21. data/spec/acceptance/rubyfile/call_foo.rb +1 -0
  22. data/spec/acceptance/rubyfile/curbuf.rb +1 -0
  23. data/spec/acceptance/rubyfile/curbuf_ivar_get.rb +1 -0
  24. data/spec/acceptance/rubyfile/curbuf_ivar_set.rb +1 -0
  25. data/spec/acceptance/rubyfile/curwin.rb +1 -0
  26. data/spec/acceptance/rubyfile/define_foo.rb +3 -0
  27. data/spec/acceptance/rubyfile/raise_standard_error.rb +1 -0
  28. data/spec/acceptance/rubyfile/raise_syntax_error.rb +1 -0
  29. data/spec/acceptance/rubyfile/set_pwd_after.rb +1 -0
  30. data/spec/acceptance/rubyfile/set_pwd_before.rb +1 -0
  31. data/spec/acceptance/rubyfile/vim_constants.rb +2 -0
  32. data/spec/acceptance/rubyfile_spec.vim +111 -0
  33. data/spec/acceptance/runtime/init.vim +1 -0
  34. data/spec/acceptance/runtime/rplugin/ruby/plugin.rb +13 -0
  35. data/spec/documentation_spec.rb +24 -0
  36. data/spec/helper.rb +20 -45
  37. data/spec/neovim/executable_spec.rb +32 -0
  38. data/spec/neovim/host_spec.rb +2 -2
  39. data/spec/neovim/ruby_provider/vim_spec.rb +38 -0
  40. data/spec/neovim_spec.rb +6 -0
  41. data/spec/support.rb +45 -0
  42. metadata +46 -7
  43. data/spec/acceptance/neovim-ruby-host_spec.rb +0 -69
  44. data/spec/acceptance/ruby_provider_spec.rb +0 -256
@@ -53,4 +53,10 @@ RSpec.describe Neovim do
53
53
  end
54
54
  end
55
55
  end
56
+
57
+ describe ".executable" do
58
+ it "returns the current executable" do
59
+ expect(Neovim.executable).to be_a(Neovim::Executable)
60
+ end
61
+ end
56
62
  end
@@ -0,0 +1,45 @@
1
+ module Support
2
+ class << self
3
+ attr_accessor :nvim_version
4
+ end
5
+
6
+ def self.workspace
7
+ File.expand_path("../workspace", __FILE__)
8
+ end
9
+
10
+ def self.socket_path
11
+ file_path("nvim.sock")
12
+ end
13
+
14
+ def self.tcp_port
15
+ server = TCPServer.new("127.0.0.1", 0)
16
+
17
+ begin
18
+ server.addr[1]
19
+ ensure
20
+ server.close
21
+ end
22
+ end
23
+
24
+ def self.file_path(name)
25
+ File.join(workspace, name)
26
+ end
27
+
28
+ def self.setup_workspace
29
+ FileUtils.mkdir_p(workspace)
30
+ end
31
+
32
+ def self.teardown_workspace
33
+ FileUtils.rm_rf(workspace)
34
+ end
35
+
36
+ def self.child_argv
37
+ [Neovim.executable.path, "--headless", "-i", "NONE", "-u", "NONE", "-n"]
38
+ end
39
+
40
+ begin
41
+ self.nvim_version = Neovim.executable.version
42
+ rescue => e
43
+ abort("Failed to load nvim: #{e}")
44
+ end
45
+ 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.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Genco
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-21 00:00:00.000000000 Z
11
+ date: 2017-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -90,6 +90,7 @@ extra_rdoc_files: []
90
90
  files:
91
91
  - ".coveralls.yml"
92
92
  - ".gitignore"
93
+ - ".gitmodules"
93
94
  - ".travis.yml"
94
95
  - CHANGELOG.md
95
96
  - Gemfile
@@ -101,6 +102,7 @@ files:
101
102
  - lib/neovim/buffer.rb
102
103
  - lib/neovim/client.rb
103
104
  - lib/neovim/current.rb
105
+ - lib/neovim/executable.rb
104
106
  - lib/neovim/host.rb
105
107
  - lib/neovim/host/loader.rb
106
108
  - lib/neovim/line_range.rb
@@ -124,16 +126,34 @@ files:
124
126
  - lib/neovim/version.rb
125
127
  - lib/neovim/window.rb
126
128
  - neovim.gemspec
129
+ - script/acceptance_tests
127
130
  - script/dump_api
128
131
  - script/generate_docs
129
132
  - script/j2mp
130
133
  - script/mp2j
131
- - spec/acceptance/neovim-ruby-host_spec.rb
132
- - spec/acceptance/ruby_provider_spec.rb
134
+ - spec/acceptance/rplugin_spec.vim
135
+ - spec/acceptance/ruby_spec.vim
136
+ - spec/acceptance/rubydo_spec.vim
137
+ - spec/acceptance/rubyfile/call_foo.rb
138
+ - spec/acceptance/rubyfile/curbuf.rb
139
+ - spec/acceptance/rubyfile/curbuf_ivar_get.rb
140
+ - spec/acceptance/rubyfile/curbuf_ivar_set.rb
141
+ - spec/acceptance/rubyfile/curwin.rb
142
+ - spec/acceptance/rubyfile/define_foo.rb
143
+ - spec/acceptance/rubyfile/raise_standard_error.rb
144
+ - spec/acceptance/rubyfile/raise_syntax_error.rb
145
+ - spec/acceptance/rubyfile/set_pwd_after.rb
146
+ - spec/acceptance/rubyfile/set_pwd_before.rb
147
+ - spec/acceptance/rubyfile/vim_constants.rb
148
+ - spec/acceptance/rubyfile_spec.vim
149
+ - spec/acceptance/runtime/init.vim
150
+ - spec/acceptance/runtime/rplugin/ruby/plugin.rb
151
+ - spec/documentation_spec.rb
133
152
  - spec/helper.rb
134
153
  - spec/neovim/buffer_spec.rb
135
154
  - spec/neovim/client_spec.rb
136
155
  - spec/neovim/current_spec.rb
156
+ - spec/neovim/executable_spec.rb
137
157
  - spec/neovim/host/loader_spec.rb
138
158
  - spec/neovim/host_spec.rb
139
159
  - spec/neovim/line_range_spec.rb
@@ -152,6 +172,7 @@ files:
152
172
  - spec/neovim/session_spec.rb
153
173
  - spec/neovim/window_spec.rb
154
174
  - spec/neovim_spec.rb
175
+ - spec/support.rb
155
176
  homepage: https://github.com/alexgenco/neovim-ruby
156
177
  licenses:
157
178
  - MIT
@@ -172,17 +193,34 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
193
  version: '0'
173
194
  requirements: []
174
195
  rubyforge_project:
175
- rubygems_version: 2.6.8
196
+ rubygems_version: 2.6.11
176
197
  signing_key:
177
198
  specification_version: 4
178
199
  summary: A Ruby client for Neovim
179
200
  test_files:
180
- - spec/acceptance/neovim-ruby-host_spec.rb
181
- - spec/acceptance/ruby_provider_spec.rb
201
+ - spec/acceptance/rplugin_spec.vim
202
+ - spec/acceptance/ruby_spec.vim
203
+ - spec/acceptance/rubydo_spec.vim
204
+ - spec/acceptance/rubyfile/call_foo.rb
205
+ - spec/acceptance/rubyfile/curbuf.rb
206
+ - spec/acceptance/rubyfile/curbuf_ivar_get.rb
207
+ - spec/acceptance/rubyfile/curbuf_ivar_set.rb
208
+ - spec/acceptance/rubyfile/curwin.rb
209
+ - spec/acceptance/rubyfile/define_foo.rb
210
+ - spec/acceptance/rubyfile/raise_standard_error.rb
211
+ - spec/acceptance/rubyfile/raise_syntax_error.rb
212
+ - spec/acceptance/rubyfile/set_pwd_after.rb
213
+ - spec/acceptance/rubyfile/set_pwd_before.rb
214
+ - spec/acceptance/rubyfile/vim_constants.rb
215
+ - spec/acceptance/rubyfile_spec.vim
216
+ - spec/acceptance/runtime/init.vim
217
+ - spec/acceptance/runtime/rplugin/ruby/plugin.rb
218
+ - spec/documentation_spec.rb
182
219
  - spec/helper.rb
183
220
  - spec/neovim/buffer_spec.rb
184
221
  - spec/neovim/client_spec.rb
185
222
  - spec/neovim/current_spec.rb
223
+ - spec/neovim/executable_spec.rb
186
224
  - spec/neovim/host/loader_spec.rb
187
225
  - spec/neovim/host_spec.rb
188
226
  - spec/neovim/line_range_spec.rb
@@ -201,3 +239,4 @@ test_files:
201
239
  - spec/neovim/session_spec.rb
202
240
  - spec/neovim/window_spec.rb
203
241
  - spec/neovim_spec.rb
242
+ - spec/support.rb
@@ -1,69 +0,0 @@
1
- require "helper"
2
- require "pty"
3
-
4
- RSpec.describe "neovim-ruby-host" do
5
- let(:host_exe) do
6
- File.expand_path("../../../bin/neovim-ruby-host", __FILE__)
7
- end
8
-
9
- it "prints the gem version" do
10
- ["--version", "-V"].each do |opt|
11
- expect {
12
- system(host_exe, opt)
13
- }.to output("#{Neovim::VERSION}\n").to_stdout_from_any_process
14
- end
15
- end
16
-
17
- it "fails when attached to a TTY" do
18
- PTY.spawn(host_exe) do |rd, wr, pid|
19
- expect(rd.gets).to match(/can't run.+interactively/i)
20
-
21
- _, status = Process.waitpid2(pid)
22
- expect(status.exitstatus).to be(1)
23
- end
24
- end
25
-
26
- it "loads and runs plugins from Ruby source files" do
27
- plugin_path = Support.file_path("plugin1.rb")
28
- File.write(plugin_path, <<-RUBY)
29
- Neovim.plugin do |plug|
30
- plug.command(:AsyncSetLine, :args => 1) do |nvim, str|
31
- nvim.current.line = str
32
- end
33
-
34
- plug.function(:SyncAdd, :args => 2, :sync => true) do |nvim, x, y|
35
- x + y
36
- end
37
-
38
- plug.autocmd(:BufEnter, :pattern => "*.rb") do |nvim|
39
- nvim.current.line = "Ruby file, eh?"
40
- end
41
- end
42
- RUBY
43
-
44
- nvim = Neovim.attach_child(Support.child_argv)
45
-
46
- nvim.command("let host = rpcstart('#{host_exe}', ['#{plugin_path}'])")
47
-
48
- expect(nvim.eval("rpcrequest(host, 'poll')")).to eq("ok")
49
- expect(nvim.eval("rpcrequest(host, '#{plugin_path}:function:SyncAdd', [1, 2])")).to eq(3)
50
-
51
- expect {
52
- nvim.command("call rpcnotify(host, '#{plugin_path}:autocmd:BufEnter:*.rb')")
53
- sleep 0.01
54
- }.to change { nvim.current.buffer.lines.to_a }.from([""]).to(["Ruby file, eh?"])
55
-
56
- expect {
57
- nvim.command("call rpcnotify(host, '#{plugin_path}:command:AsyncSetLine', ['foo'])")
58
- sleep 0.01
59
- }.to change { nvim.current.buffer.lines.to_a }.from(["Ruby file, eh?"]).to(["foo"])
60
-
61
- expect {
62
- nvim.command("call rpcnotify(host, 'Unknown')")
63
- }.not_to raise_error
64
-
65
- expect {
66
- nvim.command("call rpcrequest(host, 'Unknown')")
67
- }.to raise_error(ArgumentError)
68
- end
69
- end
@@ -1,256 +0,0 @@
1
- require "helper"
2
-
3
- RSpec.describe "ruby_provider" do
4
- let!(:nvim) do
5
- Neovim.attach_child(Support.child_argv)
6
- end
7
-
8
- around do |spec|
9
- provider_path = Support.file_path("provider.rb")
10
- File.write(provider_path, "require 'neovim/ruby_provider'")
11
- host_exe = File.expand_path("../../../bin/neovim-ruby-host", __FILE__)
12
- nvim.current.buffer.lines = ["line1", "line2"]
13
- nvim.command("let host = rpcstart('#{host_exe}', ['#{provider_path}'])")
14
-
15
- begin
16
- spec.run
17
- ensure
18
- nvim.shutdown
19
- end
20
- end
21
-
22
- describe "ruby_execute" do
23
- it "exposes the VIM constant" do
24
- ruby = "VIM.equal?(Vim) || raise".inspect
25
- nvim.eval("rpcrequest(host, 'ruby_execute', #{ruby})")
26
- end
27
-
28
- it "exposes the $curwin variable" do
29
- nvim.command("vsplit")
30
-
31
- expect {
32
- ruby = "$curwin.width -= 1".inspect
33
- nvim.eval("rpcrequest(host, 'ruby_execute', #{ruby})")
34
- }.to change { nvim.current.window.width }.by(-1)
35
- end
36
-
37
- it "exposes the $curbuf variable" do
38
- expect {
39
- ruby = "$curbuf.lines = ['line']".inspect
40
- nvim.eval("rpcrequest(host, 'ruby_execute', #{ruby})")
41
- }.to change { nvim.current.buffer.lines.to_a }.to(["line"])
42
- end
43
-
44
- it "persists state between requests" do
45
- nvim.eval("rpcrequest(host, 'ruby_execute', 'def foo; Vim.command(\"let g:called = 1\"); end')")
46
- expect { nvim.get_var("called") }.to raise_error(/key not found/i)
47
-
48
- nvim.eval("rpcrequest(host, 'ruby_execute', 'foo')")
49
- expect(nvim.get_var("called")).to be(1)
50
- end
51
-
52
- it "persists instance state in $curbuf" do
53
- nvim.eval("rpcrequest(host, 'ruby_execute', '$curbuf.instance_variable_set(:@foo, 123)')")
54
- nvim.eval("rpcrequest(host, 'ruby_execute', 'Vim.command(\"let g:foo = \#{$curbuf.instance_variable_get(:@foo)}\")')")
55
-
56
- expect(nvim.get_var("foo")).to be(123)
57
- end
58
-
59
- it "handles explicit directory changes" do
60
- expect {
61
- nvim.command("cd /")
62
- }.to change {
63
- nvim.command_output("call rpcrequest(host, 'ruby_execute', 'puts Dir.pwd')").strip
64
- }.from(Dir.pwd).to("/")
65
- end
66
-
67
- it "handles implicit directory changes" do
68
- expect {
69
- nvim.command("split | lcd / | wincmd p")
70
- }.not_to change {
71
- nvim.command_output("call rpcrequest(host, 'ruby_execute', 'puts Dir.pwd')").strip
72
- }.from(Dir.pwd)
73
- end
74
-
75
- it "handles standard errors" do
76
- expect {
77
- nvim.eval("rpcrequest(host, 'ruby_execute', 'raise')")
78
- }.to raise_error(ArgumentError)
79
-
80
- expect {
81
- nvim.eval("rpcrequest(host, 'ruby_execute', '12')")
82
- }.not_to raise_error
83
- end
84
-
85
- it "handles syntax errors" do
86
- expect {
87
- nvim.eval("rpcrequest(host, 'ruby_execute', 'puts[')")
88
- }.to raise_error(ArgumentError)
89
-
90
- expect {
91
- nvim.eval("rpcrequest(host, 'ruby_execute', '12')")
92
- }.not_to raise_error
93
- end
94
- end
95
-
96
- describe "ruby_execute_file" do
97
- let(:script_path) { Support.file_path("script.rb") }
98
-
99
- it "exposes the VIM constant" do
100
- File.write(script_path, "VIM.equal?(Vim) || raise")
101
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
102
- end
103
-
104
- it "runs ruby from a file" do
105
- File.write(script_path, "Vim.command('let myvar = [1, 2]')")
106
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
107
- expect(nvim.eval("g:myvar")).to eq([1, 2])
108
- end
109
-
110
- it "exposes the $curwin variable" do
111
- File.write(script_path, "$curwin.width -= 1")
112
- nvim.command("vsplit")
113
-
114
- expect {
115
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
116
- }.to change { nvim.current.window.width }.by(-1)
117
- end
118
-
119
- it "exposes the $curbuf variable" do
120
- File.write(script_path, "$curbuf.lines = ['line']")
121
-
122
- expect {
123
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
124
- }.to change { nvim.current.buffer.lines.to_a }.to(["line"])
125
- end
126
-
127
- it "persists state between requests" do
128
- File.write(script_path, "def foo; Vim.command(\"let g:called = 1\"); end")
129
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
130
- expect { nvim.get_var("called") }.to raise_error(/key not found/i)
131
-
132
- nvim.eval("rpcrequest(host, 'ruby_execute', 'foo')")
133
- expect(nvim.get_var("called")).to be(1)
134
- end
135
-
136
- it "can run the same file multiple times" do
137
- nvim.set_var("called", 0)
138
- File.write(script_path, "Vim.command(\"let g:called += 1\")")
139
-
140
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
141
- expect(nvim.get_var("called")).to be(1)
142
-
143
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
144
- expect(nvim.get_var("called")).to be(2)
145
- end
146
-
147
- it "persists instance state in $curbuf" do
148
- File.write(script_path, <<-RUBY)
149
- def $curbuf.foo
150
- @foo ||= 0
151
- @foo += 1
152
- end
153
-
154
- Vim.command("let g:foo = \#{$curbuf.foo}")
155
- RUBY
156
-
157
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
158
- expect(nvim.get_var("foo")).to be(1)
159
-
160
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
161
- expect(nvim.get_var("foo")).to be(2)
162
- end
163
-
164
- it "handles explicit directory changes" do
165
- File.write(script_path, "puts Dir.pwd")
166
-
167
- expect {
168
- nvim.command("cd /")
169
- }.to change {
170
- nvim.command_output("call rpcrequest(host, 'ruby_execute_file', '#{script_path}')").strip
171
- }.from(Dir.pwd).to("/")
172
- end
173
-
174
- it "handles implicit directory changes" do
175
- File.write(script_path, "puts Dir.pwd")
176
-
177
- expect {
178
- nvim.command("split | lcd / | wincmd p")
179
- }.not_to change {
180
- nvim.command_output("call rpcrequest(host, 'ruby_execute_file', '#{script_path}')").strip
181
- }.from(Dir.pwd)
182
- end
183
-
184
- it "handles standard errors" do
185
- File.write(script_path, "raise")
186
-
187
- expect {
188
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
189
- }.to raise_error(ArgumentError)
190
-
191
- File.write(script_path, "12")
192
-
193
- expect {
194
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
195
- }.not_to raise_error
196
- end
197
-
198
- it "handles syntax errors" do
199
- File.write(script_path, "puts[")
200
-
201
- expect {
202
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
203
- }.to raise_error(ArgumentError)
204
-
205
- File.write(script_path, "12")
206
-
207
- expect {
208
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
209
- }.not_to raise_error
210
- end
211
- end
212
-
213
- describe "ruby_do_range" do
214
- it "mutates lines via the $_ variable" do
215
- nvim.current.buffer.lines = ["a", "b", "c", "d"]
216
-
217
- expect {
218
- nvim.eval("rpcrequest(host, 'ruby_do_range', 2, 3, '$_.upcase!; 42')")
219
- }.to change { nvim.current.buffer.lines.to_a }.to(["a", "B", "C", "d"])
220
- end
221
-
222
- it "handles large amounts of lines" do
223
- xs = Array.new(6000, "x")
224
- ys = Array.new(6000, "y")
225
- nvim.current.buffer.lines = xs
226
-
227
- expect {
228
- nvim.eval("rpcrequest(host, 'ruby_do_range', 1, 6000, '$_.succ!')")
229
- }.to change { nvim.current.buffer.lines.to_a }.to(ys)
230
- end
231
-
232
- it "handles standard errors" do
233
- nvim.current.buffer.lines = ["a", "b"]
234
-
235
- expect {
236
- nvim.eval("rpcrequest(host, 'ruby_do_range', 1, 1, 'raise')")
237
- }.to raise_error(ArgumentError)
238
-
239
- expect {
240
- nvim.eval("rpcrequest(host, 'ruby_do_range', 1, 1, '12')")
241
- }.not_to raise_error
242
- end
243
-
244
- it "handles syntax errors" do
245
- nvim.current.buffer.lines = ["a", "b"]
246
-
247
- expect {
248
- nvim.eval("rpcrequest(host, 'ruby_do_range', 1, 1, 'puts[')")
249
- }.to raise_error(ArgumentError)
250
-
251
- expect {
252
- nvim.eval("rpcrequest(host, 'ruby_do_range', 1, 1, '12')")
253
- }.not_to raise_error
254
- end
255
- end
256
- end