neovim 0.3.0 → 0.3.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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/Gemfile +1 -0
  4. data/README.md +6 -2
  5. data/Rakefile +4 -72
  6. data/bin/neovim-ruby-host +3 -2
  7. data/lib/neovim.rb +4 -16
  8. data/lib/neovim/buffer.rb +21 -0
  9. data/lib/neovim/client.rb +35 -0
  10. data/lib/neovim/host.rb +6 -4
  11. data/lib/neovim/host/loader.rb +2 -0
  12. data/lib/neovim/line_range.rb +1 -1
  13. data/lib/neovim/logging.rb +8 -7
  14. data/lib/neovim/plugin/dsl.rb +1 -1
  15. data/lib/neovim/ruby_provider.rb +7 -10
  16. data/lib/neovim/ruby_provider/buffer_ext.rb +3 -3
  17. data/lib/neovim/ruby_provider/vim.rb +6 -1
  18. data/lib/neovim/ruby_provider/window_ext.rb +3 -3
  19. data/lib/neovim/session.rb +2 -2
  20. data/lib/neovim/session/api.rb +7 -1
  21. data/lib/neovim/session/event_loop.rb +4 -12
  22. data/lib/neovim/session/serializer.rb +2 -2
  23. data/lib/neovim/tabpage.rb +6 -0
  24. data/lib/neovim/version.rb +1 -1
  25. data/lib/neovim/window.rb +19 -1
  26. data/script/generate_docs +71 -0
  27. data/{bin → script}/j2mp +0 -0
  28. data/{bin → script}/mp2j +0 -0
  29. data/spec/acceptance/neovim-ruby-host_spec.rb +1 -6
  30. data/spec/acceptance/ruby_provider_spec.rb +17 -33
  31. data/spec/helper.rb +42 -37
  32. data/spec/neovim/buffer_spec.rb +1 -1
  33. data/spec/neovim/client_spec.rb +1 -1
  34. data/spec/neovim/current_spec.rb +1 -1
  35. data/spec/neovim/host/loader_spec.rb +2 -0
  36. data/spec/neovim/host_spec.rb +25 -5
  37. data/spec/neovim/line_range_spec.rb +2 -2
  38. data/spec/neovim/logging_spec.rb +56 -0
  39. data/spec/neovim/plugin_spec.rb +9 -0
  40. data/spec/neovim/remote_object_spec.rb +5 -1
  41. data/spec/neovim/ruby_provider/buffer_ext_spec.rb +5 -5
  42. data/spec/neovim/ruby_provider/vim_spec.rb +32 -0
  43. data/spec/neovim/ruby_provider/window_ext_spec.rb +22 -8
  44. data/spec/neovim/session/api_spec.rb +24 -5
  45. data/spec/neovim/session/event_loop_spec.rb +54 -1
  46. data/spec/neovim/session/notification_spec.rb +20 -0
  47. data/spec/neovim/session/request_spec.rb +36 -0
  48. data/spec/neovim/session/rpc_spec.rb +12 -0
  49. data/spec/neovim/session/serializer_spec.rb +14 -0
  50. data/spec/neovim/session_spec.rb +4 -4
  51. data/spec/neovim/window_spec.rb +17 -1
  52. data/spec/neovim_spec.rb +4 -20
  53. metadata +13 -4
File without changes
File without changes
@@ -15,17 +15,12 @@ RSpec.describe "neovim-ruby-host" do
15
15
  end
16
16
 
17
17
  it "fails when attached to a TTY" do
18
- yielded = false
19
-
20
18
  PTY.spawn(host_exe) do |rd, wr, pid|
21
- yielded = true
22
19
  expect(rd.gets).to match(/can't run.+interactively/i)
23
20
 
24
21
  _, status = Process.waitpid2(pid)
25
22
  expect(status.exitstatus).to be(1)
26
23
  end
27
-
28
- expect(yielded).to be(true)
29
24
  end
30
25
 
31
26
  it "loads and runs plugins from Ruby source files" do
@@ -46,7 +41,7 @@ RSpec.describe "neovim-ruby-host" do
46
41
  end
47
42
  RUBY
48
43
 
49
- nvim = Neovim.attach_child(["nvim", "-u", "NONE", "-n"])
44
+ nvim = Neovim.attach_child(Support.child_argv)
50
45
 
51
46
  nvim.command("let host = rpcstart('#{host_exe}', ['#{plugin_path}'])")
52
47
 
@@ -2,7 +2,7 @@ require "helper"
2
2
 
3
3
  RSpec.describe "ruby_provider" do
4
4
  let!(:nvim) do
5
- Neovim.attach_child(["nvim", "-u", "NONE", "-n"])
5
+ Neovim.attach_child(Support.child_argv)
6
6
  end
7
7
 
8
8
  around do |spec|
@@ -15,15 +15,14 @@ RSpec.describe "ruby_provider" do
15
15
  begin
16
16
  spec.run
17
17
  ensure
18
- nvim.session.shutdown
18
+ nvim.shutdown
19
19
  end
20
20
  end
21
21
 
22
22
  describe "ruby_execute" do
23
- it "runs ruby directly" do
24
- ruby = "VIM.command('let myvar = [1, 2]')".inspect
23
+ it "exposes the VIM constant" do
24
+ ruby = "VIM.equal?(Vim) || raise".inspect
25
25
  nvim.eval("rpcrequest(host, 'ruby_execute', #{ruby})")
26
- expect(nvim.eval("g:myvar")).to eq([1, 2])
27
26
  end
28
27
 
29
28
  it "exposes the $curwin variable" do
@@ -43,31 +42,31 @@ RSpec.describe "ruby_provider" do
43
42
  end
44
43
 
45
44
  it "persists state between requests" do
46
- nvim.eval("rpcrequest(host, 'ruby_execute', 'def foo; VIM.command(\"let g:called = 1\"); end')")
45
+ nvim.eval("rpcrequest(host, 'ruby_execute', 'def foo; Vim.command(\"let g:called = 1\"); end')")
47
46
  expect { nvim.get_var("called") }.to raise_error(/key not found/i)
48
47
 
49
48
  nvim.eval("rpcrequest(host, 'ruby_execute', 'foo')")
50
49
  expect(nvim.get_var("called")).to be(1)
51
50
  end
52
51
 
53
- it "persists instance state in globals" do
52
+ it "persists instance state in $curbuf" do
54
53
  nvim.eval("rpcrequest(host, 'ruby_execute', '$curbuf.instance_variable_set(:@foo, 123)')")
55
- nvim.eval("rpcrequest(host, 'ruby_execute', 'VIM.command(\"let g:foo = \#{$curbuf.instance_variable_get(:@foo)}\")')")
54
+ nvim.eval("rpcrequest(host, 'ruby_execute', 'Vim.command(\"let g:foo = \#{$curbuf.instance_variable_get(:@foo)}\")')")
56
55
 
57
56
  expect(nvim.get_var("foo")).to be(123)
58
-
59
- nvim.eval("rpcrequest(host, 'ruby_execute', '$curwin.instance_variable_set(:@bar, 456)')")
60
- nvim.eval("rpcrequest(host, 'ruby_execute', 'VIM.command(\"let g:bar = \#{$curwin.instance_variable_get(:@bar)}\")')")
61
-
62
- expect(nvim.get_var("bar")).to be(456)
63
57
  end
64
58
  end
65
59
 
66
60
  describe "ruby_execute_file" do
67
61
  let(:script_path) { Support.file_path("script.rb") }
68
62
 
63
+ it "exposes the VIM constant" do
64
+ File.write(script_path, "VIM.equal?(Vim) || raise")
65
+ nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
66
+ end
67
+
69
68
  it "runs ruby from a file" do
70
- File.write(script_path, "VIM.command('let myvar = [1, 2]')")
69
+ File.write(script_path, "Vim.command('let myvar = [1, 2]')")
71
70
  nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
72
71
  expect(nvim.eval("g:myvar")).to eq([1, 2])
73
72
  end
@@ -90,7 +89,7 @@ RSpec.describe "ruby_provider" do
90
89
  end
91
90
 
92
91
  it "persists state between requests" do
93
- File.write(script_path, "def foo; VIM.command(\"let g:called = 1\"); end")
92
+ File.write(script_path, "def foo; Vim.command(\"let g:called = 1\"); end")
94
93
  nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
95
94
  expect { nvim.get_var("called") }.to raise_error(/key not found/i)
96
95
 
@@ -100,7 +99,7 @@ RSpec.describe "ruby_provider" do
100
99
 
101
100
  it "can run the same file multiple times" do
102
101
  nvim.set_var("called", 0)
103
- File.write(script_path, "VIM.command(\"let g:called += 1\")")
102
+ File.write(script_path, "Vim.command(\"let g:called += 1\")")
104
103
 
105
104
  nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
106
105
  expect(nvim.get_var("called")).to be(1)
@@ -109,14 +108,14 @@ RSpec.describe "ruby_provider" do
109
108
  expect(nvim.get_var("called")).to be(2)
110
109
  end
111
110
 
112
- it "persists instance state in globals" do
111
+ it "persists instance state in $curbuf" do
113
112
  File.write(script_path, <<-RUBY)
114
113
  def $curbuf.foo
115
114
  @foo ||= 0
116
115
  @foo += 1
117
116
  end
118
117
 
119
- VIM.command("let g:foo = \#{$curbuf.foo}")
118
+ Vim.command("let g:foo = \#{$curbuf.foo}")
120
119
  RUBY
121
120
 
122
121
  nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
@@ -124,21 +123,6 @@ RSpec.describe "ruby_provider" do
124
123
 
125
124
  nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
126
125
  expect(nvim.get_var("foo")).to be(2)
127
-
128
- File.write(script_path, <<-RUBY)
129
- def $curwin.bar
130
- @bar ||= 0
131
- @bar += 1
132
- end
133
-
134
- VIM.command("let g:bar = \#{$curwin.bar}")
135
- RUBY
136
-
137
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
138
- expect(nvim.get_var("bar")).to be(1)
139
-
140
- nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
141
- expect(nvim.get_var("bar")).to be(2)
142
126
  end
143
127
  end
144
128
 
@@ -1,16 +1,53 @@
1
1
  require "bundler/setup"
2
+
3
+ if ENV["REPORT_COVERAGE"]
4
+ require "coveralls"
5
+ Coveralls.wear!
6
+ end
7
+
8
+ require "fileutils"
2
9
  require "neovim"
3
10
  require "pry"
4
11
  require "stringio"
5
12
  require "timeout"
6
- require "fileutils"
7
13
 
8
- if ENV["REPORT_COVERAGE"]
9
- require "coveralls"
10
- Coveralls.wear!
14
+ module Support
15
+ def self.workspace
16
+ File.expand_path("../workspace", __FILE__)
17
+ end
18
+
19
+ def self.socket_path
20
+ file_path("nvim.sock")
21
+ end
22
+
23
+ def self.tcp_port
24
+ server = TCPServer.new("0.0.0.0", 0)
25
+
26
+ begin
27
+ server.addr[1]
28
+ ensure
29
+ server.close
30
+ end
31
+ end
32
+
33
+ def self.file_path(name)
34
+ File.join(workspace, name)
35
+ end
36
+
37
+ def self.setup_workspace
38
+ FileUtils.mkdir_p(workspace)
39
+ end
40
+
41
+ def self.teardown_workspace
42
+ FileUtils.rm_rf(workspace)
43
+ end
44
+
45
+ def self.child_argv
46
+ ["nvim", "--headless", "-i", "NONE", "-u", "NONE", "-n"]
47
+ end
11
48
  end
12
49
 
13
- unless system("nvim -nu NONE +q")
50
+ unless system("#{Support.child_argv.join(" ")} +q")
14
51
  warn("Can't find `nvim` executable. See installation instructions:")
15
52
  warn("https://github.com/neovim/neovim/wiki/Installing-Neovim")
16
53
  exit(1)
@@ -49,36 +86,4 @@ RSpec.configure do |config|
49
86
  Kernel.srand config.seed
50
87
  end
51
88
 
52
- module Support
53
- def self.workspace
54
- File.expand_path("../workspace", __FILE__)
55
- end
56
-
57
- def self.socket_path
58
- file_path("nvim.sock")
59
- end
60
-
61
- def self.port
62
- server = TCPServer.new("0.0.0.0", 0)
63
-
64
- begin
65
- server.addr[1]
66
- ensure
67
- server.close
68
- end
69
- end
70
-
71
- def self.file_path(name)
72
- File.join(workspace, name)
73
- end
74
-
75
- def self.setup_workspace
76
- FileUtils.mkdir_p(workspace)
77
- end
78
-
79
- def self.teardown_workspace
80
- FileUtils.rm_rf(workspace)
81
- end
82
- end
83
-
84
89
  Thread.abort_on_exception = true
@@ -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", "-n", "-u", "NONE"]) }
5
+ let(:client) { Neovim.attach_child(Support.child_argv) }
6
6
  let(:buffer) { client.current.buffer }
7
7
  after { client.shutdown }
8
8
 
@@ -2,7 +2,7 @@ require "helper"
2
2
 
3
3
  module Neovim
4
4
  RSpec.describe Client do
5
- let(:client) { Neovim.attach_child(["nvim", "-n", "-u", "NONE"]) }
5
+ let(:client) { Neovim.attach_child(Support.child_argv) }
6
6
  after { client.shutdown }
7
7
 
8
8
  specify do
@@ -2,7 +2,7 @@ require "helper"
2
2
 
3
3
  module Neovim
4
4
  RSpec.describe Current do
5
- let(:client) { Neovim.attach_child(["nvim", "-n", "-u", "NONE"]) }
5
+ let(:client) { Neovim.attach_child(Support.child_argv) }
6
6
  let(:current) { client.current }
7
7
  after { client.shutdown }
8
8
 
@@ -1,4 +1,6 @@
1
1
  require "helper"
2
+ require "neovim/host"
3
+ require "neovim/host/loader"
2
4
 
3
5
  module Neovim
4
6
  class Host
@@ -1,4 +1,5 @@
1
1
  require "helper"
2
+ require "neovim/host"
2
3
 
3
4
  module Neovim
4
5
  RSpec.describe Host do
@@ -6,17 +7,36 @@ module Neovim
6
7
  let(:client) { instance_double(Client) }
7
8
  let(:host) { Host.new(session, client) }
8
9
 
9
- describe ".load_from_files" do
10
- it "instantiates with a session and loads plugins" do
10
+ describe ".run" do
11
+ it "loads plugins and runs the host event loop" do
11
12
  paths = ["/foo", "/bar"]
13
+
14
+ expect(Host).to receive(:new).and_return(host)
15
+ expect(host).to receive(:run)
16
+
12
17
  loader = instance_double(Host::Loader)
13
18
 
19
+ expect(loader).to receive(:load).with(paths)
14
20
  expect(Host::Loader).to receive(:new).
15
- with(kind_of(Host)).
21
+ with(host).
16
22
  and_return(loader)
17
- expect(loader).to receive(:load).with(paths)
18
23
 
19
- Host.load_from_files(paths, :session => session, :client => client)
24
+ Host.run(paths, :session => session, :client => client)
25
+ end
26
+ end
27
+
28
+ describe "#run" do
29
+ it "runs the session event loop and handles messages" do
30
+ message = double(:message)
31
+ expect(session).to receive(:run).and_yield(message)
32
+ expect(host).to receive(:handle).with(message)
33
+
34
+ host.run
35
+ end
36
+
37
+ it "rescues session exceptions", :silence_logging do
38
+ expect(session).to receive(:run).and_raise("BOOM")
39
+ expect { host.run }.not_to raise_error
20
40
  end
21
41
  end
22
42
 
@@ -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", "-n", "-u", "NONE"]) }
5
+ let(:client) { Neovim.attach_child(Support.child_argv) }
6
6
  let(:buffer) { client.current.buffer }
7
7
  let(:line_range) { LineRange.new(buffer, 0, -1) }
8
8
  let(:sub_range) { LineRange.new(buffer, 1, 2) }
@@ -18,7 +18,7 @@ module Neovim
18
18
 
19
19
  it "is enumerable" do
20
20
  expect(line_range).to be_an(Enumerable)
21
- expect(line_range).to respond_to(:each)
21
+ expect(line_range.each.to_a).to eq(["1", "2", "3", "4"])
22
22
  end
23
23
 
24
24
  describe "#to_a" do
@@ -0,0 +1,56 @@
1
+ require "helper"
2
+
3
+ module Neovim
4
+ RSpec.describe Logging do
5
+ around do |spec|
6
+ old_logger = Logging.logger
7
+
8
+ begin
9
+ Logging.send(:remove_instance_variable, :@logger)
10
+ spec.run
11
+ ensure
12
+ Logging.logger = old_logger
13
+ end
14
+ end
15
+
16
+ describe ".logger" do
17
+ it "fetches the output from $NVIM_RUBY_LOG_FILE" do
18
+ logger = instance_double(Logger, :level= => nil)
19
+ expect(Logger).to receive(:new).with("/tmp/nvim.log").and_return(logger)
20
+ Logging.logger("NVIM_RUBY_LOG_FILE" => "/tmp/nvim.log")
21
+ expect(Logging.logger).to be(logger)
22
+ end
23
+
24
+ it "defaults the output to STDERR" do
25
+ logger = instance_double(Logger, :level= => nil)
26
+ expect(Logger).to receive(:new).with(STDERR).and_return(logger)
27
+ Logging.logger({})
28
+ expect(Logging.logger).to be(logger)
29
+ end
30
+
31
+ it "fetches the level from $NVIM_RUBY_LOG_LEVEL as a string" do
32
+ logger = instance_double(Logger)
33
+ expect(Logger).to receive(:new).and_return(logger)
34
+ expect(logger).to receive(:level=).with(Logger::DEBUG)
35
+ Logging.logger("NVIM_RUBY_LOG_LEVEL" => "DEBUG")
36
+ expect(Logging.logger).to be(logger)
37
+ end
38
+
39
+ it "fetches the level from $NVIM_RUBY_LOG_LEVEL as an integer" do
40
+ logger = instance_double(Logger)
41
+ expect(Logger).to receive(:new).and_return(logger)
42
+ expect(logger).to receive(:level=).with(0)
43
+ Logging.logger("NVIM_RUBY_LOG_LEVEL" => "0")
44
+ expect(Logging.logger).to be(logger)
45
+ end
46
+
47
+ it "defaults the level to WARN" do
48
+ logger = instance_double(Logger)
49
+ expect(Logger).to receive(:new).and_return(logger)
50
+ expect(logger).to receive(:level=).with(Logger::WARN)
51
+ Logging.logger({})
52
+ expect(Logging.logger).to be(logger)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,4 +1,5 @@
1
1
  require "helper"
2
+ require "neovim/plugin"
2
3
 
3
4
  module Neovim
4
5
  RSpec.describe Plugin do
@@ -13,6 +14,8 @@ module Neovim
13
14
  expect(plugin.handlers.size).to be(1)
14
15
  handler = plugin.handlers.first
15
16
 
17
+ expect(handler.sync?).to be(false)
18
+ expect(handler.qualified?).to be(true)
16
19
  expect(handler.block).to eq(cmd_block)
17
20
  expect(handler.qualified_name).to eq("source:command:Foo")
18
21
  expect(handler.to_spec).to eq(
@@ -33,6 +36,8 @@ module Neovim
33
36
  expect(plugin.handlers.size).to be(1)
34
37
  handler = plugin.handlers.first
35
38
 
39
+ expect(handler.sync?).to be(false)
40
+ expect(handler.qualified?).to be(true)
36
41
  expect(handler.block).to eq(au_block)
37
42
  expect(handler.qualified_name).to eq("source:autocmd:BufEnter:*.rb")
38
43
  expect(handler.to_spec).to eq(
@@ -53,6 +58,8 @@ module Neovim
53
58
  expect(plugin.handlers.size).to be(1)
54
59
  handler = plugin.handlers.first
55
60
 
61
+ expect(handler.sync?).to be(false)
62
+ expect(handler.qualified?).to be(true)
56
63
  expect(handler.block).to eq(fun_block)
57
64
  expect(handler.qualified_name).to eq("source:function:Foo")
58
65
  expect(handler.to_spec).to eq(
@@ -73,6 +80,8 @@ module Neovim
73
80
  expect(plugin.handlers.size).to be(1)
74
81
  handler = plugin.handlers.first
75
82
 
83
+ expect(handler.sync?).to be(true)
84
+ expect(handler.qualified?).to be(false)
76
85
  expect(handler.block).to eq(cmd_block)
77
86
  expect(handler.qualified_name).to eq("Foo")
78
87
  end