neovim 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -1
  3. data/.travis.yml +2 -3
  4. data/CHANGELOG.md +29 -0
  5. data/Gemfile +0 -11
  6. data/README.md +3 -3
  7. data/Rakefile +1 -1
  8. data/appveyor.yml +9 -1
  9. data/lib/neovim.rb +3 -3
  10. data/lib/neovim/client.rb +2 -3
  11. data/lib/neovim/connection.rb +69 -0
  12. data/lib/neovim/event_loop.rb +34 -34
  13. data/lib/neovim/host.rb +47 -51
  14. data/lib/neovim/host/loader.rb +1 -4
  15. data/lib/neovim/logging.rb +8 -8
  16. data/lib/neovim/message.rb +70 -0
  17. data/lib/neovim/plugin.rb +0 -3
  18. data/lib/neovim/plugin/handler.rb +6 -6
  19. data/lib/neovim/remote_object.rb +1 -1
  20. data/lib/neovim/ruby_provider.rb +25 -14
  21. data/lib/neovim/session.rb +36 -43
  22. data/lib/neovim/version.rb +1 -1
  23. data/neovim.gemspec +4 -0
  24. data/spec/acceptance/runtime/rplugin/ruby/autocmds.rb +3 -3
  25. data/spec/acceptance/runtime/rplugin/ruby/commands.rb +15 -15
  26. data/spec/acceptance/runtime/rplugin/ruby/functions.rb +5 -5
  27. data/spec/acceptance_spec.rb +19 -16
  28. data/spec/helper.rb +15 -0
  29. data/spec/neovim/connection_spec.rb +79 -0
  30. data/spec/neovim/event_loop_spec.rb +36 -50
  31. data/spec/neovim/host/loader_spec.rb +16 -9
  32. data/spec/neovim/host_spec.rb +82 -92
  33. data/spec/neovim/logging_spec.rb +6 -6
  34. data/spec/neovim/message_spec.rb +119 -0
  35. data/spec/neovim/plugin_spec.rb +31 -31
  36. data/spec/neovim/session_spec.rb +1 -1
  37. metadata +38 -15
  38. data/lib/neovim/event_loop/connection.rb +0 -78
  39. data/lib/neovim/event_loop/message_builder.rb +0 -127
  40. data/lib/neovim/event_loop/serializer.rb +0 -37
  41. data/spec/acceptance/runtime/rplugin.vim +0 -37
  42. data/spec/neovim/event_loop/connection_spec.rb +0 -89
  43. data/spec/neovim/event_loop/message_builder_spec.rb +0 -105
  44. data/spec/neovim/event_loop/serializer_spec.rb +0 -63
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6717c82510d557b7fc3f15bd291654a609ffc53d
4
- data.tar.gz: e263dccd48b0a244cd67ea6c690eeddd06def246
2
+ SHA256:
3
+ metadata.gz: 3699ba73810bb643b4a8412a6469d6c0ec95fb138248e4f9a391b7637681cb06
4
+ data.tar.gz: 9d4e6c4513864df909a791eb23420918fe0426aeeb8d2f2929e6d52cb2b2f48e
5
5
  SHA512:
6
- metadata.gz: 6b5b1452da5d319b6587a1dba774de9123df333f9793d3f59cde1f730282f6334193174fd812f68d4c9b90117d39252ffaa9ba16b10db4802fe504516022b0e7
7
- data.tar.gz: 2b190ba96a1383acbf3ca2b6e968b7ac0a7ffdb9655b3605a2741ab6c7e213f681d178aa2543484501aeef603b9eb0ba8dfd885dbe322851ee7f0f3562cea997
6
+ metadata.gz: bf087be0814ddb1a5d765e84e462991bccef0ba8135691da379a22393d3743dcbef9cd65307f54cdbb16a8a87e5ccca72c7dbc845714b3035818f2f2108f121c
7
+ data.tar.gz: e5b78dde7090c6ade20a1869ffacee5f3e1cefdd764be149a6db81fe2f3564c26f570f99b9f048ed3eb1fe9b8f5119febfa11fc01d42bad93a21f9a52caffda0
data/.gitignore CHANGED
@@ -17,5 +17,5 @@ test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
19
  spec/workspace
20
- spec/integration/runtime/rplugin.vim
20
+ spec/acceptance/runtime/rplugin.vim
21
21
  vendor/bundle
@@ -6,16 +6,15 @@ branches:
6
6
  only: master
7
7
 
8
8
  rvm:
9
- - 1.9
10
- - 2.0
11
- - 2.1
12
9
  - 2.2
13
10
  - 2.3
14
11
  - 2.4
12
+ - 2.5
15
13
  - ruby-head
16
14
 
17
15
  before_install:
18
16
  - eval "$(curl -Ss https://raw.githubusercontent.com/neovim/bot-ci/master/scripts/travis-setup.sh) nightly-x64"
17
+ - gem update --system
19
18
  - gem update bundler
20
19
  - bundle --version
21
20
 
@@ -1,22 +1,36 @@
1
+ # 0.7.0
2
+
3
+ - Drop support for Ruby < 2.2.0, update syntax accordingly
4
+ - Use msgpack gem for all reading/writing
5
+ - Make provider std stream capturing more robust
6
+ - Lazily instantiate Host client on 'poll' request
7
+ - Fix windows by setting all IOs to binmode
8
+ - Refactor/simplify session and event loop logic
9
+
1
10
  # 0.6.2
11
+
2
12
  - Put IOs into binary mode (fixes windows bugs)
3
13
  - Various build fixes for appveyor
4
14
  - Update generated docs to v0.2.2
5
15
 
6
16
  # 0.6.1
17
+
7
18
  - Add `multi_json` dependency to fix load error in certain envs
8
19
 
9
20
  # 0.6.0
21
+
10
22
  - Refactor: consolidate "run" logic into EventLoop class to simplify middleware
11
23
  layers
12
24
  - Add JSON structured logging
13
25
  - Regenerated docs for nvim 0.2.1
14
26
 
15
27
  # 0.5.1
28
+
16
29
  - Convert vader.vim from submodule to subtree so it is included in gem
17
30
  installations
18
31
 
19
32
  # 0.5.0
33
+
20
34
  - Breaking API changes:
21
35
  - Update generated methods to map to `nvim_` RPC functions, rather than the
22
36
  deprecated `vim_` ones
@@ -25,18 +39,22 @@
25
39
  - Fix support for `:bang` and `:register` plugin DSL options
26
40
 
27
41
  # 0.4.0
42
+
28
43
  - Add `Neovim.executable` for accessing `nvim` info
29
44
  - Fix bug where `$curwin` and `$curbuf` got out of sync after `Vim.command`
30
45
  invocations
31
46
  - Use vader.vim for running vimscript acceptance tests
32
47
 
33
48
  # 0.3.3
49
+
34
50
  - Hotfix older nvim clients' inability to hook into DirChanged
35
51
 
36
52
  # 0.3.2
53
+
37
54
  - Fix directory tracking in Ruby provider
38
55
 
39
56
  # 0.3.1
57
+
40
58
  - Remove window caching to fix incompatibilities with command-t
41
59
  - Add `Vim` module alias
42
60
  - Fix `Window.count` and `Window.[]` to work with tabpages
@@ -45,6 +63,7 @@
45
63
  - Make `Neovim.attach_child` have default argv of `["nvim"]`
46
64
 
47
65
  # 0.3.0
66
+
48
67
  - Mark `Plugin::DSL#rpc` private
49
68
  - Rename Session constants:
50
69
  - `Neovim::EventLoop` -> `Neovim::Session::EventLoop`
@@ -55,28 +74,34 @@
55
74
  - `Neovim::Notification` -> `Neovim::Session::Notification`
56
75
 
57
76
  # 0.2.5
77
+
58
78
  - Optimize remote function lookup
59
79
  - Fix bug where $curbuf and $curwin weren't persisting instance state between
60
80
  requests
61
81
 
62
82
  # 0.2.4
83
+
63
84
  - Maintain cursor position on Buffer#append for compatibility with vim
64
85
  - Fix excessive fetching of API metadata
65
86
 
66
87
  # 0.2.3
88
+
67
89
  - Detach child processes in `Neovim::EventLoop.child`
68
90
  - Improve performance/compatibility of `Buffer#append`
69
91
  - Various improvements around `Host` loading
70
92
 
71
93
  # 0.2.2
94
+
72
95
  - Make `VIM` constant a module instead of a class
73
96
  - Make `Client#set_option` accept a single string argument
74
97
 
75
98
  # 0.2.1
99
+
76
100
  - Fix race condition in Fiber handling
77
101
  - General improvements to ruby\_provider.rb
78
102
 
79
103
  # 0.2.0
104
+
80
105
  - Backwards incompatible, but we're pre-1.0.0 so going with minor bump instead
81
106
  - Make vim ruby functions 1-indexed
82
107
  - Add Client#evaluate and Client#message
@@ -86,6 +111,7 @@
86
111
  - Remove race condition in Session fiber handling
87
112
 
88
113
  # 0.1.0
114
+
89
115
  - Add --version, -V to neovim-ruby-host executable
90
116
  - Update object interfaces to be compatible with Vim :ruby API
91
117
  - `NVIM_RUBY_LOG_LEVEL` now takes strings, e.g. `DEBUG`
@@ -95,17 +121,20 @@
95
121
  - Remove vendored `neovim`
96
122
 
97
123
  # 0.0.6
124
+
98
125
  - Update Session with improved Fiber coordination
99
126
  - Documentation
100
127
  - Rename APIInfo -> API
101
128
  - Rename Object -> RemoteObject
102
129
 
103
130
  # 0.0.5
131
+
104
132
  - Various fixes for Ruby remote plugins
105
133
  - Move Current#range and #range= methods to Buffer
106
134
  - Add better logging
107
135
 
108
136
  # 0.0.4
137
+
109
138
  - Add support for loading Ruby remote plugins from nvim
110
139
  - Add Current#range to return a LineRange enumerable object
111
140
  - Support sending large messages
data/Gemfile CHANGED
@@ -1,13 +1,2 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec
3
-
4
- group :development do
5
- if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new("2.0.0")
6
- gem "coveralls"
7
- gem "pry-byebug"
8
- else
9
- gem "term-ansicolor", "1.3.2"
10
- gem "coveralls", "0.8.13"
11
- gem "pry-debugger"
12
- end
13
- end
data/README.md CHANGED
@@ -54,18 +54,18 @@ Neovim.plugin do |plug|
54
54
  # Define a command called "SetLine" which sets the contents of the current
55
55
  # line. This command is executed asynchronously, so the return value is
56
56
  # ignored.
57
- plug.command(:SetLine, :nargs => 1) do |nvim, str|
57
+ plug.command(:SetLine, nargs: 1) do |nvim, str|
58
58
  nvim.current.line = str
59
59
  end
60
60
 
61
61
  # Define a function called "Sum" which adds two numbers. This function is
62
62
  # executed synchronously, so the result of the block will be returned to nvim.
63
- plug.function(:Sum, :nargs => 2, :sync => true) do |nvim, x, y|
63
+ plug.function(:Sum, nargs: 2, sync: true) do |nvim, x, y|
64
64
  x + y
65
65
  end
66
66
 
67
67
  # Define an autocmd for the BufEnter event on Ruby files.
68
- plug.autocmd(:BufEnter, :pattern => "*.rb") do |nvim|
68
+ plug.autocmd(:BufEnter, pattern: "*.rb") do |nvim|
69
69
  nvim.command("echom 'Ruby file, eh?'")
70
70
  end
71
71
  end
data/Rakefile CHANGED
@@ -24,4 +24,4 @@ namespace :spec do
24
24
  end
25
25
  end
26
26
 
27
- task :default => ["spec:functional", "spec:acceptance"]
27
+ task default: ["spec:functional", "spec:acceptance"]
@@ -1,5 +1,13 @@
1
+ version: '{build}'
2
+
3
+ environment:
4
+ matrix:
5
+ - RUBY_VERSION: 24
6
+ - RUBY_VERSION: 23
7
+ - RUBY_VERSION: 22
8
+
1
9
  install:
2
- - set PATH=C:\Ruby24-x64\bin;C:\tools\neovim\Neovim\bin;%PATH%
10
+ - set PATH=C:\Ruby%RUBY_VERSION%\bin;C:\tools\neovim\Neovim\bin;%PATH%
3
11
  - set NVIM_RUBY_LOG_LEVEL=DEBUG
4
12
  - set NVIM_RUBY_LOG_FILE=%cd%\ci.log
5
13
  - choco install neovim --pre -fy --ignore-dependencies
@@ -35,19 +35,19 @@ require "neovim/version"
35
35
  # # Define a command called "SetLine" which sets the contents of the
36
36
  # # current line. This command is executed asynchronously, so the return
37
37
  # # value is ignored.
38
- # plug.command(:SetLine, :nargs => 1) do |nvim, str|
38
+ # plug.command(:SetLine, nargs: 1) do |nvim, str|
39
39
  # nvim.current.line = str
40
40
  # end
41
41
  #
42
42
  # # Define a function called "Sum" which adds two numbers. This function is
43
43
  # # executed synchronously, so the result of the block will be returned to
44
44
  # # nvim.
45
- # plug.function(:Sum, :nargs => 2, :sync => true) do |nvim, x, y|
45
+ # plug.function(:Sum, nargs: 2, sync: true) do |nvim, x, y|
46
46
  # x + y
47
47
  # end
48
48
  #
49
49
  # # Define an autocmd for the BufEnter event on Ruby files.
50
- # plug.autocmd(:BufEnter, :pattern => "*.rb") do |nvim|
50
+ # plug.autocmd(:BufEnter, pattern: "*.rb") do |nvim|
51
51
  # nvim.command("echom 'Ruby file, eh?'")
52
52
  # end
53
53
  # end
@@ -16,8 +16,7 @@ module Neovim
16
16
  class Client
17
17
  attr_reader :session, :api
18
18
 
19
- def self.from_event_loop(event_loop)
20
- session = Session.new(event_loop)
19
+ def self.from_event_loop(event_loop, session=Session.new(event_loop))
21
20
  api = API.new(session.request(:nvim_get_api_info))
22
21
  event_loop.register_types(api, session)
23
22
 
@@ -39,7 +38,7 @@ module Neovim
39
38
  end
40
39
 
41
40
  # Extend +respond_to?+ to support RPC methods.
42
- def respond_to?(method_name)
41
+ def respond_to?(method_name, *)
43
42
  super || rpc_methods.include?(method_name.to_sym)
44
43
  end
45
44
 
@@ -0,0 +1,69 @@
1
+ require "neovim/logging"
2
+ require "socket"
3
+ require "msgpack"
4
+
5
+ module Neovim
6
+ # @api private
7
+ class Connection
8
+ include Logging
9
+
10
+ def self.tcp(host, port)
11
+ socket = Socket.tcp(host, port)
12
+ new(socket, socket)
13
+ end
14
+
15
+ def self.unix(path)
16
+ socket = Socket.unix(path)
17
+ new(socket, socket)
18
+ end
19
+
20
+ def self.child(_argv)
21
+ argv = _argv.include?("--embed") ? _argv : _argv + ["--embed"]
22
+
23
+ io = ::IO.popen(argv, "rb+").tap do |_io|
24
+ Process.detach(_io.pid)
25
+ end
26
+
27
+ new(io, io)
28
+ end
29
+
30
+ def self.stdio
31
+ new(STDIN, STDOUT)
32
+ end
33
+
34
+ def initialize(rd, wr)
35
+ @rd, @wr = [rd, wr].each { |io| io.binmode.sync = true }
36
+
37
+ @unpacker = MessagePack::Unpacker.new(@rd)
38
+ @packer = MessagePack::Packer.new(@wr)
39
+ @running = false
40
+ end
41
+
42
+ def write(object)
43
+ log(:debug) { {object: object} }
44
+ @packer.write(object).flush
45
+ end
46
+
47
+ def read
48
+ @unpacker.read.tap do |object|
49
+ log(:debug) { {object: object} }
50
+ end
51
+ end
52
+
53
+ def register_type(id, &block)
54
+ @unpacker.register_type(id) do |data|
55
+ index = MessagePack.unpack(data)
56
+ block.call(index)
57
+ end
58
+ end
59
+
60
+ def close
61
+ [@rd, @wr].each do |io|
62
+ begin
63
+ io.close
64
+ rescue ::IOError
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -1,29 +1,24 @@
1
1
  require "neovim/logging"
2
- require "neovim/event_loop/connection"
3
- require "neovim/event_loop/message_builder"
4
- require "neovim/event_loop/serializer"
2
+ require "neovim/connection"
3
+ require "neovim/message"
5
4
 
6
5
  module Neovim
6
+ # @api private
7
7
  class EventLoop
8
8
  include Logging
9
9
 
10
- # Connect to a TCP socket.
11
10
  def self.tcp(host, port)
12
11
  new Connection.tcp(host, port)
13
12
  end
14
13
 
15
- # Connect to a UNIX domain socket.
16
14
  def self.unix(path)
17
15
  new Connection.unix(path)
18
16
  end
19
17
 
20
- # Spawn and connect to a child +nvim+ process.
21
18
  def self.child(argv)
22
19
  new Connection.child(argv)
23
20
  end
24
21
 
25
- # Connect to the current process's standard streams. This is used to
26
- # promote the current process to a Ruby plugin host.
27
22
  def self.stdio
28
23
  new Connection.stdio
29
24
  end
@@ -32,8 +27,6 @@ module Neovim
32
27
  @running = false
33
28
  @shutdown = false
34
29
  @connection = connection
35
- @serializer = Serializer.new
36
- @message_builder = MessageBuilder.new
37
30
  end
38
31
 
39
32
  def stop
@@ -45,25 +38,32 @@ module Neovim
45
38
  @shutdown = true
46
39
  end
47
40
 
48
- def request(method, *args, &response_handler)
49
- log(:debug) { {:name => method, :arguments => arg} }
50
- write(:request, method, args, response_handler)
41
+ def request(request_id, method, *args)
42
+ log(:debug) do
43
+ {
44
+ request_id: request_id,
45
+ method: method,
46
+ arguments: args
47
+ }
48
+ end
49
+
50
+ write(:request, request_id, method, args)
51
51
  end
52
52
 
53
53
  def respond(request_id, return_value, error)
54
54
  log(:debug) do
55
55
  {
56
- :request_id => request_id,
57
- :return_value => return_value,
58
- :error => error
56
+ request_id: request_id,
57
+ return_value: return_value,
58
+ error: error
59
59
  }
60
60
  end
61
61
 
62
- write(:response, request_id, return_value, error)
62
+ write(:response, request_id, error, return_value)
63
63
  end
64
64
 
65
65
  def notify(method, *args)
66
- log(:debug) { {:name => method, :arguments => args} }
66
+ log(:debug) { {name: method, arguments: args} }
67
67
  write(:notification, method, args)
68
68
  end
69
69
 
@@ -74,28 +74,26 @@ module Neovim
74
74
  break if !@running
75
75
  break if @shutdown
76
76
 
77
- @connection.read do |bytes|
78
- @serializer.read(bytes) do |obj|
79
- @message_builder.read(obj, &callback)
80
- end
77
+ begin
78
+ callback.call(read)
79
+ rescue EOFError => e
80
+ log_exception(:debug, e, __method__)
81
+ shutdown
82
+ rescue => e
83
+ log_exception(:error, e, __method__)
81
84
  end
82
85
  end
83
- rescue EOFError => ex
84
- log_exception(:debug, ex, __method__)
85
- rescue => ex
86
- log_exception(:fatal, ex, __method__)
87
86
  ensure
88
87
  @connection.close if @shutdown
89
88
  end
90
89
 
91
- # Register msgpack ext types using the provided API and session
92
90
  def register_types(api, session)
93
91
  api.types.each do |type, info|
94
92
  id = info.fetch("id")
95
93
  klass = Neovim.const_get(type)
96
- log(:debug) { {:type => type, :id => id} }
94
+ log(:debug) { {type: type, id: id} }
97
95
 
98
- @serializer.register_type(id) do |index|
96
+ @connection.register_type(id) do |index|
99
97
  klass.new(index, session, api)
100
98
  end
101
99
  end
@@ -103,12 +101,14 @@ module Neovim
103
101
 
104
102
  private
105
103
 
104
+ def read
105
+ array = @connection.read
106
+ Message.from_array(array)
107
+ end
108
+
106
109
  def write(type, *args)
107
- @message_builder.write(type, *args) do |arr|
108
- @serializer.write(arr) do |bytes|
109
- @connection.write(bytes)
110
- end
111
- end
110
+ message = Message.public_send(type, *args)
111
+ @connection.write(message.to_a)
112
112
  end
113
113
  end
114
114
  end