neovim 0.2.4 → 0.2.5

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: 65ebef25a57b7d4e244b65fbceb840bd8b1102f3
4
- data.tar.gz: 152c9fbe48f7a50594be2abe6551e41a576808a1
3
+ metadata.gz: 94299b85fc9c539d812062822342c89a47b0d829
4
+ data.tar.gz: 225a197bab993d300596743292de0823ee994e9a
5
5
  SHA512:
6
- metadata.gz: 8da3e2b81089bf418c16900e0db39144b7f0bb39a9cbebd2bed4d6a5f4272940ccc02d65b8b55a629a38c121522caa46dda963145311fc052cf2d6be01dc2514
7
- data.tar.gz: af51998f0fbe47a2f7e97e576d7e22fb9721ad81cf84c73d8bb6052487c1e1cbb795d62a0d88058924f28b60270c2a1429ed2551b8c0c1c591570e2b28a0d663
6
+ metadata.gz: c641e29939e3f02a8e788cbf88e7b6eb4c4310a19b0825f86cebef93a33bbe62658fa48518c46c3d43a8d270eda169ec3e45355fc7becd38235189d637c18b0b
7
+ data.tar.gz: 83d1e66f8ff9fa729223a12a063e3b3268894d7a1d004b2bedb0c9da8e416cb7043f955f5d1bfc8c05ccf88e6a88c10567949f237c7fb3f5f127d37f74289f6f
@@ -1,3 +1,8 @@
1
+ # 0.2.5
2
+ - Optimize remote function lookup
3
+ - Fix bug where $curbuf and $curwin weren't persisting instance state between
4
+ requests
5
+
1
6
  # 0.2.4
2
7
  - Maintain cursor position on Buffer#append for compatibility with vim
3
8
  - Fix excessive fetching of API metadata
data/README.md CHANGED
@@ -70,6 +70,8 @@ end
70
70
 
71
71
  Ruby plugins go in the `$VIMRUNTIME/rplugin/ruby` directory, and are auto-loaded after calling `:UpdateRemotePlugins`. Refer to the [`Neovim::Plugin::DSL` docs](http://www.rubydoc.info/github/alexgenco/neovim-ruby/master/Neovim/Plugin/DSL) for a more complete overview.
72
72
 
73
+ The Neovim gem also acts as a compatibility layer for Ruby plugins written for legacy `vim`. The `:ruby`, `:rubyfile`, and `:rubydo` commands are intended to behave the same as they did in `vim`, and their documentation can be found [here](https://neovim.io/doc/user/if_ruby.html).
74
+
73
75
  ## Links
74
76
 
75
77
  * Source: <http://github.com/alexgenco/neovim-ruby>
@@ -1,6 +1,8 @@
1
1
  module Neovim
2
2
  # @api private
3
3
  class API
4
+ attr_reader :channel_id
5
+
4
6
  # Represents an unknown API. Used as a stand-in when the API hasn't been
5
7
  # discovered yet via the +vim_get_api_info+ RPC call.
6
8
  #
@@ -9,17 +11,19 @@ module Neovim
9
11
  new([nil, {"functions" => [], "types" => []}])
10
12
  end
11
13
 
12
- def initialize(data)
13
- @data = data
14
+ def initialize(api_info)
15
+ @channel_id, @api_info = api_info
14
16
  end
15
17
 
16
- # Return all functions defined by the API, as +Function+ objects.
18
+ # Return all functions defined by the API.
17
19
  #
18
- # @return [Array<Function>]
20
+ # @return [Hash{String => Function}] A +Hash+ mapping function names to
21
+ # +Function+ objects.
19
22
  # @see Function
20
23
  def functions
21
- @functions ||= @data.fetch(1).fetch("functions").map do |func|
22
- Function.new(func["name"], func["async"])
24
+ @functions ||= @api_info.fetch("functions").inject({}) do |acc, func|
25
+ name, async = func.values_at("name", "async")
26
+ acc.merge(name => Function.new(name, async))
23
27
  end
24
28
  end
25
29
 
@@ -28,14 +32,7 @@ module Neovim
28
32
  #
29
33
  # @return [Hash]
30
34
  def types
31
- @types ||= @data.fetch(1).fetch("types")
32
- end
33
-
34
- # Return the channel ID of the current RPC session.
35
- #
36
- # @return [Fixnum, nil]
37
- def channel_id
38
- @channel_id ||= @data.fetch(0)
35
+ @types ||= @api_info.fetch("types")
39
36
  end
40
37
 
41
38
  # Return a list of functions with the given name prefix.
@@ -43,8 +40,8 @@ module Neovim
43
40
  # @param prefix [String] The function prefix
44
41
  # @return [Array<Function>]
45
42
  def functions_with_prefix(prefix)
46
- functions.select do |function|
47
- function.name =~ /\A#{prefix}/
43
+ functions.inject([]) do |acc, (name, function)|
44
+ name =~ /\A#{prefix}/ ? acc.push(function) : acc
48
45
  end
49
46
  end
50
47
 
@@ -53,9 +50,7 @@ module Neovim
53
50
  # @param name [String] The name of the function
54
51
  # @return [Function, nil]
55
52
  def function(name)
56
- functions.find do |func|
57
- func.name == name.to_s
58
- end
53
+ functions[name.to_s]
59
54
  end
60
55
 
61
56
  # Truncate the output of inspect so console sessions are more pleasant.
@@ -3,51 +3,65 @@ require "neovim/plugin/handler"
3
3
  module Neovim
4
4
  class Plugin
5
5
  # The DSL exposed in +Neovim.plugin+ blocks.
6
+ #
7
+ # @api public
6
8
  class DSL < BasicObject
7
9
  def initialize(plugin)
8
10
  @plugin = plugin
9
11
  end
10
12
 
11
- # Register an +nvim+ command.
13
+ # Register an +nvim+ command. See +:h command+.
12
14
  #
13
- # @param name [String]
14
- # @param options [Hash]
15
- # @param &block [Proc, nil]
15
+ # @param name [String] The name of the command.
16
+ # @param options [Hash] Command options.
17
+ # @param &block [Proc, nil] The body of the command.
16
18
  #
17
- # @option options [Fixnum] :nargs
18
- # @option options [Fixnum] :count
19
- # @option options [String] :eval
20
- # @option options [Boolean] :sync (false)
21
- # @option options [Boolean] :bang
22
- # @option options [Boolean] :register
23
- # @option options [Boolean] :complete
24
- # @option options [String, Boolean] :range
19
+ # @option options [Fixnum] :nargs The number of arguments to accept. See
20
+ # +:h command-nargs+.
21
+ # @option options [String, Boolean] :range The range argument.
22
+ # See +:h command-range+.
23
+ # @option options [Fixnum] :count The default count argument.
24
+ # See +:h command-count+.
25
+ # @option options [Boolean] :bang Whether the command can take a +!+
26
+ # modifier. See +:h command-bang+.
27
+ # @option options [Boolean] :register Whether the command can accept a
28
+ # register name. See +:h command-register+.
29
+ # @option options [Boolean] :complete Set the completion attributes of
30
+ # the command. See +:h command-completion+.
31
+ # @option options [String] :eval An +nvim+ expression. Gets evaluated and
32
+ # passed as an argument to the block.
33
+ # @option options [Boolean] :sync (false) Whether +nvim+ should receive
34
+ # the return value of the block.
25
35
  def command(name, options={}, &block)
26
36
  register_handler(:command, name, options, block)
27
37
  end
28
38
 
29
- # Register an +nvim+ function.
39
+ # Register an +nvim+ function. See +:h function+.
30
40
  #
31
- # @param name [String]
32
- # @param options [Hash]
33
- # @param &block [Proc, nil]
41
+ # @param name [String] The name of the function.
42
+ # @param options [Hash] Function options.
43
+ # @param &block [Proc, nil] The body of the function.
34
44
  #
35
- # @option options [String] :eval
36
- # @option options [Boolean] :sync (false)
37
- # @option options [String, Boolean] :range
45
+ # @option options [String, Boolean] :range The range argument.
46
+ # See +:h command-range+.
47
+ # @option options [String] :eval An +nvim+ expression. Gets evaluated and
48
+ # passed as an argument to the block.
49
+ # @option options [Boolean] :sync (false) Whether +nvim+ should receive
50
+ # the return value of the block.
38
51
  def function(name, options={}, &block)
39
52
  register_handler(:function, name, options, block)
40
53
  end
41
54
 
42
- # Register an +nvim+ autocmd.
55
+ # Register an +nvim+ autocmd. See +:h autocmd+.
43
56
  #
44
- # @param event [String]
45
- # @param options [Hash]
46
- # @param &block [Proc, nil]
57
+ # @param event [String] The event type. See +:h autocmd-events+
58
+ # @param options [Hash] Autocmd options.
59
+ # @param &block [Proc, nil] The body of the autocmd.
47
60
  #
48
- # @option options [String] :pattern
49
- # @option options [String] :eval
50
- # @option options [Boolean] :sync (false)
61
+ # @option options [String] :pattern The buffer name pattern.
62
+ # See +:h autocmd-patterns+.
63
+ # @option options [String] :eval An +nvim+ expression. Gets evaluated and
64
+ # passed as an argument to the block.
51
65
  def autocmd(event, options={}, &block)
52
66
  register_handler(:autocmd, event, options, block)
53
67
  end
@@ -57,7 +71,8 @@ module Neovim
57
71
  # This can be used to directly expose an RPC call without a namespace.
58
72
  # This is used primarily for exposing legacy ruby provider calls.
59
73
  #
60
- # @option options [Boolean] :sync (false)
74
+ # @option options [Boolean] :sync (false) Whether +nvim+ should receive
75
+ # the return value of the block.
61
76
  def rpc(name, options={}, &block)
62
77
  sync = options.delete(:sync)
63
78
 
@@ -84,8 +84,20 @@ module Neovim
84
84
 
85
85
  # @api private
86
86
  def self.__with_globals(client)
87
- $curbuf = client.get_current_buffer
88
- $curwin = client.get_current_window
87
+ @__buffer_cache ||= {}
88
+ @__window_cache ||= {}
89
+
90
+ __bufnr = client.evaluate("bufnr('%')")
91
+ __winnr = client.evaluate("winnr()")
92
+
93
+ $curbuf = @__buffer_cache.fetch(__bufnr) do
94
+ @__buffer_cache[__bufnr] = client.get_current_buffer
95
+ end
96
+
97
+ $curwin = @__window_cache.fetch(__winnr) do
98
+ @__window_cache[__winnr] = client.get_current_window
99
+ end
100
+
89
101
  yield
90
102
  end
91
103
  private_class_method :__with_globals
@@ -1,3 +1,3 @@
1
1
  module Neovim
2
- VERSION = Gem::Version.new("0.2.4")
2
+ VERSION = Gem::Version.new("0.2.5")
3
3
  end
@@ -49,6 +49,18 @@ RSpec.describe "ruby_provider" do
49
49
  nvim.eval("rpcrequest(host, 'ruby_execute', 'foo')")
50
50
  expect(nvim.get_var("called")).to be(1)
51
51
  end
52
+
53
+ it "persists instance state in globals" do
54
+ 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)}\")')")
56
+
57
+ expect(nvim.get_var("foo")).to be(123)
58
+
59
+ nvim.eval("rpcrequest(host, 'ruby_execute', '$curwin.instance_variable_set(:@foo, 456)')")
60
+ nvim.eval("rpcrequest(host, 'ruby_execute', 'VIM.command(\"let g:foo = \#{$curwin.instance_variable_get(:@foo)}\")')")
61
+
62
+ expect(nvim.get_var("foo")).to be(456)
63
+ end
52
64
  end
53
65
 
54
66
  describe "ruby_execute_file" do
@@ -6,8 +6,8 @@ module Neovim
6
6
  it "returns an empty API object" do
7
7
  api = API.null
8
8
 
9
- expect(api.types).to eq([])
10
- expect(api.functions).to eq([])
9
+ expect(api.types).to be_empty
10
+ expect(api.functions).to be_empty
11
11
  end
12
12
  end
13
13
 
@@ -29,10 +29,14 @@ module Neovim
29
29
  describe "#functions_with_prefix" do
30
30
  it "returns relevant functions" do
31
31
  api = API.new(
32
- [nil, {"functions" => [{"name" => "vim_strwidth"}]}]
32
+ [nil, {"functions" => [
33
+ {"name" => "vim_strwidth"},
34
+ {"name" => "buffer_get_lines"}
35
+ ]}]
33
36
  )
34
37
 
35
38
  functions = api.functions_with_prefix("vim_")
39
+ expect(functions.size).to be(1)
36
40
  expect(functions.first.name).to eq("vim_strwidth")
37
41
  end
38
42
  end
@@ -87,10 +87,9 @@ module Neovim
87
87
  response = nil
88
88
  event_loop.write(input).run do |msg|
89
89
  response = msg
90
- event_loop.stop
90
+ event_loop.shutdown
91
91
  end
92
92
 
93
- event_loop.shutdown
94
93
  expect(response).to eq(MessagePack.pack([1, 0, nil, 2]))
95
94
  end
96
95
  end
@@ -10,13 +10,13 @@ RSpec.describe Neovim do
10
10
  pid = Process.spawn(env, *nvim_argv, [:out, :err] => "/dev/null")
11
11
 
12
12
  begin
13
- TCPSocket.open("0.0.0.0", port).close
13
+ client = Neovim.attach_tcp("0.0.0.0", port)
14
14
  rescue Errno::ECONNREFUSED
15
15
  retry
16
16
  end
17
17
 
18
18
  begin
19
- expect(Neovim.attach_tcp("0.0.0.0", port).strwidth("hi")).to eq(2)
19
+ expect(client.strwidth("hi")).to eq(2)
20
20
  ensure
21
21
  Process.kill(:TERM, pid)
22
22
  Process.waitpid(pid)
@@ -31,13 +31,13 @@ RSpec.describe Neovim do
31
31
  pid = Process.spawn(env, *nvim_argv, [:out, :err] => "/dev/null")
32
32
 
33
33
  begin
34
- UNIXSocket.new(socket_path).close
34
+ client = Neovim.attach_unix(socket_path)
35
35
  rescue Errno::ENOENT, Errno::ECONNREFUSED
36
36
  retry
37
37
  end
38
38
 
39
39
  begin
40
- expect(Neovim.attach_unix(socket_path).strwidth("hi")).to eq(2)
40
+ expect(client.strwidth("hi")).to eq(2)
41
41
  ensure
42
42
  Process.kill(:TERM, pid)
43
43
  Process.waitpid(pid)
@@ -11,7 +11,12 @@ module Support
11
11
 
12
12
  def self.port
13
13
  server = TCPServer.new("0.0.0.0", 0)
14
- server.addr[1].tap { server.close }
14
+
15
+ begin
16
+ server.addr[1]
17
+ ensure
18
+ server.close
19
+ end
15
20
  end
16
21
 
17
22
  def self.file_path(name)
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.4
4
+ version: 0.2.5
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-08-07 00:00:00.000000000 Z
11
+ date: 2016-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack