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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +2 -0
- data/lib/neovim/api.rb +14 -19
- data/lib/neovim/plugin/dsl.rb +42 -27
- data/lib/neovim/ruby_provider.rb +14 -2
- data/lib/neovim/version.rb +1 -1
- data/spec/acceptance/ruby_provider_spec.rb +12 -0
- data/spec/neovim/api_spec.rb +7 -3
- data/spec/neovim/event_loop_spec.rb +1 -2
- data/spec/neovim_spec.rb +4 -4
- data/spec/support.rb +6 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94299b85fc9c539d812062822342c89a47b0d829
|
4
|
+
data.tar.gz: 225a197bab993d300596743292de0823ee994e9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c641e29939e3f02a8e788cbf88e7b6eb4c4310a19b0825f86cebef93a33bbe62658fa48518c46c3d43a8d270eda169ec3e45355fc7becd38235189d637c18b0b
|
7
|
+
data.tar.gz: 83d1e66f8ff9fa729223a12a063e3b3268894d7a1d004b2bedb0c9da8e416cb7043f955f5d1bfc8c05ccf88e6a88c10567949f237c7fb3f5f127d37f74289f6f
|
data/CHANGELOG.md
CHANGED
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>
|
data/lib/neovim/api.rb
CHANGED
@@ -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(
|
13
|
-
@
|
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
|
18
|
+
# Return all functions defined by the API.
|
17
19
|
#
|
18
|
-
# @return [
|
20
|
+
# @return [Hash{String => Function}] A +Hash+ mapping function names to
|
21
|
+
# +Function+ objects.
|
19
22
|
# @see Function
|
20
23
|
def functions
|
21
|
-
@functions ||= @
|
22
|
-
|
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 ||= @
|
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.
|
47
|
-
|
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.
|
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.
|
data/lib/neovim/plugin/dsl.rb
CHANGED
@@ -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
|
-
#
|
19
|
-
# @option options [String] :
|
20
|
-
#
|
21
|
-
# @option options [
|
22
|
-
#
|
23
|
-
# @option options [Boolean] :
|
24
|
-
#
|
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] :
|
36
|
-
#
|
37
|
-
# @option options [String
|
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
|
-
#
|
50
|
-
# @option options [
|
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
|
|
data/lib/neovim/ruby_provider.rb
CHANGED
@@ -84,8 +84,20 @@ module Neovim
|
|
84
84
|
|
85
85
|
# @api private
|
86
86
|
def self.__with_globals(client)
|
87
|
-
|
88
|
-
|
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
|
data/lib/neovim/version.rb
CHANGED
@@ -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
|
data/spec/neovim/api_spec.rb
CHANGED
@@ -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
|
10
|
-
expect(api.functions).to
|
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" => [
|
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
|
data/spec/neovim_spec.rb
CHANGED
@@ -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
|
-
|
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(
|
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
|
-
|
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(
|
40
|
+
expect(client.strwidth("hi")).to eq(2)
|
41
41
|
ensure
|
42
42
|
Process.kill(:TERM, pid)
|
43
43
|
Process.waitpid(pid)
|
data/spec/support.rb
CHANGED
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
|
+
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-
|
11
|
+
date: 2016-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|