neovim 0.4.0 → 0.5.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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.gitmodules +1 -1
  4. data/.rspec +1 -0
  5. data/.travis.yml +1 -1
  6. data/CHANGELOG.md +8 -0
  7. data/README.md +5 -3
  8. data/Rakefile +14 -8
  9. data/lib/neovim/buffer.rb +86 -114
  10. data/lib/neovim/client.rb +105 -103
  11. data/lib/neovim/current.rb +8 -18
  12. data/lib/neovim/executable.rb +2 -2
  13. data/lib/neovim/line_range.rb +48 -59
  14. data/lib/neovim/plugin/dsl.rb +11 -3
  15. data/lib/neovim/remote_object.rb +3 -13
  16. data/lib/neovim/ruby_provider.rb +3 -3
  17. data/lib/neovim/ruby_provider/buffer_ext.rb +3 -3
  18. data/lib/neovim/ruby_provider/vim.rb +2 -2
  19. data/lib/neovim/ruby_provider/window_ext.rb +3 -3
  20. data/lib/neovim/session.rb +4 -4
  21. data/lib/neovim/session/api.rb +50 -22
  22. data/lib/neovim/tabpage.rb +29 -19
  23. data/lib/neovim/version.rb +1 -1
  24. data/lib/neovim/window.rb +60 -40
  25. data/script/dump_api +1 -1
  26. data/script/generate_docs +35 -22
  27. data/spec/helper.rb +3 -1
  28. data/spec/integration/rplugin_autocmd_spec.vim +18 -0
  29. data/spec/integration/rplugin_command_spec.vim +97 -0
  30. data/spec/integration/rplugin_function_spec.vim +26 -0
  31. data/spec/integration/ruby_buffer_spec.rb +151 -0
  32. data/spec/{acceptance → integration}/ruby_spec.vim +2 -22
  33. data/spec/integration/ruby_vim_spec.rb +27 -0
  34. data/spec/integration/ruby_window_spec.rb +56 -0
  35. data/spec/{acceptance → integration}/rubydo_spec.vim +27 -18
  36. data/spec/{acceptance → integration}/rubyfile/call_foo.rb +0 -0
  37. data/spec/{acceptance → integration}/rubyfile/curbuf_ivar_get.rb +0 -0
  38. data/spec/{acceptance → integration}/rubyfile/curbuf_ivar_set.rb +0 -0
  39. data/spec/{acceptance → integration}/rubyfile/define_foo.rb +0 -0
  40. data/spec/{acceptance → integration}/rubyfile/raise_standard_error.rb +0 -0
  41. data/spec/{acceptance → integration}/rubyfile/raise_syntax_error.rb +0 -0
  42. data/spec/{acceptance → integration}/rubyfile/set_pwd_after.rb +0 -0
  43. data/spec/{acceptance → integration}/rubyfile/set_pwd_before.rb +0 -0
  44. data/spec/{acceptance → integration}/rubyfile_spec.vim +12 -30
  45. data/spec/integration/runtime/init.vim +9 -0
  46. data/spec/integration/runtime/rplugin/ruby/autocmds.rb +9 -0
  47. data/spec/integration/runtime/rplugin/ruby/commands.rb +59 -0
  48. data/spec/integration/runtime/rplugin/ruby/functions.rb +17 -0
  49. data/spec/integration_spec.rb +119 -0
  50. data/spec/neovim/buffer_spec.rb +0 -167
  51. data/spec/neovim/client_spec.rb +1 -44
  52. data/spec/neovim/current_spec.rb +0 -8
  53. data/spec/neovim/line_range_spec.rb +92 -97
  54. data/spec/neovim/plugin_spec.rb +14 -2
  55. data/spec/neovim/remote_object_spec.rb +4 -4
  56. data/spec/neovim/ruby_provider/buffer_ext_spec.rb +3 -3
  57. data/spec/neovim/ruby_provider/window_ext_spec.rb +1 -1
  58. data/spec/neovim/session/api_spec.rb +40 -35
  59. data/spec/neovim/session/event_loop_spec.rb +1 -1
  60. data/spec/neovim/session_spec.rb +15 -15
  61. metadata +49 -41
  62. data/script/acceptance_tests +0 -46
  63. data/spec/acceptance/rplugin_spec.vim +0 -19
  64. data/spec/acceptance/rubyfile/curbuf.rb +0 -1
  65. data/spec/acceptance/rubyfile/curwin.rb +0 -1
  66. data/spec/acceptance/rubyfile/vim_constants.rb +0 -2
  67. data/spec/acceptance/runtime/init.vim +0 -1
  68. data/spec/acceptance/runtime/rplugin/ruby/plugin.rb +0 -13
  69. data/spec/documentation_spec.rb +0 -24
  70. data/spec/neovim/window_spec.rb +0 -91
@@ -135,13 +135,5 @@ module Neovim
135
135
  expect(current.tabpage = tp0).to eq(tp0)
136
136
  end
137
137
  end
138
-
139
- describe "#range=" do
140
- it "sets the line range of the current buffer" do
141
- current.buffer.lines = ["one", "two", "three", "four"]
142
- current.range = (1..2)
143
- expect(current.buffer.range.to_a).to eq(["two", "three"])
144
- end
145
- end
146
138
  end
147
139
  end
@@ -4,21 +4,31 @@ module Neovim
4
4
  RSpec.describe LineRange do
5
5
  let(:client) { Neovim.attach_child(Support.child_argv) }
6
6
  let(:buffer) { client.current.buffer }
7
- let(:line_range) { LineRange.new(buffer, 0, -1) }
8
- let(:sub_range) { LineRange.new(buffer, 1, 2) }
7
+ let(:line_range) { LineRange.new(buffer) }
9
8
 
10
9
  before do
11
- client.command("normal i1")
12
- client.command("normal o2")
13
- client.command("normal o3")
14
- client.command("normal o4")
10
+ buffer.set_lines(0, -1, true, ["1", "2", "3", "4"])
15
11
  end
16
12
 
17
13
  after { client.shutdown }
18
14
 
19
- it "is enumerable" do
20
- expect(line_range).to be_an(Enumerable)
21
- expect(line_range.each.to_a).to eq(["1", "2", "3", "4"])
15
+ describe "#each" do
16
+ it "yields each line" do
17
+ yielded = []
18
+ line_range.each { |line| yielded << line }
19
+
20
+ expect(yielded).to eq(["1", "2", "3", "4"])
21
+ end
22
+
23
+ it "yields a large number of lines" do
24
+ lines = Array.new(6000, "x")
25
+ buffer.set_lines(0, -1, true, lines)
26
+
27
+ yielded = []
28
+ line_range.each { |line| yielded << line }
29
+
30
+ expect(yielded).to eq(lines)
31
+ end
22
32
  end
23
33
 
24
34
  describe "#to_a" do
@@ -26,82 +36,99 @@ module Neovim
26
36
  expect(line_range.to_a).to eq(["1", "2", "3", "4"])
27
37
  end
28
38
 
29
- it "returns a subset of lines as an array" do
30
- expect(sub_range.to_a).to eq(["2", "3"])
39
+ it "returns a large number of lines as an array" do
40
+ lines = Array.new(6000, "x")
41
+ buffer.set_lines(0, -1, true, lines)
42
+ expect(line_range.to_a).to eq(lines)
31
43
  end
32
44
  end
33
45
 
34
- describe "#[]" do
35
- it "accepts a single index" do
36
- expect(line_range[1]).to eq("2")
37
- end
38
-
39
- it "returns lines at an offset from the index" do
40
- expect(sub_range[0]).to eq("2")
41
- end
46
+ describe "#==" do
47
+ it "compares line contents" do
48
+ client.command("new")
49
+ buffer2 = client.current.buffer
42
50
 
43
- it "allows indexes beyond the bounds of a sub range" do
44
- expect(sub_range[2]).to eq("4")
51
+ expect(buffer2.lines == buffer.lines).to eq(false)
52
+ buffer2.set_lines(0, -1, true, ["1", "2", "3", "4"])
53
+ expect(buffer2.lines == buffer.lines).to eq(true)
45
54
  end
55
+ end
46
56
 
47
- it "returns lines at an offset with a negative index" do
48
- expect(sub_range[-1]).to eq("3")
57
+ describe "#[]" do
58
+ it "accepts a single index" do
59
+ expect(line_range[1]).to eq("2")
60
+ expect(line_range[-1]).to eq("4")
61
+ expect(line_range[-2]).to eq("3")
49
62
  end
50
63
 
51
64
  it "accepts an index and length" do
52
- expect(line_range[0, 2].to_a).to eq(["1", "2"])
53
- end
65
+ expect(line_range[0, 2]).to eq(["1", "2"])
66
+ expect(line_range[-2, 2]).to eq(["3", "4"])
67
+ expect(line_range[-2, 3]).to eq(["3", "4"])
54
68
 
55
- it "returns lines at an offset from an index and length" do
56
- expect(sub_range[0, 2].to_a).to eq(["2", "3"])
69
+ expect {
70
+ line_range[2, 3]
71
+ }.to raise_error(/out of bounds/)
57
72
  end
58
73
 
59
74
  it "accepts a range" do
60
- expect(line_range[0..1].to_a).to eq(["1", "2"])
61
- expect(line_range[0...1].to_a).to eq(["1"])
62
- end
75
+ expect(line_range[0..1]).to eq(["1", "2"])
76
+ expect(line_range[0...1]).to eq(["1"])
63
77
 
64
- it "accepts a range with a negative end" do
65
- expect(line_range[0..-1].to_a).to eq(["1", "2", "3", "4"])
66
- end
78
+ expect(line_range[0..-1]).to eq(["1", "2", "3", "4"])
79
+ expect(line_range[0..-2]).to eq(["1", "2", "3"])
80
+ expect(line_range[-3..-2]).to eq(["2", "3"])
81
+
82
+ expect(line_range[0..-5]).to eq([])
83
+ expect(line_range[0...-4]).to eq([])
84
+ expect(line_range[-2..-3]).to eq([])
67
85
 
68
- it "returns lines at an offset from a range" do
69
- expect(sub_range[0..1].to_a).to eq(["2", "3"])
86
+ expect {
87
+ line_range[2..4]
88
+ }.to raise_error(/out of bounds/)
70
89
  end
71
90
  end
72
91
 
73
92
  describe "#[]=" do
74
93
  it "accepts a single index" do
75
- line_range[0] = "foo"
94
+ expect(line_range[0] = "foo").to eq("foo")
76
95
  expect(line_range.to_a).to eq(["foo", "2", "3", "4"])
77
- end
78
96
 
79
- it "accepts a single index at an offset" do
80
- sub_range[0] = "foo"
81
- expect(buffer.lines.to_a).to eq(["1", "foo", "3", "4"])
97
+ expect(line_range[-1] = "bar").to eq("bar")
98
+ expect(line_range.to_a).to eq(["foo", "2", "3", "bar"])
99
+
100
+ expect {
101
+ line_range[-5] = "foo"
102
+ }.to raise_error(/out of bounds/)
82
103
  end
83
104
 
84
105
  it "accepts an index and length" do
85
- line_range[0, 2] = ["foo"]
106
+ expect(line_range[0, 2] = ["foo"]).to eq(["foo"])
86
107
  expect(line_range.to_a).to eq(["foo", "3", "4"])
87
- end
88
108
 
89
- it "accepts an index and length at an offset" do
90
- sub_range[0, 2] = ["foo"]
91
- expect(buffer.lines.to_a).to eq(["1", "foo", "4"])
109
+ expect(line_range[-2, 2] = ["bar"]).to eq(["bar"])
110
+ expect(line_range.to_a).to eq(["foo", "bar"])
111
+
112
+ expect(line_range[0, 2] = "baz").to eq("baz")
113
+ expect(line_range.to_a).to eq(["baz"])
114
+
115
+ expect {
116
+ line_range[0, 5] = "foo"
117
+ }.to raise_error(/out of bounds/)
92
118
  end
93
119
 
94
120
  it "accepts a range" do
95
- line_range[0..1] = ["foo"]
121
+ expect(line_range[0..1] = ["foo"]).to eq(["foo"])
96
122
  expect(line_range.to_a).to eq(["foo", "3", "4"])
97
123
 
98
- line_range[0...1] = ["bar"]
124
+ expect(line_range[0...1] = ["bar"]).to eq(["bar"])
99
125
  expect(line_range.to_a).to eq(["bar", "3", "4"])
100
- end
101
126
 
102
- it "accepts a range at an offset" do
103
- sub_range[0..1] = ["foo"]
104
- expect(buffer.lines.to_a).to eq(["1", "foo", "4"])
127
+ expect(line_range[0..-2] = ["baz"]).to eq(["baz"])
128
+ expect(line_range.to_a).to eq(["baz", "4"])
129
+
130
+ expect(line_range[0...2] = "qux").to eq("qux")
131
+ expect(line_range.to_a).to eq(["qux"])
105
132
  end
106
133
  end
107
134
 
@@ -110,64 +137,32 @@ module Neovim
110
137
  line_range.replace(["4", "5"])
111
138
  expect(line_range.to_a).to eq(["4", "5"])
112
139
  end
113
-
114
- it "replaces a subset of lines" do
115
- sub_range.replace(["5", "6"])
116
- expect(buffer.lines.to_a).to eq(["1", "5", "6", "4"])
117
- end
118
140
  end
119
141
 
120
- describe "#insert" do
121
- before { line_range.replace(["1", "2"]) }
122
-
123
- it "inserts lines at the beginning" do
124
- expect {
125
- line_range.insert(0, "z")
126
- }.to change { line_range.to_a }.to(["z", "1", "2"])
127
-
128
- expect {
129
- line_range.insert(0, ["x", "y"])
130
- }.to change { line_range.to_a }.to(["x", "y", "z", "1", "2"])
131
- end
132
-
133
- it "inserts lines in the middle" do
134
- expect {
135
- line_range.insert(1, "z")
136
- }.to change { line_range.to_a }.to(["1", "z", "2"])
137
-
138
- expect {
139
- line_range.insert(1, ["x", "y"])
140
- }.to change { line_range.to_a }.to(["1", "x", "y", "z", "2"])
141
- end
142
-
143
- it "inserts lines at the end" do
142
+ describe "#delete" do
143
+ it "deletes the line at the given index" do
144
144
  expect {
145
- line_range.insert(-1, "x")
146
- }.to change { line_range.to_a }.to(["1", "2", "x"])
145
+ line_range.delete(0)
146
+ }.to change { line_range.to_a }.to(["2", "3", "4"])
147
147
 
148
148
  expect {
149
- line_range.insert(-1, ["y", "z"])
150
- }.to change { line_range.to_a }.to(["1", "2", "x", "y", "z"])
151
- end
149
+ line_range.delete(-1)
150
+ }.to change { line_range.to_a }.to(["2", "3"])
152
151
 
153
- it "raises on out of bounds indexes" do
154
152
  expect {
155
- line_range.insert(10, "x")
156
- }.to raise_error(/out of bounds/i)
153
+ line_range.delete(-2)
154
+ }.to change { line_range.to_a }.to(["3"])
157
155
  end
158
- end
159
156
 
160
- describe "#delete" do
161
- it "deletes the line at the given index" do
162
- expect {
163
- line_range.delete(0)
164
- }.to change { line_range.to_a }.to(["2", "3", "4"])
157
+ it "returns the line deleted" do
158
+ expect(line_range.delete(0)).to eq("1")
159
+ expect(line_range.delete(-1)).to eq("4")
165
160
  end
166
161
 
167
- it "deletes the line at an offset" do
162
+ it "returns nil if provided a non-integer" do
168
163
  expect {
169
- sub_range.delete(0)
170
- }.to change { buffer.lines.to_a }.to(["1", "3", "4"])
164
+ expect(line_range.delete(:foo)).to eq(nil)
165
+ }.not_to change { line_range.to_a }
171
166
  end
172
167
  end
173
168
  end
@@ -8,7 +8,14 @@ module Neovim
8
8
  cmd_block = Proc.new {}
9
9
 
10
10
  plugin = Plugin.from_config_block("source") do |plug|
11
- plug.command("Foo", :range => true, :nargs => 1, &cmd_block)
11
+ plug.command(
12
+ "Foo",
13
+ :nargs => 1,
14
+ :range => true,
15
+ :bang => true,
16
+ :register => true,
17
+ &cmd_block
18
+ )
12
19
  end
13
20
 
14
21
  expect(plugin.handlers.size).to be(1)
@@ -22,7 +29,12 @@ module Neovim
22
29
  :type => :command,
23
30
  :name => "Foo",
24
31
  :sync => false,
25
- :opts => {:range => "", :nargs => 1},
32
+ :opts => {
33
+ :nargs => 1,
34
+ :range => "",
35
+ :bang => "",
36
+ :register => "",
37
+ },
26
38
  )
27
39
  end
28
40
 
@@ -23,7 +23,7 @@ module Neovim
23
23
  end
24
24
 
25
25
  describe "#method_missing" do
26
- it "enables window_* function calls" do
26
+ it "enables nvim_win_* function calls" do
27
27
  expect(window.get_cursor).to eq([1, 0])
28
28
  end
29
29
 
@@ -61,7 +61,7 @@ module Neovim
61
61
  end
62
62
 
63
63
  describe "#method_missing" do
64
- it "enables tabpage_* function calls" do
64
+ it "enables nvim_tabpage_* function calls" do
65
65
  expect(tabpage.is_valid).to be(true)
66
66
  end
67
67
  end
@@ -72,7 +72,7 @@ module Neovim
72
72
  end
73
73
 
74
74
  it "returns api methods" do
75
- expect(tabpage.methods).to include(:get_windows)
75
+ expect(tabpage.methods).to include(:list_wins)
76
76
  end
77
77
  end
78
78
  end
@@ -95,7 +95,7 @@ module Neovim
95
95
  end
96
96
 
97
97
  describe "#method_missing" do
98
- it "enables buffer_* function calls" do
98
+ it "enables nvim_buf_* function calls" do
99
99
  expect(buffer.line_count).to be(1)
100
100
  end
101
101
  end
@@ -13,7 +13,7 @@ module Neovim
13
13
 
14
14
  describe ".current" do
15
15
  it "returns the current buffer from the global Vim client" do
16
- expect(Buffer.current).to eq(nvim.get_current_buffer)
16
+ expect(Buffer.current).to eq(nvim.get_current_buf)
17
17
  end
18
18
  end
19
19
 
@@ -27,9 +27,9 @@ module Neovim
27
27
 
28
28
  describe ".[]" do
29
29
  it "returns the buffer from the global Vim client at the given index" do
30
- expect(Buffer[0]).to eq(nvim.get_current_buffer)
30
+ expect(Buffer[0]).to eq(nvim.get_current_buf)
31
31
  nvim.command("new")
32
- expect(Buffer[1]).to eq(nvim.get_current_buffer)
32
+ expect(Buffer[1]).to eq(nvim.get_current_buf)
33
33
  end
34
34
  end
35
35
  end
@@ -13,7 +13,7 @@ module Neovim
13
13
 
14
14
  describe ".current" do
15
15
  it "returns the current window from the global Vim client" do
16
- expect(Window.current).to eq(nvim.get_current_window)
16
+ expect(Window.current).to eq(nvim.get_current_win)
17
17
  end
18
18
  end
19
19
 
@@ -12,52 +12,57 @@ module Neovim
12
12
  end
13
13
  end
14
14
 
15
- describe "#function" do
16
- it "returns a sync function object" do
17
- api = API.new(
18
- [nil, {"functions" => [
19
- {"name" => "vim_sync", "async" => false}
20
- ]}]
21
- )
15
+ let(:client) { Neovim.attach_child(Support.child_argv) }
22
16
 
23
- function = api.function("vim_sync")
24
- expect(function.name).to eq("vim_sync")
25
- expect(function.async).to be(false)
17
+ let(:api) do
18
+ API.new(
19
+ [
20
+ nil,
21
+ {
22
+ "functions" => [
23
+ {"name" => "nvim_func"},
24
+ {"name" => "nvim_buf_func"},
25
+ {"name" => "nvim_win_func"},
26
+ {"name" => "nvim_tabpage_func"},
27
+ ]
28
+ }
29
+ ]
30
+ )
31
+ end
26
32
 
27
- session = instance_double(Session)
28
- expect(session).to receive(:request).with("vim_sync", "msg")
29
- function.call(session, "msg")
30
- end
33
+ describe "#functions_for_object_method" do
34
+ it "returns relevant functions" do
35
+ function = api.function_for_object_method(client, :func)
36
+ expect(function.name).to eq("nvim_func")
31
37
 
32
- it "returns an async function object" do
33
- api = API.new(
34
- [nil, {"functions" => [
35
- {"name" => "vim_async", "async" => true}
36
- ]}]
37
- )
38
+ function = api.function_for_object_method(client.get_current_buf, :func)
39
+ expect(function.name).to eq("nvim_buf_func")
38
40
 
39
- function = api.function("vim_async")
40
- expect(function.name).to eq("vim_async")
41
- expect(function.async).to be(true)
41
+ function = api.function_for_object_method(client.get_current_win, :func)
42
+ expect(function.name).to eq("nvim_win_func")
42
43
 
43
- session = instance_double(Session)
44
- expect(session).to receive(:notify).with("vim_async", "msg")
45
- function.call(session, "msg")
44
+ function = api.function_for_object_method(client.get_current_tabpage, :func)
45
+ expect(function.name).to eq("nvim_tabpage_func")
46
46
  end
47
47
  end
48
48
 
49
- describe "#functions_with_prefix" do
49
+ describe "#functions_for_object" do
50
50
  it "returns relevant functions" do
51
- api = API.new(
52
- [nil, {"functions" => [
53
- {"name" => "vim_strwidth"},
54
- {"name" => "buffer_get_lines"}
55
- ]}]
56
- )
51
+ functions = api.functions_for_object(client)
52
+ expect(functions.size).to be(1)
53
+ expect(functions.first.name).to eq("nvim_func")
54
+
55
+ functions = api.functions_for_object(client.get_current_buf)
56
+ expect(functions.size).to be(1)
57
+ expect(functions.first.name).to eq("nvim_buf_func")
58
+
59
+ functions = api.functions_for_object(client.get_current_win)
60
+ expect(functions.size).to be(1)
61
+ expect(functions.first.name).to eq("nvim_win_func")
57
62
 
58
- functions = api.functions_with_prefix("vim_")
63
+ functions = api.functions_for_object(client.get_current_tabpage)
59
64
  expect(functions.size).to be(1)
60
- expect(functions.first.name).to eq("vim_strwidth")
65
+ expect(functions.first.name).to eq("nvim_tabpage_func")
61
66
  end
62
67
  end
63
68
  end