neovim 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f815ff4bec0348ba8b77aa4f9b04197e8a521655
4
- data.tar.gz: 149067ce655eb2b13102f9d68b0ef635668a3578
3
+ metadata.gz: 65ebef25a57b7d4e244b65fbceb840bd8b1102f3
4
+ data.tar.gz: 152c9fbe48f7a50594be2abe6551e41a576808a1
5
5
  SHA512:
6
- metadata.gz: a0b76436db1b7523be49ecfb8be84785f3420a0eeeea294b38f6173b94136a5d60cd02f8c9dd3ff6d209bf728dc1e042c1faf1c5b0a24239a199a3099a5b141b
7
- data.tar.gz: e7048d7300227a7effc924d3248798b0669471dfa56820eac798a0300f3cc3545bad333d14d37c682b61b67d3cbf185f9d40c356c17491ff8288706551a2da46
6
+ metadata.gz: 8da3e2b81089bf418c16900e0db39144b7f0bb39a9cbebd2bed4d6a5f4272940ccc02d65b8b55a629a38c121522caa46dda963145311fc052cf2d6be01dc2514
7
+ data.tar.gz: af51998f0fbe47a2f7e97e576d7e22fb9721ad81cf84c73d8bb6052487c1e1cbb795d62a0d88058924f28b60270c2a1429ed2551b8c0c1c591570e2b28a0d663
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.2.4
2
+ - Maintain cursor position on Buffer#append for compatibility with vim
3
+ - Fix excessive fetching of API metadata
4
+
1
5
  # 0.2.3
2
6
  - Detach child processes in `Neovim::EventLoop.child`
3
7
  - Improve performance/compatibility of `Buffer#append`
@@ -11,6 +11,8 @@ module Neovim
11
11
  class AsyncSession
12
12
  include Logging
13
13
 
14
+ attr_reader :msgpack_stream
15
+
14
16
  def initialize(msgpack_stream)
15
17
  @msgpack_stream = msgpack_stream
16
18
  @request_id = 0
@@ -59,8 +61,8 @@ module Neovim
59
61
  # @return [void]
60
62
  # @see MsgpackStream#run
61
63
  # @see EventLoop#run
62
- def run(session=nil, &callback)
63
- @msgpack_stream.run(session) do |msg|
64
+ def run(&callback)
65
+ @msgpack_stream.run do |msg|
64
66
  debug("received #{msg.inspect}")
65
67
  kind, *payload = msg
66
68
 
data/lib/neovim/buffer.rb CHANGED
@@ -93,14 +93,21 @@ module Neovim
93
93
 
94
94
  # Append a line after the given line (1-indexed).
95
95
  #
96
+ # To maintain backwards compatibility with +vim+, the cursor is forced back
97
+ # to its previous position after inserting the line.
98
+ #
96
99
  # @param index [Fixnum]
97
100
  # @param str [String]
98
101
  # @return [String]
99
102
  def append(index, str)
103
+ window = @session.request(:vim_get_current_window)
104
+ cursor = window.cursor
105
+
100
106
  if index < 0
101
107
  raise ArgumentError, "Index out of bounds"
102
108
  else
103
- lines.insert(index, str)
109
+ set_lines(index, index, true, [str])
110
+ window.set_cursor(cursor)
104
111
  end
105
112
  str
106
113
  end
@@ -114,7 +114,7 @@ module Neovim
114
114
  end
115
115
 
116
116
  # @param index [Fixnum]
117
- # @param line [String]
117
+ # @param lines [String]
118
118
  def insert(index, lines)
119
119
  @buffer.insert(index, Array(lines))
120
120
  end
@@ -32,9 +32,7 @@ module Neovim
32
32
  # described by the +vim_get_api_info+ call
33
33
  # @return [void]
34
34
  # @see EventLoop#run
35
- def run(session=nil)
36
- register_types(session)
37
-
35
+ def run
38
36
  @event_loop.run do |data|
39
37
  @unpacker.feed_each(data) do |msg|
40
38
  debug("received #{msg.inspect}")
@@ -62,12 +60,14 @@ module Neovim
62
60
  @event_loop.shutdown
63
61
  end
64
62
 
65
- private
66
-
67
- def register_types(session)
68
- return unless session && session.api
69
-
70
- session.api.types.each do |type, info|
63
+ # Register msgpack ext types using the provided API and session
64
+ #
65
+ # @param api [API]
66
+ # @param session [Session]
67
+ # @see Session#discover_api
68
+ def register_types(api, session)
69
+ info("registering msgpack ext types")
70
+ api.types.each do |type, info|
71
71
  klass = Neovim.const_get(type)
72
72
  id = info.fetch("id")
73
73
 
@@ -73,12 +73,15 @@ module Neovim
73
73
  @api ||= API.null
74
74
  end
75
75
 
76
- # Discover the +nvim+ API as described in the +vim_get_api_info+ call.
76
+ # Discover the +nvim+ API as described in the +vim_get_api_info+ call,
77
+ # propagating it down to lower layers of the stack.
77
78
  #
78
79
  # @return [API]
79
80
  # @see API
80
81
  def discover_api
81
- @api = API.new(request(:vim_get_api_info))
82
+ @api = API.new(request(:vim_get_api_info)).tap do |api|
83
+ @async_session.msgpack_stream.register_types(api, self)
84
+ end
82
85
  end
83
86
 
84
87
  # Run the event loop, handling messages in a +Fiber+.
@@ -97,7 +100,7 @@ module Neovim
97
100
 
98
101
  return unless @running
99
102
 
100
- @async_session.run(self) do |message|
103
+ @async_session.run do |message|
101
104
  Fiber.new { yield message if block_given? }.resume
102
105
  end
103
106
  ensure
@@ -186,7 +189,7 @@ module Neovim
186
189
  @async_session.request(method, *args) do |err, res|
187
190
  error, result = err, res
188
191
  stop
189
- end.run(self) do |message|
192
+ end.run do |message|
190
193
  @pending_messages << message
191
194
  end
192
195
 
@@ -1,3 +1,3 @@
1
1
  module Neovim
2
- VERSION = Gem::Version.new("0.2.3")
2
+ VERSION = Gem::Version.new("0.2.4")
3
3
  end
data/lib/neovim/window.rb CHANGED
@@ -2,14 +2,6 @@ require "neovim/remote_object"
2
2
 
3
3
  module Neovim
4
4
  class Window < RemoteObject
5
- # Interface for interacting with the cursor position.
6
- #
7
- # @return [Cursor]
8
- # @see Cursor
9
- def cursor
10
- @cursor ||= Cursor.new(self)
11
- end
12
-
13
5
  # Get the buffer displayed in the window
14
6
  #
15
7
  # @return [Buffer]
@@ -1,10 +1,41 @@
1
1
  require "helper"
2
+ require "pty"
2
3
 
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
+ yielded = false
19
+
20
+ PTY.spawn(host_exe) do |rd, wr, pid|
21
+ yielded = true
22
+ expect(rd.gets).to match(/can't run.+interactively/i)
23
+
24
+ _, status = Process.waitpid2(pid)
25
+ expect(status.exitstatus).to be(1)
26
+ end
27
+
28
+ expect(yielded).to be(true)
29
+ end
30
+
4
31
  it "loads and runs plugins from Ruby source files" do
5
- plugin1_path = Support.file_path("plugin1.rb")
6
- File.write(plugin1_path, <<-RUBY)
32
+ plugin_path = Support.file_path("plugin1.rb")
33
+ File.write(plugin_path, <<-RUBY)
7
34
  Neovim.plugin do |plug|
35
+ plug.command(:AsyncSetLine, :args => 1) do |nvim, str|
36
+ nvim.current.line = str
37
+ end
38
+
8
39
  plug.function(:SyncAdd, :args => 2, :sync => true) do |nvim, x, y|
9
40
  x + y
10
41
  end
@@ -12,15 +43,6 @@ RSpec.describe "neovim-ruby-host" do
12
43
  plug.autocmd(:BufEnter, :pattern => "*.rb") do |nvim|
13
44
  nvim.current.line = "Ruby file, eh?"
14
45
  end
15
- end
16
- RUBY
17
-
18
- plugin2_path = Support.file_path("plugin2.rb")
19
- File.write(plugin2_path, <<-RUBY)
20
- Neovim.plugin do |plug|
21
- plug.command(:AsyncSetLine, :args => 1) do |nvim, str|
22
- nvim.current.line = str
23
- end
24
46
 
25
47
  plug.rpc(:TopLevelAdd, :nargs => 2, :sync => true) do |nvim, x, y|
26
48
  x + y
@@ -30,21 +52,20 @@ RSpec.describe "neovim-ruby-host" do
30
52
 
31
53
  nvim = Neovim.attach_child(["nvim", "-u", "NONE", "-n"])
32
54
 
33
- host_exe = File.expand_path("../../../bin/neovim-ruby-host", __FILE__)
34
- nvim.command("let host = rpcstart('#{host_exe}', ['#{plugin1_path}', '#{plugin2_path}'])")
55
+ nvim.command("let host = rpcstart('#{host_exe}', ['#{plugin_path}'])")
35
56
 
36
57
  expect(nvim.eval("rpcrequest(host, 'poll')")).to eq("ok")
37
- expect(nvim.eval("rpcrequest(host, '#{plugin1_path}:function:SyncAdd', [1, 2])")).to eq(3)
58
+ expect(nvim.eval("rpcrequest(host, '#{plugin_path}:function:SyncAdd', [1, 2])")).to eq(3)
38
59
  expect(nvim.eval("rpcrequest(host, 'TopLevelAdd', 1, 2)")).to eq(3)
39
60
 
40
61
  expect {
41
- nvim.command("call rpcnotify(host, '#{plugin1_path}:autocmd:BufEnter:*.rb')")
42
- sleep 0.1
62
+ nvim.command("call rpcnotify(host, '#{plugin_path}:autocmd:BufEnter:*.rb')")
63
+ sleep 0.01
43
64
  }.to change { nvim.current.buffer.lines.to_a }.from([""]).to(["Ruby file, eh?"])
44
65
 
45
66
  expect {
46
- nvim.command("call rpcnotify(host, '#{plugin2_path}:command:AsyncSetLine', ['foo'])")
47
- sleep 0.1
67
+ nvim.command("call rpcnotify(host, '#{plugin_path}:command:AsyncSetLine', ['foo'])")
68
+ sleep 0.01
48
69
  }.to change { nvim.current.buffer.lines.to_a }.from(["Ruby file, eh?"]).to(["foo"])
49
70
 
50
71
  expect {
@@ -15,7 +15,7 @@ RSpec.describe "ruby_provider" do
15
15
  begin
16
16
  spec.run
17
17
  ensure
18
- nvim.command("call rpcstop(host) | qa!")
18
+ nvim.session.shutdown
19
19
  end
20
20
  end
21
21
 
data/spec/helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "bundler/setup"
2
2
  require "neovim"
3
3
  require "pry"
4
+ require "stringio"
4
5
  require "timeout"
5
6
 
6
7
  require File.expand_path("../support.rb", __FILE__)
@@ -35,8 +36,18 @@ RSpec.configure do |config|
35
36
  end
36
37
  end
37
38
 
39
+ config.around(:example, :silence_logging) do |spec|
40
+ old_logger = Neovim.logger
41
+
42
+ begin
43
+ Neovim.logger = Logger.new(StringIO.new)
44
+ spec.run
45
+ ensure
46
+ Neovim.logger = old_logger
47
+ end
48
+ end
49
+
38
50
  Kernel.srand config.seed
39
51
  end
40
52
 
41
- Neovim.logger.level = Logger::FATAL
42
53
  Thread.abort_on_exception = true
@@ -118,6 +118,12 @@ module Neovim
118
118
  }.to change { buffer.lines.to_a }.to(["one", "two", ""])
119
119
  end
120
120
 
121
+ it "leaves the cursor unchanged" do
122
+ expect {
123
+ buffer.append(0, "one")
124
+ }.not_to change { client.current.window.cursor }
125
+ end
126
+
121
127
  it "raises for out of bounds indexes" do
122
128
  expect {
123
129
  buffer.append(-1, "err")
@@ -5,6 +5,12 @@ module Neovim
5
5
  let(:client) { Neovim.attach_child(["nvim", "-n", "-u", "NONE"]) }
6
6
  after { client.shutdown }
7
7
 
8
+ specify do
9
+ client.strwidth("foo")
10
+ client.strwidth("bar")
11
+ client.command("echom 'hi'")
12
+ end
13
+
8
14
  describe "#respond_to?" do
9
15
  it "returns true for vim functions" do
10
16
  expect(client).to respond_to(:strwidth)
@@ -98,7 +98,7 @@ module Neovim
98
98
  host.handle(message)
99
99
  end
100
100
 
101
- it "rescues plugin sync handler exceptions" do
101
+ it "rescues plugin sync handler exceptions", :silence_logging do
102
102
  plugin = Plugin.from_config_block("source") do |plug|
103
103
  plug.command(:Foo, :sync => true) { raise "BOOM" }
104
104
  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.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Genco
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-23 00:00:00.000000000 Z
11
+ date: 2016-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack