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
 
| 
         @@ -21,16 +21,21 @@ RSpec.describe "neovim-ruby-host" do 
     | 
|
| 
       21 
21 
     | 
    
         
             
                    plug.command(:AsyncSetLine, :args => 1) do |nvim, str|
         
     | 
| 
       22 
22 
     | 
    
         
             
                      nvim.current.line = str
         
     | 
| 
       23 
23 
     | 
    
         
             
                    end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                    plug.rpc(:TopLevelAdd, :nargs => 2, :sync => true) do |nvim, x, y|
         
     | 
| 
      
 26 
     | 
    
         
            +
                      x + y
         
     | 
| 
      
 27 
     | 
    
         
            +
                    end
         
     | 
| 
       24 
28 
     | 
    
         
             
                  end
         
     | 
| 
       25 
29 
     | 
    
         
             
                RUBY
         
     | 
| 
       26 
30 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
                nvim = Neovim.attach_child(["--headless", "-u", "NONE", "-N", "-n"])
         
     | 
| 
      
 31 
     | 
    
         
            +
                nvim = Neovim.attach_child(["nvim", "--headless", "-u", "NONE", "-N", "-n"])
         
     | 
| 
       28 
32 
     | 
    
         | 
| 
       29 
33 
     | 
    
         
             
                host_exe = File.expand_path("../../../bin/neovim-ruby-host", __FILE__)
         
     | 
| 
       30 
34 
     | 
    
         
             
                nvim.command("let host = rpcstart('#{host_exe}', ['#{plugin1_path}', '#{plugin2_path}'])")
         
     | 
| 
       31 
35 
     | 
    
         | 
| 
       32 
36 
     | 
    
         
             
                expect(nvim.eval("rpcrequest(host, 'poll')")).to eq("ok")
         
     | 
| 
       33 
37 
     | 
    
         
             
                expect(nvim.eval("rpcrequest(host, '#{plugin1_path}:function:SyncAdd', [1, 2])")).to eq(3)
         
     | 
| 
      
 38 
     | 
    
         
            +
                expect(nvim.eval("rpcrequest(host, 'TopLevelAdd', 1, 2)")).to eq(3)
         
     | 
| 
       34 
39 
     | 
    
         | 
| 
       35 
40 
     | 
    
         
             
                expect {
         
     | 
| 
       36 
41 
     | 
    
         
             
                  nvim.command("call rpcnotify(host, '#{plugin1_path}:autocmd:BufEnter:*.rb')")
         
     | 
| 
         @@ -0,0 +1,76 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "helper"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            RSpec.describe "ruby_provider" do
         
     | 
| 
      
 4 
     | 
    
         
            +
              let(:nvim) do
         
     | 
| 
      
 5 
     | 
    
         
            +
                Neovim.attach_child(["nvim", "--headless", "-u", "NONE", "-N", "-n"])
         
     | 
| 
      
 6 
     | 
    
         
            +
              end
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              before do
         
     | 
| 
      
 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 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              describe "ruby_execute" do
         
     | 
| 
      
 17 
     | 
    
         
            +
                it "runs ruby directly" do
         
     | 
| 
      
 18 
     | 
    
         
            +
                  ruby = "VIM.command('let myvar = [1, 2]')".inspect
         
     | 
| 
      
 19 
     | 
    
         
            +
                  nvim.eval("rpcrequest(host, 'ruby_execute', #{ruby})")
         
     | 
| 
      
 20 
     | 
    
         
            +
                  expect(nvim.eval("g:myvar")).to eq([1, 2])
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                it "exposes the $curwin variable" do
         
     | 
| 
      
 24 
     | 
    
         
            +
                  nvim.command("vsplit")
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  expect {
         
     | 
| 
      
 27 
     | 
    
         
            +
                    ruby = "$curwin.width -= 1".inspect
         
     | 
| 
      
 28 
     | 
    
         
            +
                    nvim.eval("rpcrequest(host, 'ruby_execute', #{ruby})")
         
     | 
| 
      
 29 
     | 
    
         
            +
                  }.to change { nvim.current.window.width }.by(-1)
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                it "exposes the $curbuf variable" do
         
     | 
| 
      
 33 
     | 
    
         
            +
                  expect {
         
     | 
| 
      
 34 
     | 
    
         
            +
                    ruby = "$curbuf.lines = ['line']".inspect
         
     | 
| 
      
 35 
     | 
    
         
            +
                    nvim.eval("rpcrequest(host, 'ruby_execute', #{ruby})")
         
     | 
| 
      
 36 
     | 
    
         
            +
                  }.to change { nvim.current.buffer.lines.to_a }.to(["line"])
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
              end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
              describe "ruby_execute_file" do
         
     | 
| 
      
 41 
     | 
    
         
            +
                let(:script_path) { Support.file_path("script.rb") }
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                it "runs ruby from a file" do
         
     | 
| 
      
 44 
     | 
    
         
            +
                  File.write(script_path, "VIM.command('let myvar = [1, 2]')")
         
     | 
| 
      
 45 
     | 
    
         
            +
                  nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
         
     | 
| 
      
 46 
     | 
    
         
            +
                  expect(nvim.eval("g:myvar")).to eq([1, 2])
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                it "exposes the $curwin variable" do
         
     | 
| 
      
 50 
     | 
    
         
            +
                  File.write(script_path, "$curwin.width -= 1")
         
     | 
| 
      
 51 
     | 
    
         
            +
                  nvim.command("vsplit")
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                  expect {
         
     | 
| 
      
 54 
     | 
    
         
            +
                    nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
         
     | 
| 
      
 55 
     | 
    
         
            +
                  }.to change { nvim.current.window.width }.by(-1)
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                it "exposes the $curbuf variable" do
         
     | 
| 
      
 59 
     | 
    
         
            +
                  File.write(script_path, "$curbuf.lines = ['line']")
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                  expect {
         
     | 
| 
      
 62 
     | 
    
         
            +
                    nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
         
     | 
| 
      
 63 
     | 
    
         
            +
                  }.to change { nvim.current.buffer.lines.to_a }.to(["line"])
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
              end
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
              describe "ruby_do_range" do
         
     | 
| 
      
 68 
     | 
    
         
            +
                it "mutates lines via the $_ variable" do
         
     | 
| 
      
 69 
     | 
    
         
            +
                  nvim.current.buffer.lines = ["a", "b", "c", "d"]
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                  expect {
         
     | 
| 
      
 72 
     | 
    
         
            +
                    nvim.eval("rpcrequest(host, 'ruby_do_range', 2, 3, '$_.upcase!; 42')")
         
     | 
| 
      
 73 
     | 
    
         
            +
                  }.to change { nvim.current.buffer.lines.to_a }.to(["a", "B", "C", "d"])
         
     | 
| 
      
 74 
     | 
    
         
            +
                end
         
     | 
| 
      
 75 
     | 
    
         
            +
              end
         
     | 
| 
      
 76 
     | 
    
         
            +
            end
         
     | 
    
        data/spec/helper.rb
    CHANGED
    
    | 
         @@ -1,5 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require "bundler/setup"
         
     | 
| 
       2 
     | 
    
         
            -
            require " 
     | 
| 
      
 2 
     | 
    
         
            +
            require "mkmf"
         
     | 
| 
       3 
3 
     | 
    
         
             
            require "neovim"
         
     | 
| 
       4 
4 
     | 
    
         
             
            require "pry"
         
     | 
| 
       5 
5 
     | 
    
         
             
            require "timeout"
         
     | 
| 
         @@ -11,21 +11,12 @@ if ENV["REPORT_COVERAGE"] 
     | 
|
| 
       11 
11 
     | 
    
         
             
              Coveralls.wear!
         
     | 
| 
       12 
12 
     | 
    
         
             
            end
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
            if File.exists?(nvim_bin)
         
     | 
| 
       19 
     | 
    
         
            -
              ENV["NVIM_EXECUTABLE"] = nvim_bin
         
     | 
| 
       20 
     | 
    
         
            -
            else
         
     | 
| 
       21 
     | 
    
         
            -
              warn("Can't find vendored `nvim` executable. Build it with `rake neovim:build`")
         
     | 
| 
      
 14 
     | 
    
         
            +
            unless find_executable0("nvim")
         
     | 
| 
      
 15 
     | 
    
         
            +
              warn("Can't find `nvim` executable. See installation instructions:")
         
     | 
| 
      
 16 
     | 
    
         
            +
              warn("https://github.com/neovim/neovim/wiki/Installing-Neovim")
         
     | 
| 
       22 
17 
     | 
    
         
             
              exit(1)
         
     | 
| 
       23 
18 
     | 
    
         
             
            end
         
     | 
| 
       24 
19 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
            Neovim.logger = Logger.new(STDERR).tap do |logger|
         
     | 
| 
       26 
     | 
    
         
            -
              logger.level = ENV.fetch("NVIM_RUBY_LOG_LEVEL", Logger::WARN).to_i
         
     | 
| 
       27 
     | 
    
         
            -
            end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
20 
     | 
    
         
             
            RSpec.configure do |config|
         
     | 
| 
       30 
21 
     | 
    
         
             
              config.expect_with :rspec do |exp|
         
     | 
| 
       31 
22 
     | 
    
         
             
                exp.syntax = :expect
         
     | 
| 
         @@ -35,14 +26,17 @@ RSpec.configure do |config| 
     | 
|
| 
       35 
26 
     | 
    
         
             
              config.order = :random
         
     | 
| 
       36 
27 
     | 
    
         
             
              config.color = true
         
     | 
| 
       37 
28 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
              Kernel.srand config.seed
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
29 
     | 
    
         
             
              config.around(:example) do |spec|
         
     | 
| 
       41 
30 
     | 
    
         
             
                Support.setup_workspace
         
     | 
| 
       42 
     | 
    
         
            -
                Timeout.timeout(2) { spec.run }
         
     | 
| 
       43 
     | 
    
         
            -
              end
         
     | 
| 
       44 
31 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
      
 32 
     | 
    
         
            +
                begin
         
     | 
| 
      
 33 
     | 
    
         
            +
                  Timeout.timeout(5) { spec.run }
         
     | 
| 
      
 34 
     | 
    
         
            +
                ensure
         
     | 
| 
      
 35 
     | 
    
         
            +
                  Support.teardown_workspace
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
       47 
37 
     | 
    
         
             
              end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
              Kernel.srand config.seed
         
     | 
| 
       48 
40 
     | 
    
         
             
            end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
            Thread.abort_on_exception = true
         
     | 
| 
         @@ -9,10 +9,11 @@ module Neovim 
     | 
|
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
                    server_thread = Thread.new do
         
     | 
| 
       11 
11 
     | 
    
         
             
                      client = server.accept
         
     | 
| 
       12 
     | 
    
         
            -
                       
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 12 
     | 
    
         
            +
                      client.write(
         
     | 
| 
      
 13 
     | 
    
         
            +
                        MessagePack.pack(
         
     | 
| 
      
 14 
     | 
    
         
            +
                          [0, 123, "func", [1, 2, 3]]
         
     | 
| 
      
 15 
     | 
    
         
            +
                        )
         
     | 
| 
      
 16 
     | 
    
         
            +
                      )
         
     | 
| 
       16 
17 
     | 
    
         
             
                    end
         
     | 
| 
       17 
18 
     | 
    
         | 
| 
       18 
19 
     | 
    
         
             
                    request = nil
         
     | 
| 
         @@ -34,10 +35,11 @@ module Neovim 
     | 
|
| 
       34 
35 
     | 
    
         | 
| 
       35 
36 
     | 
    
         
             
                    server_thread = Thread.new do
         
     | 
| 
       36 
37 
     | 
    
         
             
                      client = server.accept
         
     | 
| 
       37 
     | 
    
         
            -
                       
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
      
 38 
     | 
    
         
            +
                      client.write(
         
     | 
| 
      
 39 
     | 
    
         
            +
                        MessagePack.pack(
         
     | 
| 
      
 40 
     | 
    
         
            +
                          [2, "func", [1, 2, 3]]
         
     | 
| 
      
 41 
     | 
    
         
            +
                        )
         
     | 
| 
      
 42 
     | 
    
         
            +
                      )
         
     | 
| 
       41 
43 
     | 
    
         
             
                    end
         
     | 
| 
       42 
44 
     | 
    
         | 
| 
       43 
45 
     | 
    
         
             
                    notification = nil
         
     | 
| 
         @@ -56,15 +58,17 @@ module Neovim 
     | 
|
| 
       56 
58 
     | 
    
         
             
                  it "receives responses to requests" do
         
     | 
| 
       57 
59 
     | 
    
         
             
                    stream = MsgpackStream.new(event_loop)
         
     | 
| 
       58 
60 
     | 
    
         
             
                    async_session = AsyncSession.new(stream)
         
     | 
| 
       59 
     | 
    
         
            -
                     
     | 
| 
      
 61 
     | 
    
         
            +
                    request = nil
         
     | 
| 
       60 
62 
     | 
    
         | 
| 
       61 
63 
     | 
    
         
             
                    server_thread = Thread.new do
         
     | 
| 
       62 
64 
     | 
    
         
             
                      client = server.accept
         
     | 
| 
       63 
     | 
    
         
            -
                       
     | 
| 
      
 65 
     | 
    
         
            +
                      request = client.readpartial(1024)
         
     | 
| 
       64 
66 
     | 
    
         | 
| 
       65 
     | 
    
         
            -
                      client.write( 
     | 
| 
       66 
     | 
    
         
            -
                         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
      
 67 
     | 
    
         
            +
                      client.write(
         
     | 
| 
      
 68 
     | 
    
         
            +
                        MessagePack.pack(
         
     | 
| 
      
 69 
     | 
    
         
            +
                          [1, 0, [0, "error"], "result"]
         
     | 
| 
      
 70 
     | 
    
         
            +
                        )
         
     | 
| 
      
 71 
     | 
    
         
            +
                      )
         
     | 
| 
       68 
72 
     | 
    
         
             
                    end
         
     | 
| 
       69 
73 
     | 
    
         | 
| 
       70 
74 
     | 
    
         
             
                    error, result = nil
         
     | 
| 
         @@ -79,8 +83,8 @@ module Neovim 
     | 
|
| 
       79 
83 
     | 
    
         
             
                    server_thread.join
         
     | 
| 
       80 
84 
     | 
    
         
             
                    async_session.shutdown
         
     | 
| 
       81 
85 
     | 
    
         | 
| 
       82 
     | 
    
         
            -
                    expect( 
     | 
| 
       83 
     | 
    
         
            -
                       
     | 
| 
      
 86 
     | 
    
         
            +
                    expect(request).to eq(
         
     | 
| 
      
 87 
     | 
    
         
            +
                      MessagePack.pack([0, 0, "func", [1, 2, 3]])
         
     | 
| 
       84 
88 
     | 
    
         
             
                    )
         
     | 
| 
       85 
89 
     | 
    
         
             
                  end
         
     | 
| 
       86 
90 
     | 
    
         
             
                end
         
     | 
    
        data/spec/neovim/buffer_spec.rb
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ require "helper" 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module Neovim
         
     | 
| 
       4 
4 
     | 
    
         
             
              RSpec.describe Buffer do
         
     | 
| 
       5 
     | 
    
         
            -
                let(:client) { Neovim.attach_child(["--headless", "-n", "-u", "NONE"]) }
         
     | 
| 
      
 5 
     | 
    
         
            +
                let(:client) { Neovim.attach_child(["nvim", "--headless", "-n", "-u", "NONE"]) }
         
     | 
| 
       6 
6 
     | 
    
         
             
                let(:buffer) { client.current.buffer }
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
                describe "#lines" do
         
     | 
| 
         @@ -31,5 +31,131 @@ module Neovim 
     | 
|
| 
       31 
31 
     | 
    
         
             
                    expect(buffer.range.to_a).to eq(["one", "two"])
         
     | 
| 
       32 
32 
     | 
    
         
             
                  end
         
     | 
| 
       33 
33 
     | 
    
         
             
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                describe "if_ruby compatibility" do
         
     | 
| 
      
 36 
     | 
    
         
            +
                  describe "#name" do
         
     | 
| 
      
 37 
     | 
    
         
            +
                    it "returns the buffer path as a string" do
         
     | 
| 
      
 38 
     | 
    
         
            +
                      buffer.set_name("test_buf")
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                      expect(File.basename(buffer.name)).
         
     | 
| 
      
 41 
     | 
    
         
            +
                        to end_with("test_buf")
         
     | 
| 
      
 42 
     | 
    
         
            +
                    end
         
     | 
| 
      
 43 
     | 
    
         
            +
                  end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                  describe "#number" do
         
     | 
| 
      
 46 
     | 
    
         
            +
                    it "returns the buffer index" do
         
     | 
| 
      
 47 
     | 
    
         
            +
                      expect(buffer.number).to be(1)
         
     | 
| 
      
 48 
     | 
    
         
            +
                    end
         
     | 
| 
      
 49 
     | 
    
         
            +
                  end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                  describe "#count" do
         
     | 
| 
      
 52 
     | 
    
         
            +
                    it "returns the number of lines" do
         
     | 
| 
      
 53 
     | 
    
         
            +
                      buffer.lines = ["one", "two", "three"]
         
     | 
| 
      
 54 
     | 
    
         
            +
                      expect(buffer.count).to be(3)
         
     | 
| 
      
 55 
     | 
    
         
            +
                    end
         
     | 
| 
      
 56 
     | 
    
         
            +
                  end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                  describe "#length" do
         
     | 
| 
      
 59 
     | 
    
         
            +
                    it "returns the number of lines" do
         
     | 
| 
      
 60 
     | 
    
         
            +
                      buffer.lines = ["one", "two", "three"]
         
     | 
| 
      
 61 
     | 
    
         
            +
                      expect(buffer.length).to be(3)
         
     | 
| 
      
 62 
     | 
    
         
            +
                    end
         
     | 
| 
      
 63 
     | 
    
         
            +
                  end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                  describe "#[]" do
         
     | 
| 
      
 66 
     | 
    
         
            +
                    it "returns the line at the given index" do
         
     | 
| 
      
 67 
     | 
    
         
            +
                      buffer.lines = ["one", "two", "three"]
         
     | 
| 
      
 68 
     | 
    
         
            +
                      expect(buffer[1]).to eq("two")
         
     | 
| 
      
 69 
     | 
    
         
            +
                    end
         
     | 
| 
      
 70 
     | 
    
         
            +
                  end
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                  describe "#[]=" do
         
     | 
| 
      
 73 
     | 
    
         
            +
                    it "sets the line at the given index" do
         
     | 
| 
      
 74 
     | 
    
         
            +
                      buffer.lines = ["one", "two"]
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                      expect {
         
     | 
| 
      
 77 
     | 
    
         
            +
                        buffer[0] = "first"
         
     | 
| 
      
 78 
     | 
    
         
            +
                      }.to change { buffer.lines }.to(["first", "two"])
         
     | 
| 
      
 79 
     | 
    
         
            +
                    end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                    it "returns the line" do
         
     | 
| 
      
 82 
     | 
    
         
            +
                      expect(buffer[0] = "first").to eq("first")
         
     | 
| 
      
 83 
     | 
    
         
            +
                    end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                    it "raises an out of bounds exception" do
         
     | 
| 
      
 86 
     | 
    
         
            +
                      expect {
         
     | 
| 
      
 87 
     | 
    
         
            +
                        buffer[10] = "line"
         
     | 
| 
      
 88 
     | 
    
         
            +
                      }.to raise_error(/out of bounds/)
         
     | 
| 
      
 89 
     | 
    
         
            +
                    end
         
     | 
| 
      
 90 
     | 
    
         
            +
                  end
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                  describe "#delete" do
         
     | 
| 
      
 93 
     | 
    
         
            +
                    it "deletes the line at the given index" do
         
     | 
| 
      
 94 
     | 
    
         
            +
                      buffer.lines = ["one", "two"]
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
                      expect {
         
     | 
| 
      
 97 
     | 
    
         
            +
                        buffer.delete(0)
         
     | 
| 
      
 98 
     | 
    
         
            +
                      }.to change { buffer.lines }.to(["two"])
         
     | 
| 
      
 99 
     | 
    
         
            +
                    end
         
     | 
| 
      
 100 
     | 
    
         
            +
                  end
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
                  describe "#append" do
         
     | 
| 
      
 103 
     | 
    
         
            +
                    it "adds a line after the given index" do
         
     | 
| 
      
 104 
     | 
    
         
            +
                      buffer.lines = ["one"]
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
                      expect {
         
     | 
| 
      
 107 
     | 
    
         
            +
                        buffer.append(0, "two")
         
     | 
| 
      
 108 
     | 
    
         
            +
                      }.to change { buffer.lines.to_a }.to(["one", "two"])
         
     | 
| 
      
 109 
     | 
    
         
            +
                    end
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
                    it "returns the appended line" do
         
     | 
| 
      
 112 
     | 
    
         
            +
                      expect(buffer.append(0, "two")).to eq("two")
         
     | 
| 
      
 113 
     | 
    
         
            +
                    end
         
     | 
| 
      
 114 
     | 
    
         
            +
                  end
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
                  describe "#line" do
         
     | 
| 
      
 117 
     | 
    
         
            +
                    it "returns the current line on an active buffer" do
         
     | 
| 
      
 118 
     | 
    
         
            +
                      buffer.lines = ["one", "two"]
         
     | 
| 
      
 119 
     | 
    
         
            +
                      expect(buffer.line).to eq("one")
         
     | 
| 
      
 120 
     | 
    
         
            +
                    end
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
                    it "returns nil on an inactive buffer" do
         
     | 
| 
      
 123 
     | 
    
         
            +
                      original = buffer
         
     | 
| 
      
 124 
     | 
    
         
            +
                      client.command("vnew")
         
     | 
| 
      
 125 
     | 
    
         
            +
                      expect(original.line).to be(nil)
         
     | 
| 
      
 126 
     | 
    
         
            +
                    end
         
     | 
| 
      
 127 
     | 
    
         
            +
                  end
         
     | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
      
 129 
     | 
    
         
            +
                  describe "#line=" do
         
     | 
| 
      
 130 
     | 
    
         
            +
                    it "sets the current line on an active buffer" do
         
     | 
| 
      
 131 
     | 
    
         
            +
                      expect {
         
     | 
| 
      
 132 
     | 
    
         
            +
                        buffer.line = "line"
         
     | 
| 
      
 133 
     | 
    
         
            +
                      }.to change { buffer.lines }.to(["line"])
         
     | 
| 
      
 134 
     | 
    
         
            +
                    end
         
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
      
 136 
     | 
    
         
            +
                    it "has no effect when called on an inactive buffer" do
         
     | 
| 
      
 137 
     | 
    
         
            +
                      original = buffer
         
     | 
| 
      
 138 
     | 
    
         
            +
                      client.command("vnew")
         
     | 
| 
      
 139 
     | 
    
         
            +
                      original.line = "line"
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
                      expect(original.lines.to_a).to eq([""])
         
     | 
| 
      
 142 
     | 
    
         
            +
                      expect(client.current.buffer.lines.to_a).to eq([""])
         
     | 
| 
      
 143 
     | 
    
         
            +
                    end
         
     | 
| 
      
 144 
     | 
    
         
            +
                  end
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
                  describe "#line_number" do
         
     | 
| 
      
 147 
     | 
    
         
            +
                    it "returns the current line number on an active buffer" do
         
     | 
| 
      
 148 
     | 
    
         
            +
                      client.command("normal oone")
         
     | 
| 
      
 149 
     | 
    
         
            +
                      expect(buffer.line_number).to be(2)
         
     | 
| 
      
 150 
     | 
    
         
            +
                    end
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
                    it "returns nil on an inactive buffer" do
         
     | 
| 
      
 153 
     | 
    
         
            +
                      original = buffer
         
     | 
| 
      
 154 
     | 
    
         
            +
                      client.command("vnew")
         
     | 
| 
      
 155 
     | 
    
         
            +
             
     | 
| 
      
 156 
     | 
    
         
            +
                      expect(original.line_number).to be(nil)
         
     | 
| 
      
 157 
     | 
    
         
            +
                    end
         
     | 
| 
      
 158 
     | 
    
         
            +
                  end
         
     | 
| 
      
 159 
     | 
    
         
            +
                end
         
     | 
| 
       34 
160 
     | 
    
         
             
              end
         
     | 
| 
       35 
161 
     | 
    
         
             
            end
         
     | 
    
        data/spec/neovim/client_spec.rb
    CHANGED
    
    
    
        data/spec/neovim/current_spec.rb
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ require "helper" 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module Neovim
         
     | 
| 
       4 
4 
     | 
    
         
             
              RSpec.describe Current do
         
     | 
| 
       5 
     | 
    
         
            -
                let(:client) { Neovim.attach_child(["-n", "-u", "NONE"]) }
         
     | 
| 
      
 5 
     | 
    
         
            +
                let(:client) { Neovim.attach_child(["nvim", "-n", "-u", "NONE"]) }
         
     | 
| 
       6 
6 
     | 
    
         
             
                let(:current) { client.current }
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
                describe "#line" do
         
     | 
| 
         @@ -134,5 +134,13 @@ module Neovim 
     | 
|
| 
       134 
134 
     | 
    
         
             
                    expect(current.tabpage = tp0).to eq(tp0)
         
     | 
| 
       135 
135 
     | 
    
         
             
                  end
         
     | 
| 
       136 
136 
     | 
    
         
             
                end
         
     | 
| 
      
 137 
     | 
    
         
            +
             
     | 
| 
      
 138 
     | 
    
         
            +
                describe "#range=" do
         
     | 
| 
      
 139 
     | 
    
         
            +
                  it "sets the line range of the current buffer" do
         
     | 
| 
      
 140 
     | 
    
         
            +
                    current.buffer.lines = ["one", "two", "three", "four"]
         
     | 
| 
      
 141 
     | 
    
         
            +
                    current.range = (1..2)
         
     | 
| 
      
 142 
     | 
    
         
            +
                    expect(current.buffer.range.to_a).to eq(["two", "three"])
         
     | 
| 
      
 143 
     | 
    
         
            +
                  end
         
     | 
| 
      
 144 
     | 
    
         
            +
                end
         
     | 
| 
       137 
145 
     | 
    
         
             
              end
         
     | 
| 
       138 
146 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,32 +1,31 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require "helper"
         
     | 
| 
       2 
2 
     | 
    
         
             
            require "socket"
         
     | 
| 
       3 
     | 
    
         
            -
            require "fileutils"
         
     | 
| 
       4 
3 
     | 
    
         | 
| 
       5 
4 
     | 
    
         
             
            module Neovim
         
     | 
| 
       6 
5 
     | 
    
         
             
              RSpec.describe EventLoop do
         
     | 
| 
       7 
6 
     | 
    
         
             
                shared_context "socket behavior" do
         
     | 
| 
       8 
7 
     | 
    
         
             
                  it "sends and receives data" do
         
     | 
| 
       9 
     | 
    
         
            -
                     
     | 
| 
      
 8 
     | 
    
         
            +
                    request = nil
         
     | 
| 
       10 
9 
     | 
    
         | 
| 
       11 
10 
     | 
    
         
             
                    server_thread = Thread.new do
         
     | 
| 
       12 
11 
     | 
    
         
             
                      client = server.accept
         
     | 
| 
       13 
     | 
    
         
            -
                       
     | 
| 
      
 12 
     | 
    
         
            +
                      request = client.readpartial(1024)
         
     | 
| 
       14 
13 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
                      client.write(" 
     | 
| 
      
 14 
     | 
    
         
            +
                      client.write("res")
         
     | 
| 
       16 
15 
     | 
    
         
             
                      client.close
         
     | 
| 
       17 
16 
     | 
    
         
             
                      server.close
         
     | 
| 
       18 
17 
     | 
    
         
             
                    end
         
     | 
| 
       19 
18 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
                     
     | 
| 
       21 
     | 
    
         
            -
                    event_loop.write(" 
     | 
| 
       22 
     | 
    
         
            -
                       
     | 
| 
      
 19 
     | 
    
         
            +
                    response = nil
         
     | 
| 
      
 20 
     | 
    
         
            +
                    event_loop.write("req").run do |msg|
         
     | 
| 
      
 21 
     | 
    
         
            +
                      response = msg
         
     | 
| 
       23 
22 
     | 
    
         
             
                      event_loop.stop
         
     | 
| 
       24 
23 
     | 
    
         
             
                    end
         
     | 
| 
       25 
24 
     | 
    
         | 
| 
       26 
25 
     | 
    
         
             
                    server_thread.join
         
     | 
| 
       27 
26 
     | 
    
         
             
                    event_loop.shutdown
         
     | 
| 
       28 
     | 
    
         
            -
                    expect( 
     | 
| 
       29 
     | 
    
         
            -
                    expect( 
     | 
| 
      
 27 
     | 
    
         
            +
                    expect(request).to eq("req")
         
     | 
| 
      
 28 
     | 
    
         
            +
                    expect(response).to eq("res")
         
     | 
| 
       30 
29 
     | 
    
         
             
                  end
         
     | 
| 
       31 
30 
     | 
    
         
             
                end
         
     | 
| 
       32 
31 
     | 
    
         | 
| 
         @@ -57,22 +56,22 @@ module Neovim 
     | 
|
| 
       57 
56 
     | 
    
         
             
                      STDIN.reopen(cl_stdin)
         
     | 
| 
       58 
57 
     | 
    
         | 
| 
       59 
58 
     | 
    
         
             
                      event_loop = EventLoop.stdio
         
     | 
| 
       60 
     | 
    
         
            -
                       
     | 
| 
      
 59 
     | 
    
         
            +
                      request = nil
         
     | 
| 
       61 
60 
     | 
    
         | 
| 
       62 
61 
     | 
    
         
             
                      server_thread = Thread.new do
         
     | 
| 
       63 
     | 
    
         
            -
                         
     | 
| 
       64 
     | 
    
         
            -
                        srv_stdin.write(" 
     | 
| 
      
 62 
     | 
    
         
            +
                        request = srv_stdout.readpartial(1024)
         
     | 
| 
      
 63 
     | 
    
         
            +
                        srv_stdin.write("res")
         
     | 
| 
       65 
64 
     | 
    
         
             
                      end
         
     | 
| 
       66 
65 
     | 
    
         | 
| 
       67 
     | 
    
         
            -
                       
     | 
| 
       68 
     | 
    
         
            -
                      event_loop.write(" 
     | 
| 
       69 
     | 
    
         
            -
                         
     | 
| 
      
 66 
     | 
    
         
            +
                      response = nil
         
     | 
| 
      
 67 
     | 
    
         
            +
                      event_loop.write("req").run do |msg|
         
     | 
| 
      
 68 
     | 
    
         
            +
                        response = msg
         
     | 
| 
       70 
69 
     | 
    
         
             
                        event_loop.stop
         
     | 
| 
       71 
70 
     | 
    
         
             
                      end
         
     | 
| 
       72 
71 
     | 
    
         | 
| 
       73 
72 
     | 
    
         
             
                      server_thread.join
         
     | 
| 
       74 
     | 
    
         
            -
                      expect( 
     | 
| 
       75 
     | 
    
         
            -
                      expect( 
     | 
| 
      
 73 
     | 
    
         
            +
                      expect(request).to eq("req")
         
     | 
| 
      
 74 
     | 
    
         
            +
                      expect(response).to eq("res")
         
     | 
| 
       76 
75 
     | 
    
         
             
                    ensure
         
     | 
| 
       77 
76 
     | 
    
         
             
                      STDOUT.reopen(old_stdout)
         
     | 
| 
       78 
77 
     | 
    
         
             
                      STDIN.reopen(old_stdin)
         
     | 
| 
         @@ -82,17 +81,17 @@ module Neovim 
     | 
|
| 
       82 
81 
     | 
    
         | 
| 
       83 
82 
     | 
    
         
             
                context "child" do
         
     | 
| 
       84 
83 
     | 
    
         
             
                  it "sends and receives data" do
         
     | 
| 
       85 
     | 
    
         
            -
                    event_loop = EventLoop.child(["-n", "-u", "NONE"])
         
     | 
| 
      
 84 
     | 
    
         
            +
                    event_loop = EventLoop.child(["nvim", "-n", "-u", "NONE"])
         
     | 
| 
       86 
85 
     | 
    
         
             
                    input = MessagePack.pack([0, 0, :vim_strwidth, ["hi"]])
         
     | 
| 
       87 
86 
     | 
    
         | 
| 
       88 
     | 
    
         
            -
                     
     | 
| 
      
 87 
     | 
    
         
            +
                    response = nil
         
     | 
| 
       89 
88 
     | 
    
         
             
                    event_loop.write(input).run do |msg|
         
     | 
| 
       90 
     | 
    
         
            -
                       
     | 
| 
      
 89 
     | 
    
         
            +
                      response = msg
         
     | 
| 
       91 
90 
     | 
    
         
             
                      event_loop.stop
         
     | 
| 
       92 
91 
     | 
    
         
             
                    end
         
     | 
| 
       93 
92 
     | 
    
         | 
| 
       94 
93 
     | 
    
         
             
                    event_loop.shutdown
         
     | 
| 
       95 
     | 
    
         
            -
                    expect( 
     | 
| 
      
 94 
     | 
    
         
            +
                    expect(response).to eq(MessagePack.pack([1, 0, nil, 2]))
         
     | 
| 
       96 
95 
     | 
    
         
             
                  end
         
     | 
| 
       97 
96 
     | 
    
         
             
                end
         
     | 
| 
       98 
97 
     | 
    
         
             
              end
         
     |