neovim 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +8 -0
  4. data/.travis.yml +4 -3
  5. data/CHANGELOG.md +11 -0
  6. data/README.md +10 -13
  7. data/Rakefile +18 -3
  8. data/appveyor.yml +4 -1
  9. data/{bin → exe}/neovim-ruby-host +0 -0
  10. data/lib/neovim/buffer.rb +34 -36
  11. data/lib/neovim/client.rb +121 -36
  12. data/lib/neovim/connection.rb +7 -1
  13. data/lib/neovim/event_loop.rb +3 -2
  14. data/lib/neovim/message.rb +1 -1
  15. data/lib/neovim/remote_object.rb +5 -2
  16. data/lib/neovim/ruby_provider.rb +2 -2
  17. data/lib/neovim/ruby_provider/vim.rb +6 -5
  18. data/lib/neovim/session.rb +11 -1
  19. data/lib/neovim/tabpage.rb +8 -15
  20. data/lib/neovim/version.rb +1 -1
  21. data/lib/neovim/window.rb +17 -33
  22. data/neovim.gemspec +4 -4
  23. data/script/dump_api.rb +1 -1
  24. data/script/generate_docs.rb +6 -7
  25. data/script/run_acceptance.rb +1 -1
  26. data/script/validate_docs.rb +1 -1
  27. data/spec/acceptance/ruby_spec.vim +13 -11
  28. data/spec/acceptance/rubydo_spec.vim +9 -0
  29. data/spec/acceptance/rubyfile/curbuf_ivar_get.rb +1 -1
  30. data/spec/acceptance/rubyfile/curbuf_ivar_set.rb +1 -1
  31. data/spec/acceptance/rubyfile/define_foo.rb +1 -1
  32. data/spec/acceptance/rubyfile/nested_inner.rb +1 -1
  33. data/spec/acceptance/rubyfile/set_pwd_after.rb +1 -1
  34. data/spec/acceptance/rubyfile/set_pwd_before.rb +1 -1
  35. data/spec/acceptance/rubyfile_spec.vim +15 -13
  36. data/spec/acceptance/runtime/init.vim +2 -2
  37. data/spec/helper.rb +1 -6
  38. data/spec/neovim/buffer_spec.rb +6 -0
  39. data/spec/neovim/client_spec.rb +7 -0
  40. data/spec/neovim/connection_spec.rb +30 -4
  41. data/spec/neovim/event_loop_spec.rb +6 -0
  42. data/spec/neovim/session_spec.rb +6 -0
  43. data/spec/support.rb +1 -1
  44. metadata +8 -23
  45. data/.coveralls.yml +0 -1
@@ -40,7 +40,8 @@ module Neovim
40
40
 
41
41
  def write(object)
42
42
  log(:debug) { {object: object} }
43
- @packer.write(object).flush
43
+ @packer.write(object)
44
+ self
44
45
  end
45
46
 
46
47
  def read
@@ -49,6 +50,11 @@ module Neovim
49
50
  end
50
51
  end
51
52
 
53
+ def flush
54
+ @packer.flush
55
+ self
56
+ end
57
+
52
58
  def register_type(id)
53
59
  @unpacker.register_type(id) do |data|
54
60
  index = MessagePack.unpack(data)
@@ -34,8 +34,9 @@ module Neovim
34
34
  end
35
35
 
36
36
  def shutdown
37
- stop
37
+ @running = false
38
38
  @shutdown = true
39
+ run
39
40
  end
40
41
 
41
42
  def request(request_id, method, *args)
@@ -102,7 +103,7 @@ module Neovim
102
103
  private
103
104
 
104
105
  def read
105
- array = @connection.read
106
+ array = @connection.flush.read
106
107
  Message.from_array(array)
107
108
  end
108
109
 
@@ -49,7 +49,7 @@ module Neovim
49
49
  end
50
50
 
51
51
  def received(handlers)
52
- handlers[request_id].call(self)
52
+ handlers.delete(request_id).call(self)
53
53
  end
54
54
  end
55
55
 
@@ -1,3 +1,5 @@
1
+ require "set"
2
+
1
3
  module Neovim
2
4
  # @abstract Superclass for all +nvim+ remote objects.
3
5
  #
@@ -37,7 +39,7 @@ module Neovim
37
39
 
38
40
  # Extend +methods+ to include RPC methods
39
41
  def methods(*args)
40
- super | rpc_methods
42
+ super | rpc_methods.to_a
41
43
  end
42
44
 
43
45
  # Extend +==+ to only look at class and index.
@@ -48,7 +50,8 @@ module Neovim
48
50
  private
49
51
 
50
52
  def rpc_methods
51
- @api.functions_for_object(self).map(&:method_name)
53
+ @rpc_methods ||=
54
+ @api.functions_for_object(self).map(&:method_name).to_set
52
55
  end
53
56
  end
54
57
  end
@@ -134,9 +134,9 @@ module Neovim
134
134
  def self.__update_lines_in_chunks(buffer, start, stop, size)
135
135
  (start..stop).each_slice(size) do |linenos|
136
136
  start, stop = linenos[0] - 1, linenos[-1]
137
- lines = buffer.get_lines(start, stop, true)
137
+ lines = buffer.get_lines(start, stop, false)
138
138
 
139
- buffer.set_lines(start, stop, true, yield(lines))
139
+ buffer.set_lines(start, stop, false, yield(lines))
140
140
  end
141
141
  end
142
142
  private_class_method :__update_lines_in_chunks
@@ -15,7 +15,7 @@ module Vim
15
15
 
16
16
  # Delegate all method calls to the underlying +Neovim::Client+ object.
17
17
  def self.method_missing(method, *args, &block)
18
- if @__client.respond_to?(method)
18
+ if @__client
19
19
  @__client.public_send(method, *args, &block).tap do
20
20
  __refresh_globals(@__client)
21
21
  end
@@ -33,13 +33,14 @@ module Vim
33
33
  end
34
34
 
35
35
  def self.__refresh_globals(client)
36
- bufnr = client.evaluate("bufnr('%')")
36
+ bufid, winid = client.evaluate("[nvim_get_current_buf(), nvim_get_current_win()]")
37
+ session, api = client.session, client.api
37
38
 
38
- $curbuf = @__buffer_cache.fetch(bufnr) do
39
- @__buffer_cache[bufnr] = client.get_current_buf
39
+ $curbuf = @__buffer_cache.fetch(bufid) do
40
+ @__buffer_cache[bufid] = Buffer.new(bufid, session, api)
40
41
  end
41
42
 
42
- $curwin = client.get_current_win
43
+ $curwin = Window.new(winid, session, api)
43
44
  end
44
45
  end
45
46
 
@@ -11,6 +11,13 @@ module Neovim
11
11
 
12
12
  attr_writer :request_id
13
13
 
14
+ # @api private
15
+ class Exited < RuntimeError
16
+ def initialize
17
+ super("nvim process exited")
18
+ end
19
+ end
20
+
14
21
  def initialize(event_loop)
15
22
  @event_loop = event_loop
16
23
  @main_thread = Thread.current
@@ -60,7 +67,10 @@ module Neovim
60
67
 
61
68
  @event_loop.request(@request_id, method, *args)
62
69
  response = blocking ? blocking_response : yielding_response
63
- response.error ? raise(response.error) : response.value
70
+
71
+ raise(Exited) if response.nil?
72
+ raise(response.error) if response.error
73
+ response.value
64
74
  end
65
75
  end
66
76
 
@@ -3,47 +3,40 @@ require "neovim/remote_object"
3
3
  module Neovim
4
4
  # Class representing an +nvim+ tabpage.
5
5
  #
6
- # The methods documented here were generated using NVIM v0.2.2
6
+ # The methods documented here were generated using NVIM v0.3.1
7
7
  class Tabpage < RemoteObject
8
8
  # The following methods are dynamically generated.
9
9
  =begin
10
- @method list_wins(tabpage)
10
+ @method list_wins
11
11
  See +:h nvim_tabpage_list_wins()+
12
- @param [Tabpage] tabpage
13
12
  @return [Array<Window>]
14
13
 
15
- @method get_var(tabpage, name)
14
+ @method get_var(name)
16
15
  See +:h nvim_tabpage_get_var()+
17
- @param [Tabpage] tabpage
18
16
  @param [String] name
19
17
  @return [Object]
20
18
 
21
- @method set_var(tabpage, name, value)
19
+ @method set_var(name, value)
22
20
  See +:h nvim_tabpage_set_var()+
23
- @param [Tabpage] tabpage
24
21
  @param [String] name
25
22
  @param [Object] value
26
23
  @return [void]
27
24
 
28
- @method del_var(tabpage, name)
25
+ @method del_var(name)
29
26
  See +:h nvim_tabpage_del_var()+
30
- @param [Tabpage] tabpage
31
27
  @param [String] name
32
28
  @return [void]
33
29
 
34
- @method get_win(tabpage)
30
+ @method get_win
35
31
  See +:h nvim_tabpage_get_win()+
36
- @param [Tabpage] tabpage
37
32
  @return [Window]
38
33
 
39
- @method get_number(tabpage)
34
+ @method get_number
40
35
  See +:h nvim_tabpage_get_number()+
41
- @param [Tabpage] tabpage
42
36
  @return [Integer]
43
37
 
44
- @method is_valid(tabpage)
38
+ @method is_valid
45
39
  See +:h nvim_tabpage_is_valid()+
46
- @param [Tabpage] tabpage
47
40
  @return [Boolean]
48
41
 
49
42
  =end
@@ -1,3 +1,3 @@
1
1
  module Neovim
2
- VERSION = Gem::Version.new("0.7.1")
2
+ VERSION = Gem::Version.new("0.8.0")
3
3
  end
@@ -3,7 +3,7 @@ require "neovim/remote_object"
3
3
  module Neovim
4
4
  # Class representing an +nvim+ window.
5
5
  #
6
- # The methods documented here were generated using NVIM v0.2.2
6
+ # The methods documented here were generated using NVIM v0.3.1
7
7
  class Window < RemoteObject
8
8
  # Get the buffer displayed in the window
9
9
  #
@@ -64,94 +64,78 @@ module Neovim
64
64
 
65
65
  # The following methods are dynamically generated.
66
66
  =begin
67
- @method get_buf(window)
67
+ @method get_buf
68
68
  See +:h nvim_win_get_buf()+
69
- @param [Window] window
70
69
  @return [Buffer]
71
70
 
72
- @method get_cursor(window)
71
+ @method get_cursor
73
72
  See +:h nvim_win_get_cursor()+
74
- @param [Window] window
75
73
  @return [Array<Integer>]
76
74
 
77
- @method set_cursor(window, pos)
75
+ @method set_cursor(pos)
78
76
  See +:h nvim_win_set_cursor()+
79
- @param [Window] window
80
77
  @param [Array<Integer>] pos
81
78
  @return [void]
82
79
 
83
- @method get_height(window)
80
+ @method get_height
84
81
  See +:h nvim_win_get_height()+
85
- @param [Window] window
86
82
  @return [Integer]
87
83
 
88
- @method set_height(window, height)
84
+ @method set_height(height)
89
85
  See +:h nvim_win_set_height()+
90
- @param [Window] window
91
86
  @param [Integer] height
92
87
  @return [void]
93
88
 
94
- @method get_width(window)
89
+ @method get_width
95
90
  See +:h nvim_win_get_width()+
96
- @param [Window] window
97
91
  @return [Integer]
98
92
 
99
- @method set_width(window, width)
93
+ @method set_width(width)
100
94
  See +:h nvim_win_set_width()+
101
- @param [Window] window
102
95
  @param [Integer] width
103
96
  @return [void]
104
97
 
105
- @method get_var(window, name)
98
+ @method get_var(name)
106
99
  See +:h nvim_win_get_var()+
107
- @param [Window] window
108
100
  @param [String] name
109
101
  @return [Object]
110
102
 
111
- @method set_var(window, name, value)
103
+ @method set_var(name, value)
112
104
  See +:h nvim_win_set_var()+
113
- @param [Window] window
114
105
  @param [String] name
115
106
  @param [Object] value
116
107
  @return [void]
117
108
 
118
- @method del_var(window, name)
109
+ @method del_var(name)
119
110
  See +:h nvim_win_del_var()+
120
- @param [Window] window
121
111
  @param [String] name
122
112
  @return [void]
123
113
 
124
- @method get_option(window, name)
114
+ @method get_option(name)
125
115
  See +:h nvim_win_get_option()+
126
- @param [Window] window
127
116
  @param [String] name
128
117
  @return [Object]
129
118
 
130
- @method set_option(window, name, value)
119
+ @method set_option(name, value)
131
120
  See +:h nvim_win_set_option()+
132
- @param [Window] window
133
121
  @param [String] name
134
122
  @param [Object] value
135
123
  @return [void]
136
124
 
137
- @method get_position(window)
125
+ @method get_position
138
126
  See +:h nvim_win_get_position()+
139
- @param [Window] window
140
127
  @return [Array<Integer>]
141
128
 
142
- @method get_tabpage(window)
129
+ @method get_tabpage
143
130
  See +:h nvim_win_get_tabpage()+
144
- @param [Window] window
145
131
  @return [Tabpage]
146
132
 
147
- @method get_number(window)
133
+ @method get_number
148
134
  See +:h nvim_win_get_number()+
149
- @param [Window] window
150
135
  @return [Integer]
151
136
 
152
- @method is_valid(window)
137
+ @method is_valid
153
138
  See +:h nvim_win_is_valid()+
154
- @param [Window] window
155
139
  @return [Boolean]
156
140
 
157
141
  =end
@@ -1,4 +1,4 @@
1
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path("lib", __dir__)
2
2
  $:.unshift(lib) unless $:.include?(lib)
3
3
  require "neovim/version"
4
4
 
@@ -8,10 +8,11 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Alex Genco"]
9
9
  spec.email = ["alexgenco@gmail.com"]
10
10
  spec.summary = "A Ruby client for Neovim"
11
- spec.homepage = "https://github.com/alexgenco/neovim-ruby"
11
+ spec.homepage = "https://github.com/neovim/neovim-ruby"
12
12
  spec.license = "MIT"
13
13
 
14
14
  spec.files = `git ls-files -z`.split("\x0")
15
+ spec.bindir = "exe"
15
16
  spec.executables = ["neovim-ruby-host"]
16
17
  spec.test_files = spec.files.grep(%r{^spec/})
17
18
  spec.require_paths = ["lib"]
@@ -22,11 +23,10 @@ Gem::Specification.new do |spec|
22
23
  spec.add_dependency "multi_json", "~> 1.0"
23
24
 
24
25
  spec.add_development_dependency "bundler"
25
- spec.add_development_dependency "coveralls"
26
26
  spec.add_development_dependency "pry"
27
27
  spec.add_development_dependency "pry-byebug"
28
28
  spec.add_development_dependency "rake"
29
29
  spec.add_development_dependency "rspec", "~> 3.0"
30
- spec.add_development_dependency "rubocop", "0.52.1"
30
+ spec.add_development_dependency "rubocop", "0.56.0"
31
31
  spec.add_development_dependency "vim-flavor", "2.2.2"
32
32
  end
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $:.unshift File.expand_path("../../lib", __FILE__)
3
+ $:.unshift File.expand_path("../lib", __dir__)
4
4
 
5
5
  require "neovim"
6
6
  require "json"
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $:.unshift File.expand_path("../../lib", __FILE__)
3
+ $:.unshift File.expand_path("../lib", __dir__)
4
4
 
5
5
  require "neovim"
6
6
  require "pathname"
@@ -19,10 +19,6 @@ buffer_defs = Neovim::Buffer.instance_methods(false)
19
19
  tabpage_defs = Neovim::Tabpage.instance_methods(false)
20
20
  window_defs = Neovim::Window.instance_methods(false)
21
21
 
22
- def add_method(docs, defs, method_name)
23
- return if defs.include?(method_name.to_s)
24
- end
25
-
26
22
  session.request(:nvim_get_api_info)[1]["functions"].each do |func|
27
23
  func_name = func["name"]
28
24
  params = func["parameters"]
@@ -30,16 +26,18 @@ session.request(:nvim_get_api_info)[1]["functions"].each do |func|
30
26
  case func_name
31
27
  when /^nvim_buf_(.+)/
32
28
  method_name = $1
29
+ params.shift
33
30
  next if buffer_defs.include?(method_name.to_sym)
34
31
  when /^nvim_win_(.+)/
35
32
  method_name = $1
33
+ params.shift
36
34
  next if window_defs.include?(method_name.to_sym)
37
35
  when /^nvim_tabpage_(.+)/
38
36
  method_name = $1
37
+ params.shift
39
38
  next if tabpage_defs.include?(method_name.to_sym)
40
39
  when /^nvim_(.+)/
41
40
  method_name = $1
42
- params.shift
43
41
  next if nvim_defs.include?(method_name.to_sym)
44
42
  else
45
43
  next
@@ -72,7 +70,8 @@ session.request(:nvim_get_api_info)[1]["functions"].each do |func|
72
70
  end
73
71
  end
74
72
 
75
- lib_dir = Pathname.new(File.expand_path("../../lib/neovim", __FILE__))
73
+ lib_dir = Pathname.new(File.expand_path("../lib/neovim", __dir__))
74
+
76
75
  {
77
76
  "client.rb" => nvim_docs,
78
77
  "buffer.rb" => buffer_docs,
@@ -5,7 +5,7 @@ require "fileutils"
5
5
  ENV.delete("VIM")
6
6
  ENV.delete("VIMRUNTIME")
7
7
 
8
- acceptance_root = File.expand_path("../../spec/acceptance", __FILE__)
8
+ acceptance_root = File.expand_path("../spec/acceptance", __dir__)
9
9
  themis_rtp = File.join(acceptance_root, "runtime")
10
10
  themis_home = File.join(themis_rtp, "flavors/thinca_vim-themis")
11
11
  manifest = File.join(themis_rtp, "rplugin_manifest.vim")
@@ -15,7 +15,7 @@ end
15
15
  release_version = response["name"][/NVIM v?(.+)$/, 1]
16
16
 
17
17
  client_file = File.read(
18
- File.expand_path("../../lib/neovim/client.rb", __FILE__)
18
+ File.expand_path("../lib/neovim/client.rb", __dir__)
19
19
  )
20
20
  docs_version = client_file[
21
21
  /The methods documented here were generated using NVIM v?(.+)$/,
@@ -4,6 +4,7 @@ let s:expect = themis#helper("expect")
4
4
  function! s:suite.before_each() abort
5
5
  1,$delete
6
6
  call append(0, ["one", "two"])
7
+ unlet! s:var
7
8
  endfunction
8
9
 
9
10
  function! s:suite.has_nvim() abort
@@ -11,41 +12,42 @@ function! s:suite.has_nvim() abort
11
12
  endfunction
12
13
 
13
14
  function! s:suite.defines_a_ruby_method() abort
14
- ruby def foo; Vim.command("let g:called = 1"); end
15
+ ruby def foo; Vim.command("let s:var = 1"); end
15
16
  ruby foo
16
17
 
17
- call s:expect(g:called).to_equal(1)
18
+ call s:expect(s:var).to_equal(1)
18
19
  endfunction
19
20
 
20
21
  function! s:suite.persists_curbuf_state() abort
21
22
  ruby $curbuf.instance_variable_set(:@foo, 123)
22
- ruby Vim.command("let g:foo = #{$curbuf.instance_variable_get(:@foo)}")
23
+ ruby Vim.command("let s:var = #{$curbuf.instance_variable_get(:@foo)}")
23
24
 
24
- call s:expect(g:foo).to_equal(123)
25
+ call s:expect(s:var).to_equal(123)
25
26
  endfunction
26
27
 
27
28
  function! s:suite.updates_working_directory() abort
28
29
  cd /
29
- ruby Vim.command("let g:ruby_pwd = '#{Dir.pwd.sub(/^C:/, "")}'")
30
+ ruby Vim.command("let s:var = '#{Dir.pwd.sub(/^C:/, "")}'")
30
31
  cd -
31
32
 
32
- call s:expect(g:ruby_pwd).to_equal("/")
33
+ call s:expect(s:var).to_equal("/")
33
34
  endfunction
34
35
 
35
36
  function! s:suite.updates_working_directory_implicitly() abort
36
37
  split | lcd /
37
- ruby Vim.command("let g:before_pwd = '#{Dir.pwd}'")
38
+ ruby Vim.command("let s:var = ['#{Dir.pwd}']")
38
39
  wincmd p
39
- ruby Vim.command("let g:after_pwd = '#{Dir.pwd}'")
40
+ ruby Vim.command("call add(s:var, '#{Dir.pwd}')")
40
41
  wincmd p | lcd -
41
42
 
42
- call s:expect(g:before_pwd).not.to_equal(g:after_pwd)
43
+ call s:expect(len(s:var)).to_equal(2)
44
+ call s:expect(s:var[0]).not.to_equal(s:var[1])
43
45
  endfunction
44
46
 
45
47
  function! s:suite.supports_nesting() abort
46
- ruby Vim.command("ruby Vim.command('let g:ruby_nested = 123')")
48
+ ruby Vim.command("ruby Vim.command('let s:var = 123')")
47
49
 
48
- call s:expect(g:ruby_nested).to_equal(123)
50
+ call s:expect(s:var).to_equal(123)
49
51
  endfunction
50
52
 
51
53
  function! s:suite.handles_standard_error() abort