neovim 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +3 -0
- data/Rakefile +5 -0
- data/lib/neovim.rb +1 -1
- data/lib/neovim/buffer.rb +55 -55
- data/lib/neovim/client.rb +20 -19
- data/lib/neovim/current.rb +6 -6
- data/lib/neovim/host.rb +1 -0
- data/lib/neovim/line_range.rb +8 -8
- data/lib/neovim/plugin.rb +7 -1
- data/lib/neovim/plugin/dsl.rb +15 -5
- data/lib/neovim/ruby_provider.rb +18 -1
- data/lib/neovim/session/event_loop.rb +2 -2
- data/lib/neovim/tabpage.rb +9 -9
- data/lib/neovim/version.rb +1 -1
- data/lib/neovim/window.rb +27 -27
- data/script/dump_api +10 -0
- data/script/generate_docs +3 -2
- data/spec/acceptance/ruby_provider_spec.rb +72 -0
- data/spec/helper.rb +11 -5
- data/spec/neovim/current_spec.rb +3 -3
- data/spec/neovim/host_spec.rb +18 -0
- data/spec/neovim/plugin_spec.rb +18 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4fecc46a144d9fa3d537f9b0f9ed7da0a89e0c3
|
4
|
+
data.tar.gz: e8d246f7011bc118ba28706306065b823d18fb12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1367f6f99b864818ddc7b98f6ffd04b8e3795cc3f797deed986ba8c86f3bc880c5be66d5b1bd7b17a6c7877a7b554ef944bbee473af3d30345055ce41925a06
|
7
|
+
data.tar.gz: 6b67c6c0163aea888f5131e4cad4bc5c7bc3c7765462569a5fc37251b4d5d6482a77b01b9a06878b22a9c7c0523fe17bc0b04ca18daf64f7f6ca7dd8702381fd
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Rakefile
CHANGED
data/lib/neovim.rb
CHANGED
@@ -56,7 +56,7 @@ module Neovim
|
|
56
56
|
# Connect to a running +nvim+ instance over TCP.
|
57
57
|
#
|
58
58
|
# @param host [String] The hostname or IP address
|
59
|
-
# @param port [
|
59
|
+
# @param port [Integer] The port
|
60
60
|
# @return [Client]
|
61
61
|
# @see Session.tcp
|
62
62
|
def self.attach_tcp(host, port)
|
data/lib/neovim/buffer.rb
CHANGED
@@ -47,28 +47,28 @@ module Neovim
|
|
47
47
|
|
48
48
|
# Get the buffer index.
|
49
49
|
#
|
50
|
-
# @return [
|
50
|
+
# @return [Integer]
|
51
51
|
def number
|
52
52
|
get_number
|
53
53
|
end
|
54
54
|
|
55
55
|
# Get the number of lines.
|
56
56
|
#
|
57
|
-
# @return [
|
57
|
+
# @return [Integer]
|
58
58
|
def count
|
59
59
|
line_count
|
60
60
|
end
|
61
61
|
|
62
62
|
# Get the number of lines.
|
63
63
|
#
|
64
|
-
# @return [
|
64
|
+
# @return [Integer]
|
65
65
|
def length
|
66
66
|
count
|
67
67
|
end
|
68
68
|
|
69
69
|
# Get the given line (1-indexed).
|
70
70
|
#
|
71
|
-
# @param index [
|
71
|
+
# @param index [Integer]
|
72
72
|
# @return [String]
|
73
73
|
def [](index)
|
74
74
|
lines[index-1]
|
@@ -76,7 +76,7 @@ module Neovim
|
|
76
76
|
|
77
77
|
# Set the given line (1-indexed).
|
78
78
|
#
|
79
|
-
# @param index [
|
79
|
+
# @param index [Integer]
|
80
80
|
# @param str [String]
|
81
81
|
# @return [String]
|
82
82
|
def []=(index, str)
|
@@ -85,7 +85,7 @@ module Neovim
|
|
85
85
|
|
86
86
|
# Delete the given line (1-indexed).
|
87
87
|
#
|
88
|
-
# @param index [
|
88
|
+
# @param index [Integer]
|
89
89
|
# @return [void]
|
90
90
|
def delete(index)
|
91
91
|
lines.delete(index-1)
|
@@ -96,7 +96,7 @@ module Neovim
|
|
96
96
|
# To maintain backwards compatibility with +vim+, the cursor is forced back
|
97
97
|
# to its previous position after inserting the line.
|
98
98
|
#
|
99
|
-
# @param index [
|
99
|
+
# @param index [Integer]
|
100
100
|
# @param str [String]
|
101
101
|
# @return [String]
|
102
102
|
def append(index, str)
|
@@ -133,7 +133,7 @@ module Neovim
|
|
133
133
|
|
134
134
|
# Get the current line number of an active buffer.
|
135
135
|
#
|
136
|
-
# @return [
|
136
|
+
# @return [Integer, nil]
|
137
137
|
def line_number
|
138
138
|
if active?
|
139
139
|
window = @session.request(:vim_get_current_window)
|
@@ -150,63 +150,39 @@ module Neovim
|
|
150
150
|
|
151
151
|
# The following methods are dynamically generated.
|
152
152
|
=begin
|
153
|
-
@method line_count
|
154
|
-
Send the +buffer_line_count+ RPC to +nvim+
|
155
|
-
@return [Fixnum]
|
156
|
-
|
157
153
|
@method get_line(index)
|
158
154
|
Send the +buffer_get_line+ RPC to +nvim+
|
159
|
-
@param [
|
155
|
+
@param [Integer] index
|
160
156
|
@return [String]
|
161
157
|
|
162
158
|
@method set_line(index, line)
|
163
159
|
Send the +buffer_set_line+ RPC to +nvim+
|
164
|
-
@param [
|
160
|
+
@param [Integer] index
|
165
161
|
@param [String] line
|
166
162
|
@return [void]
|
167
163
|
|
168
164
|
@method del_line(index)
|
169
165
|
Send the +buffer_del_line+ RPC to +nvim+
|
170
|
-
@param [
|
166
|
+
@param [Integer] index
|
171
167
|
@return [void]
|
172
168
|
|
173
169
|
@method get_line_slice(start, end, include_start, include_end)
|
174
170
|
Send the +buffer_get_line_slice+ RPC to +nvim+
|
175
|
-
@param [
|
176
|
-
@param [
|
171
|
+
@param [Integer] start
|
172
|
+
@param [Integer] end
|
177
173
|
@param [Boolean] include_start
|
178
174
|
@param [Boolean] include_end
|
179
175
|
@return [Array<String>]
|
180
176
|
|
181
|
-
@method get_lines(start, end, strict_indexing)
|
182
|
-
Send the +buffer_get_lines+ RPC to +nvim+
|
183
|
-
@param [Fixnum] start
|
184
|
-
@param [Fixnum] end
|
185
|
-
@param [Boolean] strict_indexing
|
186
|
-
@return [Array<String>]
|
187
|
-
|
188
177
|
@method set_line_slice(start, end, include_start, include_end, replacement)
|
189
178
|
Send the +buffer_set_line_slice+ RPC to +nvim+
|
190
|
-
@param [
|
191
|
-
@param [
|
179
|
+
@param [Integer] start
|
180
|
+
@param [Integer] end
|
192
181
|
@param [Boolean] include_start
|
193
182
|
@param [Boolean] include_end
|
194
183
|
@param [Array<String>] replacement
|
195
184
|
@return [void]
|
196
185
|
|
197
|
-
@method set_lines(start, end, strict_indexing, replacement)
|
198
|
-
Send the +buffer_set_lines+ RPC to +nvim+
|
199
|
-
@param [Fixnum] start
|
200
|
-
@param [Fixnum] end
|
201
|
-
@param [Boolean] strict_indexing
|
202
|
-
@param [Array<String>] replacement
|
203
|
-
@return [void]
|
204
|
-
|
205
|
-
@method get_var(name)
|
206
|
-
Send the +buffer_get_var+ RPC to +nvim+
|
207
|
-
@param [String] name
|
208
|
-
@return [Object]
|
209
|
-
|
210
186
|
@method set_var(name, value)
|
211
187
|
Send the +buffer_set_var+ RPC to +nvim+
|
212
188
|
@param [String] name
|
@@ -218,6 +194,36 @@ module Neovim
|
|
218
194
|
@param [String] name
|
219
195
|
@return [Object]
|
220
196
|
|
197
|
+
@method insert(lnum, lines)
|
198
|
+
Send the +buffer_insert+ RPC to +nvim+
|
199
|
+
@param [Integer] lnum
|
200
|
+
@param [Array<String>] lines
|
201
|
+
@return [void]
|
202
|
+
|
203
|
+
@method line_count
|
204
|
+
Send the +buffer_line_count+ RPC to +nvim+
|
205
|
+
@return [Integer]
|
206
|
+
|
207
|
+
@method get_lines(start, end, strict_indexing)
|
208
|
+
Send the +buffer_get_lines+ RPC to +nvim+
|
209
|
+
@param [Integer] start
|
210
|
+
@param [Integer] end
|
211
|
+
@param [Boolean] strict_indexing
|
212
|
+
@return [Array<String>]
|
213
|
+
|
214
|
+
@method set_lines(start, end, strict_indexing, replacement)
|
215
|
+
Send the +buffer_set_lines+ RPC to +nvim+
|
216
|
+
@param [Integer] start
|
217
|
+
@param [Integer] end
|
218
|
+
@param [Boolean] strict_indexing
|
219
|
+
@param [Array<String>] replacement
|
220
|
+
@return [void]
|
221
|
+
|
222
|
+
@method get_var(name)
|
223
|
+
Send the +buffer_get_var+ RPC to +nvim+
|
224
|
+
@param [String] name
|
225
|
+
@return [Object]
|
226
|
+
|
221
227
|
@method get_option(name)
|
222
228
|
Send the +buffer_get_option+ RPC to +nvim+
|
223
229
|
@param [String] name
|
@@ -231,7 +237,7 @@ module Neovim
|
|
231
237
|
|
232
238
|
@method get_number
|
233
239
|
Send the +buffer_get_number+ RPC to +nvim+
|
234
|
-
@return [
|
240
|
+
@return [Integer]
|
235
241
|
|
236
242
|
@method get_name
|
237
243
|
Send the +buffer_get_name+ RPC to +nvim+
|
@@ -246,31 +252,25 @@ module Neovim
|
|
246
252
|
Send the +buffer_is_valid+ RPC to +nvim+
|
247
253
|
@return [Boolean]
|
248
254
|
|
249
|
-
@method insert(lnum, lines)
|
250
|
-
Send the +buffer_insert+ RPC to +nvim+
|
251
|
-
@param [Fixnum] lnum
|
252
|
-
@param [Array<String>] lines
|
253
|
-
@return [void]
|
254
|
-
|
255
255
|
@method get_mark(name)
|
256
256
|
Send the +buffer_get_mark+ RPC to +nvim+
|
257
257
|
@param [String] name
|
258
|
-
@return [Array<
|
258
|
+
@return [Array<Integer>]
|
259
259
|
|
260
260
|
@method add_highlight(src_id, hl_group, line, col_start, col_end)
|
261
261
|
Send the +buffer_add_highlight+ RPC to +nvim+
|
262
|
-
@param [
|
262
|
+
@param [Integer] src_id
|
263
263
|
@param [String] hl_group
|
264
|
-
@param [
|
265
|
-
@param [
|
266
|
-
@param [
|
267
|
-
@return [
|
264
|
+
@param [Integer] line
|
265
|
+
@param [Integer] col_start
|
266
|
+
@param [Integer] col_end
|
267
|
+
@return [Integer]
|
268
268
|
|
269
269
|
@method clear_highlight(src_id, line_start, line_end)
|
270
270
|
Send the +buffer_clear_highlight+ RPC to +nvim+
|
271
|
-
@param [
|
272
|
-
@param [
|
273
|
-
@param [
|
271
|
+
@param [Integer] src_id
|
272
|
+
@param [Integer] line_start
|
273
|
+
@param [Integer] line_end
|
274
274
|
@return [void]
|
275
275
|
|
276
276
|
=end
|
data/lib/neovim/client.rb
CHANGED
@@ -10,13 +10,14 @@ module Neovim
|
|
10
10
|
# @see Window
|
11
11
|
# @see Tabpage
|
12
12
|
class Client
|
13
|
-
attr_reader :session
|
13
|
+
attr_reader :session, :channel_id
|
14
14
|
|
15
15
|
def initialize(session)
|
16
16
|
session.discover_api
|
17
17
|
|
18
18
|
@session = session
|
19
19
|
@api = session.api
|
20
|
+
@channel_id = session.channel_id
|
20
21
|
end
|
21
22
|
|
22
23
|
# Intercept method calls and delegate to appropriate RPC methods.
|
@@ -104,9 +105,20 @@ module Neovim
|
|
104
105
|
|
105
106
|
# The following methods are dynamically generated.
|
106
107
|
=begin
|
107
|
-
@method
|
108
|
+
@method set_var(name, value)
|
109
|
+
Send the +vim_set_var+ RPC to +nvim+
|
110
|
+
@param [String] name
|
111
|
+
@param [Object] value
|
112
|
+
@return [Object]
|
113
|
+
|
114
|
+
@method del_var(name)
|
115
|
+
Send the +vim_del_var+ RPC to +nvim+
|
116
|
+
@param [String] name
|
117
|
+
@return [Object]
|
118
|
+
|
119
|
+
@method command(command)
|
108
120
|
Send the +vim_command+ RPC to +nvim+
|
109
|
-
@param [String]
|
121
|
+
@param [String] command
|
110
122
|
@return [void]
|
111
123
|
|
112
124
|
@method feedkeys(keys, mode, escape_csi)
|
@@ -119,7 +131,7 @@ module Neovim
|
|
119
131
|
@method input(keys)
|
120
132
|
Send the +vim_input+ RPC to +nvim+
|
121
133
|
@param [String] keys
|
122
|
-
@return [
|
134
|
+
@return [Integer]
|
123
135
|
|
124
136
|
@method replace_termcodes(str, from_part, do_lt, special)
|
125
137
|
Send the +vim_replace_termcodes+ RPC to +nvim+
|
@@ -134,9 +146,9 @@ module Neovim
|
|
134
146
|
@param [String] str
|
135
147
|
@return [String]
|
136
148
|
|
137
|
-
@method eval(
|
149
|
+
@method eval(expr)
|
138
150
|
Send the +vim_eval+ RPC to +nvim+
|
139
|
-
@param [String]
|
151
|
+
@param [String] expr
|
140
152
|
@return [Object]
|
141
153
|
|
142
154
|
@method call_function(fname, args)
|
@@ -148,7 +160,7 @@ module Neovim
|
|
148
160
|
@method strwidth(str)
|
149
161
|
Send the +vim_strwidth+ RPC to +nvim+
|
150
162
|
@param [String] str
|
151
|
-
@return [
|
163
|
+
@return [Integer]
|
152
164
|
|
153
165
|
@method list_runtime_paths
|
154
166
|
Send the +vim_list_runtime_paths+ RPC to +nvim+
|
@@ -177,17 +189,6 @@ module Neovim
|
|
177
189
|
@param [String] name
|
178
190
|
@return [Object]
|
179
191
|
|
180
|
-
@method set_var(name, value)
|
181
|
-
Send the +vim_set_var+ RPC to +nvim+
|
182
|
-
@param [String] name
|
183
|
-
@param [Object] value
|
184
|
-
@return [Object]
|
185
|
-
|
186
|
-
@method del_var(name)
|
187
|
-
Send the +vim_del_var+ RPC to +nvim+
|
188
|
-
@param [String] name
|
189
|
-
@return [Object]
|
190
|
-
|
191
192
|
@method get_vvar(name)
|
192
193
|
Send the +vim_get_vvar+ RPC to +nvim+
|
193
194
|
@param [String] name
|
@@ -265,7 +266,7 @@ module Neovim
|
|
265
266
|
@method name_to_color(name)
|
266
267
|
Send the +vim_name_to_color+ RPC to +nvim+
|
267
268
|
@param [String] name
|
268
|
-
@return [
|
269
|
+
@return [Integer]
|
269
270
|
|
270
271
|
@method get_color_map
|
271
272
|
Send the +vim_get_color_map+ RPC to +nvim+
|
data/lib/neovim/current.rb
CHANGED
@@ -38,8 +38,8 @@ module Neovim
|
|
38
38
|
|
39
39
|
# Set the active buffer.
|
40
40
|
#
|
41
|
-
# @param buffer [Buffer,
|
42
|
-
# @return [Buffer,
|
41
|
+
# @param buffer [Buffer, Integer] The target buffer or index.
|
42
|
+
# @return [Buffer, Integer]
|
43
43
|
def buffer=(buffer)
|
44
44
|
@session.request(:vim_set_current_buffer, buffer)
|
45
45
|
end
|
@@ -53,8 +53,8 @@ module Neovim
|
|
53
53
|
|
54
54
|
# Set the active window.
|
55
55
|
#
|
56
|
-
# @param window [Window,
|
57
|
-
# @return [Window,
|
56
|
+
# @param window [Window, Integer] The target window or index.
|
57
|
+
# @return [Window, Integer]
|
58
58
|
def window=(window)
|
59
59
|
@session.request(:vim_set_current_window, window)
|
60
60
|
end
|
@@ -68,8 +68,8 @@ module Neovim
|
|
68
68
|
|
69
69
|
# Set the active tabpage.
|
70
70
|
#
|
71
|
-
# @param tabpage [Tabpage,
|
72
|
-
# @return [Tabpage,
|
71
|
+
# @param tabpage [Tabpage, Integer] The target tabpage or index.
|
72
|
+
# @return [Tabpage, Integer]
|
73
73
|
def tabpage=(tabpage)
|
74
74
|
@session.request(:vim_set_current_tabpage, tabpage)
|
75
75
|
end
|
data/lib/neovim/host.rb
CHANGED
data/lib/neovim/line_range.rb
CHANGED
@@ -27,14 +27,14 @@ module Neovim
|
|
27
27
|
# Access the line at the given index within the range.
|
28
28
|
#
|
29
29
|
# @overload [](index)
|
30
|
-
# @param index [
|
30
|
+
# @param index [Integer]
|
31
31
|
#
|
32
32
|
# @overload [](range)
|
33
33
|
# @param range [Range]
|
34
34
|
#
|
35
35
|
# @overload [](index, length)
|
36
|
-
# @param index [
|
37
|
-
# @param length [
|
36
|
+
# @param index [Integer]
|
37
|
+
# @param length [Integer]
|
38
38
|
#
|
39
39
|
# @example Get the first line using an index
|
40
40
|
# line_range[0] # => "first"
|
@@ -67,12 +67,12 @@ module Neovim
|
|
67
67
|
# Set the line at the given index within the range.
|
68
68
|
#
|
69
69
|
# @overload []=(index, string)
|
70
|
-
# @param index [
|
70
|
+
# @param index [Integer]
|
71
71
|
# @param string [String]
|
72
72
|
#
|
73
73
|
# @overload []=(index, length, strings)
|
74
|
-
# @param index [
|
75
|
-
# @param length [
|
74
|
+
# @param index [Integer]
|
75
|
+
# @param length [Integer]
|
76
76
|
# @param strings [Array<String>]
|
77
77
|
#
|
78
78
|
# @overload []=(range, strings)
|
@@ -123,7 +123,7 @@ module Neovim
|
|
123
123
|
|
124
124
|
# Insert line(s) at the given index within the range.
|
125
125
|
#
|
126
|
-
# @param index [
|
126
|
+
# @param index [Integer]
|
127
127
|
# @param lines [String]
|
128
128
|
def insert(index, lines)
|
129
129
|
@buffer.insert(index, Array(lines))
|
@@ -131,7 +131,7 @@ module Neovim
|
|
131
131
|
|
132
132
|
# Delete the line at the given index within the range.
|
133
133
|
#
|
134
|
-
# @param index [
|
134
|
+
# @param index [Integer]
|
135
135
|
def delete(index)
|
136
136
|
@buffer.del_line(abs_line(index))
|
137
137
|
end
|
data/lib/neovim/plugin.rb
CHANGED
@@ -3,7 +3,7 @@ require "neovim/plugin/dsl"
|
|
3
3
|
module Neovim
|
4
4
|
# @api private
|
5
5
|
class Plugin
|
6
|
-
attr_accessor :handlers
|
6
|
+
attr_accessor :handlers, :setup_blocks
|
7
7
|
attr_reader :source
|
8
8
|
|
9
9
|
# Entrypoint to the +Neovim.plugin+ DSL.
|
@@ -16,6 +16,7 @@ module Neovim
|
|
16
16
|
def initialize(source)
|
17
17
|
@handlers = []
|
18
18
|
@source = source
|
19
|
+
@setup_blocks = []
|
19
20
|
end
|
20
21
|
|
21
22
|
# Return specs used by +nvim+ to register plugins.
|
@@ -24,5 +25,10 @@ module Neovim
|
|
24
25
|
handler.qualified? ? acc + [handler.to_spec] : acc
|
25
26
|
end
|
26
27
|
end
|
28
|
+
|
29
|
+
# Run all registered setup blocks.
|
30
|
+
def setup(client)
|
31
|
+
@setup_blocks.each { |bl| bl.call(client) }
|
32
|
+
end
|
27
33
|
end
|
28
34
|
end
|
data/lib/neovim/plugin/dsl.rb
CHANGED
@@ -16,11 +16,11 @@ module Neovim
|
|
16
16
|
# @param options [Hash] Command options.
|
17
17
|
# @param &block [Proc, nil] The body of the command.
|
18
18
|
#
|
19
|
-
# @option options [
|
19
|
+
# @option options [Integer] :nargs The number of arguments to accept. See
|
20
20
|
# +:h command-nargs+.
|
21
21
|
# @option options [String, Boolean] :range The range argument.
|
22
22
|
# See +:h command-range+.
|
23
|
-
# @option options [
|
23
|
+
# @option options [Integer] :count The default count argument.
|
24
24
|
# See +:h command-count+.
|
25
25
|
# @option options [Boolean] :bang Whether the command can take a +!+
|
26
26
|
# modifier. See +:h command-bang+.
|
@@ -68,9 +68,19 @@ module Neovim
|
|
68
68
|
|
69
69
|
private
|
70
70
|
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
71
|
+
# Register a setup block to run once before the host starts. The block
|
72
|
+
# should expect to receive a single argument, a +Neovim::Client+.
|
73
|
+
#
|
74
|
+
# This is used for bootstrapping the legacy ruby provider, and not meant
|
75
|
+
# to be used publicly in plugin definitions.
|
76
|
+
def setup(&block)
|
77
|
+
@plugin.setup_blocks << block
|
78
|
+
end
|
79
|
+
|
80
|
+
# Directly define a synchronous RPC call without a namespace.
|
81
|
+
#
|
82
|
+
# This is used for exposing legacy ruby provider calls, and not meant to
|
83
|
+
# be used publicly in plugin definitions.
|
74
84
|
def rpc(name, &block)
|
75
85
|
@plugin.handlers.push(Handler.unqualified(name, block))
|
76
86
|
end
|
data/lib/neovim/ruby_provider.rb
CHANGED
@@ -18,6 +18,7 @@ module Neovim
|
|
18
18
|
__define_ruby_execute(plug)
|
19
19
|
__define_ruby_execute_file(plug)
|
20
20
|
__define_ruby_do_range(plug)
|
21
|
+
__define_ruby_chdir(plug)
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
@@ -71,11 +72,27 @@ module Neovim
|
|
71
72
|
end
|
72
73
|
private_class_method :__define_ruby_do_range
|
73
74
|
|
75
|
+
def self.__define_ruby_chdir(plug)
|
76
|
+
plug.__send__(:setup) do |client|
|
77
|
+
cid = client.channel_id
|
78
|
+
client.command("au DirChanged * call rpcrequest(#{cid}, 'ruby_chdir', v:event)")
|
79
|
+
end
|
80
|
+
|
81
|
+
plug.__send__(:rpc, :ruby_chdir) do |nvim, event|
|
82
|
+
Dir.chdir(event.fetch("cwd"))
|
83
|
+
end
|
84
|
+
end
|
85
|
+
private_class_method :__define_ruby_chdir
|
86
|
+
|
74
87
|
def self.__wrap_client(client)
|
75
88
|
__with_globals(client) do
|
76
89
|
__with_vim_constant(client) do
|
77
90
|
__with_redirect_streams(client) do
|
78
|
-
|
91
|
+
begin
|
92
|
+
yield
|
93
|
+
rescue SyntaxError => e
|
94
|
+
client.err_write(e.message)
|
95
|
+
end
|
79
96
|
end
|
80
97
|
end
|
81
98
|
end
|
@@ -11,13 +11,13 @@ module Neovim
|
|
11
11
|
|
12
12
|
# Connect to a TCP socket.
|
13
13
|
def self.tcp(host, port)
|
14
|
-
socket =
|
14
|
+
socket = Socket.tcp(host, port)
|
15
15
|
new(socket)
|
16
16
|
end
|
17
17
|
|
18
18
|
# Connect to a UNIX domain socket.
|
19
19
|
def self.unix(path)
|
20
|
-
socket =
|
20
|
+
socket = Socket.unix(path)
|
21
21
|
new(socket)
|
22
22
|
end
|
23
23
|
|
data/lib/neovim/tabpage.rb
CHANGED
@@ -5,15 +5,6 @@ module Neovim
|
|
5
5
|
|
6
6
|
# The following methods are dynamically generated.
|
7
7
|
=begin
|
8
|
-
@method get_windows
|
9
|
-
Send the +tabpage_get_windows+ RPC to +nvim+
|
10
|
-
@return [Array<Window>]
|
11
|
-
|
12
|
-
@method get_var(name)
|
13
|
-
Send the +tabpage_get_var+ RPC to +nvim+
|
14
|
-
@param [String] name
|
15
|
-
@return [Object]
|
16
|
-
|
17
8
|
@method set_var(name, value)
|
18
9
|
Send the +tabpage_set_var+ RPC to +nvim+
|
19
10
|
@param [String] name
|
@@ -25,6 +16,15 @@ module Neovim
|
|
25
16
|
@param [String] name
|
26
17
|
@return [Object]
|
27
18
|
|
19
|
+
@method get_windows
|
20
|
+
Send the +tabpage_get_windows+ RPC to +nvim+
|
21
|
+
@return [Array<Window>]
|
22
|
+
|
23
|
+
@method get_var(name)
|
24
|
+
Send the +tabpage_get_var+ RPC to +nvim+
|
25
|
+
@param [String] name
|
26
|
+
@return [Object]
|
27
|
+
|
28
28
|
@method get_window
|
29
29
|
Send the +tabpage_get_window+ RPC to +nvim+
|
30
30
|
@return [Window]
|
data/lib/neovim/version.rb
CHANGED
data/lib/neovim/window.rb
CHANGED
@@ -11,15 +11,15 @@ module Neovim
|
|
11
11
|
|
12
12
|
# Get the height of the window
|
13
13
|
#
|
14
|
-
# @return [
|
14
|
+
# @return [Integer]
|
15
15
|
def height
|
16
16
|
get_height
|
17
17
|
end
|
18
18
|
|
19
19
|
# Set the height of the window
|
20
20
|
#
|
21
|
-
# @param height [
|
22
|
-
# @return [
|
21
|
+
# @param height [Integer]
|
22
|
+
# @return [Integer]
|
23
23
|
def height=(height)
|
24
24
|
set_height(height)
|
25
25
|
height
|
@@ -27,15 +27,15 @@ module Neovim
|
|
27
27
|
|
28
28
|
# Get the width of the window
|
29
29
|
#
|
30
|
-
# @return [
|
30
|
+
# @return [Integer]
|
31
31
|
def width
|
32
32
|
get_width
|
33
33
|
end
|
34
34
|
|
35
35
|
# Set the width of the window
|
36
36
|
#
|
37
|
-
# @param width [
|
38
|
-
# @return [
|
37
|
+
# @param width [Integer]
|
38
|
+
# @return [Integer]
|
39
39
|
def width=(width)
|
40
40
|
set_width(width)
|
41
41
|
width
|
@@ -43,15 +43,15 @@ module Neovim
|
|
43
43
|
|
44
44
|
# Get the cursor coordinates
|
45
45
|
#
|
46
|
-
# @return [Array(
|
46
|
+
# @return [Array(Integer, Integer)]
|
47
47
|
def cursor
|
48
48
|
get_cursor
|
49
49
|
end
|
50
50
|
|
51
51
|
# Set the cursor coodinates
|
52
52
|
#
|
53
|
-
# @param coords [Array(
|
54
|
-
# @return [Array(
|
53
|
+
# @param coords [Array(Integer, Integer)]
|
54
|
+
# @return [Array(Integer, Integer)]
|
55
55
|
def cursor=(coords)
|
56
56
|
_x, _y = coords
|
57
57
|
x = [_x, 1].max
|
@@ -61,35 +61,46 @@ module Neovim
|
|
61
61
|
|
62
62
|
# The following methods are dynamically generated.
|
63
63
|
=begin
|
64
|
+
@method set_var(name, value)
|
65
|
+
Send the +window_set_var+ RPC to +nvim+
|
66
|
+
@param [String] name
|
67
|
+
@param [Object] value
|
68
|
+
@return [Object]
|
69
|
+
|
70
|
+
@method del_var(name)
|
71
|
+
Send the +window_del_var+ RPC to +nvim+
|
72
|
+
@param [String] name
|
73
|
+
@return [Object]
|
74
|
+
|
64
75
|
@method get_buffer
|
65
76
|
Send the +window_get_buffer+ RPC to +nvim+
|
66
77
|
@return [Buffer]
|
67
78
|
|
68
79
|
@method get_cursor
|
69
80
|
Send the +window_get_cursor+ RPC to +nvim+
|
70
|
-
@return [Array<
|
81
|
+
@return [Array<Integer>]
|
71
82
|
|
72
83
|
@method set_cursor(pos)
|
73
84
|
Send the +window_set_cursor+ RPC to +nvim+
|
74
|
-
@param [Array<
|
85
|
+
@param [Array<Integer>] pos
|
75
86
|
@return [void]
|
76
87
|
|
77
88
|
@method get_height
|
78
89
|
Send the +window_get_height+ RPC to +nvim+
|
79
|
-
@return [
|
90
|
+
@return [Integer]
|
80
91
|
|
81
92
|
@method set_height(height)
|
82
93
|
Send the +window_set_height+ RPC to +nvim+
|
83
|
-
@param [
|
94
|
+
@param [Integer] height
|
84
95
|
@return [void]
|
85
96
|
|
86
97
|
@method get_width
|
87
98
|
Send the +window_get_width+ RPC to +nvim+
|
88
|
-
@return [
|
99
|
+
@return [Integer]
|
89
100
|
|
90
101
|
@method set_width(width)
|
91
102
|
Send the +window_set_width+ RPC to +nvim+
|
92
|
-
@param [
|
103
|
+
@param [Integer] width
|
93
104
|
@return [void]
|
94
105
|
|
95
106
|
@method get_var(name)
|
@@ -97,17 +108,6 @@ module Neovim
|
|
97
108
|
@param [String] name
|
98
109
|
@return [Object]
|
99
110
|
|
100
|
-
@method set_var(name, value)
|
101
|
-
Send the +window_set_var+ RPC to +nvim+
|
102
|
-
@param [String] name
|
103
|
-
@param [Object] value
|
104
|
-
@return [Object]
|
105
|
-
|
106
|
-
@method del_var(name)
|
107
|
-
Send the +window_del_var+ RPC to +nvim+
|
108
|
-
@param [String] name
|
109
|
-
@return [Object]
|
110
|
-
|
111
111
|
@method get_option(name)
|
112
112
|
Send the +window_get_option+ RPC to +nvim+
|
113
113
|
@param [String] name
|
@@ -121,7 +121,7 @@ module Neovim
|
|
121
121
|
|
122
122
|
@method get_position
|
123
123
|
Send the +window_get_position+ RPC to +nvim+
|
124
|
-
@return [Array<
|
124
|
+
@return [Array<Integer>]
|
125
125
|
|
126
126
|
@method get_tabpage
|
127
127
|
Send the +window_get_tabpage+ RPC to +nvim+
|
data/script/dump_api
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
4
|
+
|
5
|
+
require "neovim"
|
6
|
+
require "pp"
|
7
|
+
|
8
|
+
nvim_exe = ENV.fetch("NVIM_EXECUTABLE", "nvim")
|
9
|
+
session = Neovim::Session.child([nvim_exe, "-u", "NONE", "-n"])
|
10
|
+
pp session.request(:vim_get_api_info)
|
data/script/generate_docs
CHANGED
@@ -9,7 +9,9 @@ vim_docs = []
|
|
9
9
|
buffer_docs = []
|
10
10
|
window_docs = []
|
11
11
|
tabpage_docs = []
|
12
|
-
|
12
|
+
nvim_exe = ENV.fetch("NVIM_EXECUTABLE", "nvim")
|
13
|
+
|
14
|
+
session = Neovim::Session.child([nvim_exe, "-u", "NONE", "-n"])
|
13
15
|
vim_defs = Neovim::Client.instance_methods(false)
|
14
16
|
buffer_defs = Neovim::Buffer.instance_methods(false)
|
15
17
|
tabpage_defs = Neovim::Tabpage.instance_methods(false)
|
@@ -42,7 +44,6 @@ session.request(:vim_get_api_info)[1]["functions"].each do |func|
|
|
42
44
|
return_doc = " @return [#{return_type}]\n"
|
43
45
|
method_doc = [method_decl, method_desc, *param_docs, return_doc].join("\n")
|
44
46
|
method_doc.gsub!(/ArrayOf\((\w+)[^)]*\)/, 'Array<\1>')
|
45
|
-
method_doc.gsub!(/Integer/, "Fixnum")
|
46
47
|
|
47
48
|
case prefix
|
48
49
|
when "vim"
|
@@ -55,6 +55,32 @@ RSpec.describe "ruby_provider" do
|
|
55
55
|
|
56
56
|
expect(nvim.get_var("foo")).to be(123)
|
57
57
|
end
|
58
|
+
|
59
|
+
it "handles explicit directory changes" do
|
60
|
+
expect {
|
61
|
+
nvim.command("cd /")
|
62
|
+
}.to change {
|
63
|
+
nvim.command_output("call rpcrequest(host, 'ruby_execute', 'puts Dir.pwd')").strip
|
64
|
+
}.from(Dir.pwd).to("/")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "handles implicit directory changes" do
|
68
|
+
expect {
|
69
|
+
nvim.command("split | lcd / | wincmd p")
|
70
|
+
}.not_to change {
|
71
|
+
nvim.command_output("call rpcrequest(host, 'ruby_execute', 'puts Dir.pwd')").strip
|
72
|
+
}.from(Dir.pwd)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "handles malformed ruby" do
|
76
|
+
expect {
|
77
|
+
nvim.eval("rpcrequest(host, 'ruby_execute', 'puts[')")
|
78
|
+
}.to raise_error(ArgumentError)
|
79
|
+
|
80
|
+
expect {
|
81
|
+
nvim.eval("rpcrequest(host, 'ruby_execute', 'puts \"12\"')")
|
82
|
+
}.not_to raise_error
|
83
|
+
end
|
58
84
|
end
|
59
85
|
|
60
86
|
describe "ruby_execute_file" do
|
@@ -124,6 +150,40 @@ RSpec.describe "ruby_provider" do
|
|
124
150
|
nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
|
125
151
|
expect(nvim.get_var("foo")).to be(2)
|
126
152
|
end
|
153
|
+
|
154
|
+
it "handles explicit directory changes" do
|
155
|
+
File.write(script_path, "puts Dir.pwd")
|
156
|
+
|
157
|
+
expect {
|
158
|
+
nvim.command("cd /")
|
159
|
+
}.to change {
|
160
|
+
nvim.command_output("call rpcrequest(host, 'ruby_execute_file', '#{script_path}')").strip
|
161
|
+
}.from(Dir.pwd).to("/")
|
162
|
+
end
|
163
|
+
|
164
|
+
it "handles implicit directory changes" do
|
165
|
+
File.write(script_path, "puts Dir.pwd")
|
166
|
+
|
167
|
+
expect {
|
168
|
+
nvim.command("split | lcd / | wincmd p")
|
169
|
+
}.not_to change {
|
170
|
+
nvim.command_output("call rpcrequest(host, 'ruby_execute_file', '#{script_path}')").strip
|
171
|
+
}.from(Dir.pwd)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "handles malformed ruby" do
|
175
|
+
File.write(script_path, "puts[")
|
176
|
+
|
177
|
+
expect {
|
178
|
+
nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
|
179
|
+
}.to raise_error(ArgumentError)
|
180
|
+
|
181
|
+
File.write(script_path, "12")
|
182
|
+
|
183
|
+
expect {
|
184
|
+
nvim.eval("rpcrequest(host, 'ruby_execute_file', '#{script_path}')")
|
185
|
+
}.not_to raise_error
|
186
|
+
end
|
127
187
|
end
|
128
188
|
|
129
189
|
describe "ruby_do_range" do
|
@@ -144,5 +204,17 @@ RSpec.describe "ruby_provider" do
|
|
144
204
|
nvim.eval("rpcrequest(host, 'ruby_do_range', 1, 6000, '$_.succ!')")
|
145
205
|
}.to change { nvim.current.buffer.lines.to_a }.to(ys)
|
146
206
|
end
|
207
|
+
|
208
|
+
it "handles malformed ruby" do
|
209
|
+
nvim.current.buffer.lines = ["a", "b"]
|
210
|
+
|
211
|
+
expect {
|
212
|
+
nvim.eval("rpcrequest(host, 'ruby_do_range', 1, 1, 'puts[')")
|
213
|
+
}.to raise_error(ArgumentError)
|
214
|
+
|
215
|
+
expect {
|
216
|
+
nvim.eval("rpcrequest(host, 'ruby_do_range', 1, 1, 'puts')")
|
217
|
+
}.not_to raise_error
|
218
|
+
end
|
147
219
|
end
|
148
220
|
end
|
data/spec/helper.rb
CHANGED
@@ -8,6 +8,7 @@ end
|
|
8
8
|
require "fileutils"
|
9
9
|
require "neovim"
|
10
10
|
require "pry"
|
11
|
+
require "shellwords"
|
11
12
|
require "stringio"
|
12
13
|
require "timeout"
|
13
14
|
|
@@ -21,7 +22,7 @@ module Support
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def self.tcp_port
|
24
|
-
server = TCPServer.new("
|
25
|
+
server = TCPServer.new("127.0.0.1", 0)
|
25
26
|
|
26
27
|
begin
|
27
28
|
server.addr[1]
|
@@ -43,12 +44,13 @@ module Support
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def self.child_argv
|
46
|
-
|
47
|
+
nvim_exe = ENV.fetch("NVIM_EXECUTABLE", "nvim")
|
48
|
+
[nvim_exe, "--headless", "-i", "NONE", "-u", "NONE", "-n"]
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
50
|
-
unless system("#{Support.child_argv.
|
51
|
-
warn("
|
52
|
+
unless system("#{Support.child_argv.shelljoin} --version | grep -q NVIM")
|
53
|
+
warn("Failed to load nvim. See installation instructions:")
|
52
54
|
warn("https://github.com/neovim/neovim/wiki/Installing-Neovim")
|
53
55
|
exit(1)
|
54
56
|
end
|
@@ -74,10 +76,14 @@ RSpec.configure do |config|
|
|
74
76
|
|
75
77
|
config.around(:example, :silence_logging) do |spec|
|
76
78
|
old_logger = Neovim.logger
|
79
|
+
log_target = StringIO.new
|
80
|
+
Neovim.logger = Logger.new(log_target)
|
77
81
|
|
78
82
|
begin
|
79
|
-
Neovim.logger = Logger.new(StringIO.new)
|
80
83
|
spec.run
|
84
|
+
|
85
|
+
expect(log_target.string).not_to be_empty,
|
86
|
+
":silence_logging used but nothing logged"
|
81
87
|
ensure
|
82
88
|
Neovim.logger = old_logger
|
83
89
|
end
|
data/spec/neovim/current_spec.rb
CHANGED
@@ -69,12 +69,12 @@ module Neovim
|
|
69
69
|
|
70
70
|
describe "#window=" do
|
71
71
|
it "sets the current window from an integer" do
|
72
|
+
start_index = current.window.index
|
72
73
|
client.command("vsp")
|
73
|
-
expect(current.window.index).not_to eq(1)
|
74
74
|
|
75
75
|
expect {
|
76
|
-
current.window =
|
77
|
-
}.to change { current.window.index }.to(
|
76
|
+
current.window = start_index
|
77
|
+
}.to change { current.window.index }.to(start_index)
|
78
78
|
end
|
79
79
|
|
80
80
|
it "sets the current window from a Window" do
|
data/spec/neovim/host_spec.rb
CHANGED
@@ -75,6 +75,24 @@ module Neovim
|
|
75
75
|
}.from(nil).to(kind_of(Proc))
|
76
76
|
end
|
77
77
|
|
78
|
+
it "yields a client to the plugin setup blocks" do
|
79
|
+
yielded = []
|
80
|
+
|
81
|
+
plugin = Plugin.from_config_block("source") do |plug|
|
82
|
+
plug.__send__(:setup) do |client|
|
83
|
+
yielded << client
|
84
|
+
end
|
85
|
+
|
86
|
+
plug.__send__(:setup) do |_|
|
87
|
+
yielded << :other
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
expect {
|
92
|
+
host.register(plugin)
|
93
|
+
}.to change { yielded }.from([]).to([client, :other])
|
94
|
+
end
|
95
|
+
|
78
96
|
it "doesn't add top-level RPCs to specs" do
|
79
97
|
plugin = Plugin.from_config_block("source") do |plug|
|
80
98
|
plug.__send__(:rpc, :Foo)
|
data/spec/neovim/plugin_spec.rb
CHANGED
@@ -70,6 +70,24 @@ module Neovim
|
|
70
70
|
)
|
71
71
|
end
|
72
72
|
|
73
|
+
it "registers setup callbacks" do
|
74
|
+
yielded = []
|
75
|
+
|
76
|
+
plugin = Plugin.from_config_block("source") do |plug|
|
77
|
+
plug.__send__(:setup) do |client|
|
78
|
+
yielded << client
|
79
|
+
end
|
80
|
+
|
81
|
+
plug.__send__(:setup) do |_|
|
82
|
+
yielded << :other
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
expect {
|
87
|
+
plugin.setup(:client)
|
88
|
+
}.to change { yielded }.from([]).to([:client, :other])
|
89
|
+
end
|
90
|
+
|
73
91
|
it "registers a top level RPC" do
|
74
92
|
cmd_block = Proc.new {}
|
75
93
|
|
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.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Genco
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- lib/neovim/version.rb
|
125
125
|
- lib/neovim/window.rb
|
126
126
|
- neovim.gemspec
|
127
|
+
- script/dump_api
|
127
128
|
- script/generate_docs
|
128
129
|
- script/j2mp
|
129
130
|
- script/mp2j
|
@@ -171,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
172
|
version: '0'
|
172
173
|
requirements: []
|
173
174
|
rubyforge_project:
|
174
|
-
rubygems_version: 2.
|
175
|
+
rubygems_version: 2.6.8
|
175
176
|
signing_key:
|
176
177
|
specification_version: 4
|
177
178
|
summary: A Ruby client for Neovim
|
@@ -200,4 +201,3 @@ test_files:
|
|
200
201
|
- spec/neovim/session_spec.rb
|
201
202
|
- spec/neovim/window_spec.rb
|
202
203
|
- spec/neovim_spec.rb
|
203
|
-
has_rdoc:
|