neovim 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -1
  3. data/CHANGELOG.md +9 -3
  4. data/CODE_OF_CONDUCT.md +46 -0
  5. data/README.md +2 -2
  6. data/Rakefile +6 -6
  7. data/lib/neovim.rb +8 -7
  8. data/lib/neovim/api.rb +87 -0
  9. data/lib/neovim/buffer.rb +7 -1
  10. data/lib/neovim/client.rb +32 -6
  11. data/lib/neovim/event_loop.rb +114 -0
  12. data/lib/neovim/event_loop/connection.rb +78 -0
  13. data/lib/neovim/event_loop/message_builder.rb +127 -0
  14. data/lib/neovim/event_loop/serializer.rb +37 -0
  15. data/lib/neovim/host.rb +28 -28
  16. data/lib/neovim/logging.rb +41 -19
  17. data/lib/neovim/plugin/dsl.rb +6 -6
  18. data/lib/neovim/remote_object.rb +2 -2
  19. data/lib/neovim/ruby_provider.rb +8 -6
  20. data/lib/neovim/ruby_provider/vim.rb +2 -2
  21. data/lib/neovim/session.rb +42 -79
  22. data/lib/neovim/tabpage.rb +1 -1
  23. data/lib/neovim/version.rb +1 -1
  24. data/lib/neovim/window.rb +1 -1
  25. data/script/dump_api +4 -2
  26. data/script/generate_docs +2 -1
  27. data/spec/{integration → acceptance}/rplugin_autocmd_spec.vim +1 -1
  28. data/spec/{integration → acceptance}/rplugin_command_spec.vim +6 -2
  29. data/spec/{integration → acceptance}/rplugin_function_spec.vim +5 -2
  30. data/spec/{integration → acceptance}/ruby_spec.vim +18 -0
  31. data/spec/{integration → acceptance}/rubydo_spec.vim +0 -0
  32. data/spec/{integration → acceptance}/rubyfile/call_foo.rb +0 -0
  33. data/spec/{integration → acceptance}/rubyfile/curbuf_ivar_get.rb +0 -0
  34. data/spec/{integration → acceptance}/rubyfile/curbuf_ivar_set.rb +0 -0
  35. data/spec/{integration → acceptance}/rubyfile/define_foo.rb +0 -0
  36. data/spec/acceptance/rubyfile/nested.rb +1 -0
  37. data/spec/acceptance/rubyfile/nested_inner.rb +1 -0
  38. data/spec/{integration → acceptance}/rubyfile/raise_standard_error.rb +0 -0
  39. data/spec/{integration → acceptance}/rubyfile/raise_syntax_error.rb +0 -0
  40. data/spec/acceptance/rubyfile/ruby_interface.rb +8 -0
  41. data/spec/{integration → acceptance}/rubyfile/set_pwd_after.rb +0 -0
  42. data/spec/{integration → acceptance}/rubyfile/set_pwd_before.rb +0 -0
  43. data/spec/{integration → acceptance}/rubyfile_spec.vim +9 -0
  44. data/spec/acceptance/runtime/init.vim +8 -0
  45. data/spec/acceptance/runtime/rplugin.vim +37 -0
  46. data/spec/{integration → acceptance}/runtime/rplugin/ruby/autocmds.rb +1 -1
  47. data/spec/{integration → acceptance}/runtime/rplugin/ruby/commands.rb +9 -1
  48. data/spec/{integration → acceptance}/runtime/rplugin/ruby/functions.rb +9 -1
  49. data/spec/{integration → acceptance}/runtime/vader.vim/autoload/vader.vim +0 -0
  50. data/spec/{integration → acceptance}/runtime/vader.vim/autoload/vader/assert.vim +0 -0
  51. data/spec/{integration → acceptance}/runtime/vader.vim/autoload/vader/helper.vim +0 -0
  52. data/spec/{integration → acceptance}/runtime/vader.vim/autoload/vader/parser.vim +0 -0
  53. data/spec/{integration → acceptance}/runtime/vader.vim/autoload/vader/syntax.vim +0 -0
  54. data/spec/{integration → acceptance}/runtime/vader.vim/autoload/vader/window.vim +0 -0
  55. data/spec/{integration → acceptance}/runtime/vader.vim/plugin/vader.vim +0 -0
  56. data/spec/acceptance_spec.rb +74 -0
  57. data/spec/helper.rb +2 -32
  58. data/spec/neovim/api_spec.rb +59 -0
  59. data/spec/neovim/buffer_spec.rb +161 -2
  60. data/spec/neovim/client_spec.rb +18 -4
  61. data/spec/neovim/event_loop/connection_spec.rb +63 -0
  62. data/spec/neovim/event_loop/message_builder_spec.rb +105 -0
  63. data/spec/neovim/event_loop/serializer_spec.rb +63 -0
  64. data/spec/neovim/event_loop_spec.rb +81 -0
  65. data/spec/neovim/host/loader_spec.rb +0 -1
  66. data/spec/neovim/host_spec.rb +130 -161
  67. data/spec/neovim/logging_spec.rb +77 -5
  68. data/spec/neovim/session_spec.rb +54 -127
  69. data/spec/neovim/window_spec.rb +46 -0
  70. metadata +81 -81
  71. data/lib/neovim/session/api.rb +0 -95
  72. data/lib/neovim/session/event_loop.rb +0 -100
  73. data/lib/neovim/session/notification.rb +0 -19
  74. data/lib/neovim/session/request.rb +0 -31
  75. data/lib/neovim/session/rpc.rb +0 -95
  76. data/lib/neovim/session/serializer.rb +0 -62
  77. data/spec/integration/ruby_buffer_spec.rb +0 -151
  78. data/spec/integration/ruby_vim_spec.rb +0 -27
  79. data/spec/integration/ruby_window_spec.rb +0 -56
  80. data/spec/integration/runtime/init.vim +0 -9
  81. data/spec/integration_spec.rb +0 -119
  82. data/spec/neovim/session/api_spec.rb +0 -70
  83. data/spec/neovim/session/event_loop_spec.rb +0 -152
  84. data/spec/neovim/session/notification_spec.rb +0 -20
  85. data/spec/neovim/session/request_spec.rb +0 -36
  86. data/spec/neovim/session/rpc_spec.rb +0 -120
  87. data/spec/neovim/session/serializer_spec.rb +0 -62
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64c75505d6b6148e56df55a0f63f20dcc33ff329
4
- data.tar.gz: 23581eb000bf8165fcbccc01b1ef004c86f57aac
3
+ metadata.gz: 032dc3f0f775880e56b120aee0aeeb3cea3dfb9e
4
+ data.tar.gz: 794159179a08c5d1a0cc9b4793ca72a242565098
5
5
  SHA512:
6
- metadata.gz: ea759f8fe2edd4b37c2646245deffb627466633f7424e7ce0ff563e32c141d113cd4b7a2094c82cd62fbeb5238cd9bf512521ccbe3ba376996f45021f9451d10
7
- data.tar.gz: '08498a8f0928796988e6e4abe2c3e27fc1c70b8c59786898649e2acbdfd9f9f8e333dae0438b15b04fd3a51189ae421570bc91de7eb6bbe8230faaef4f7b9ae7'
6
+ metadata.gz: 3431b345bb0f720639ef25069decdf2391494c7367ddf9bdf9a6ee3f05a096b48958c2735ae5e2e8dabe808b49ee3ee84d0f48cf54930ce0d74a2dcdfa050328
7
+ data.tar.gz: 8bc6a89a0cefab81796cf2afd668f20ebf13d9e61bb62579fc55617136293d46621c8a2556a54e57c8d66a8849b0b406888349c916bac33d4073fdf3959b9bac
@@ -16,6 +16,8 @@ rvm:
16
16
 
17
17
  before_install:
18
18
  - eval "$(curl -Ss https://raw.githubusercontent.com/neovim/bot-ci/master/scripts/travis-setup.sh) nightly-x64"
19
+ - gem update bundler
20
+ - bundle --version
19
21
 
20
- env: REPORT_COVERAGE=1
22
+ env: REPORT_COVERAGE=1 NVIM_RUBY_LOG_LEVEL=DEBUG NVIM_RUBY_LOG_FILE=ci.log
21
23
  script: bundle exec rake --trace
@@ -1,3 +1,9 @@
1
+ # 0.6.0
2
+ - Refactor: consolidate "run" logic into EventLoop class to simplify middleware
3
+ layers
4
+ - Add JSON structured logging
5
+ - Regenerated docs for nvim 0.2.1
6
+
1
7
  # 0.5.1
2
8
  - Convert vader.vim from submodule to subtree so it is included in gem
3
9
  installations
@@ -20,7 +26,7 @@
20
26
  - Hotfix older nvim clients' inability to hook into DirChanged
21
27
 
22
28
  # 0.3.2
23
- - Fix directory tracking in legacy Ruby provider
29
+ - Fix directory tracking in Ruby provider
24
30
 
25
31
  # 0.3.1
26
32
  - Remove window caching to fix incompatibilities with command-t
@@ -64,7 +70,7 @@
64
70
 
65
71
  # 0.2.0
66
72
  - Backwards incompatible, but we're pre-1.0.0 so going with minor bump instead
67
- - Make legacy ruby functions 1-indexed
73
+ - Make vim ruby functions 1-indexed
68
74
  - Add Client#evaluate and Client#message
69
75
  - Make ruby functions affect global scope
70
76
  - Add VIM::{Buffer,Window}.{count,index}
@@ -95,7 +101,7 @@
95
101
  - Add support for loading Ruby remote plugins from nvim
96
102
  - Add Current#range to return a LineRange enumerable object
97
103
  - Support sending large messages
98
- - Remove unecessary #stop methods
104
+ - Remove unnecessary #stop methods
99
105
  - Add setup callback support to event loop
100
106
 
101
107
  # 0.0.3
@@ -0,0 +1,46 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ ## Our Standards
8
+
9
+ Examples of behavior that contributes to creating a positive environment include:
10
+
11
+ * Using welcoming and inclusive language
12
+ * Being respectful of differing viewpoints and experiences
13
+ * Gracefully accepting constructive criticism
14
+ * Focusing on what is best for the community
15
+ * Showing empathy towards other community members
16
+
17
+ Examples of unacceptable behavior by participants include:
18
+
19
+ * The use of sexualized language or imagery and unwelcome sexual attention or advances
20
+ * Trolling, insulting/derogatory comments, and personal or political attacks
21
+ * Public or private harassment
22
+ * Publishing others' private information, such as a physical or electronic address, without explicit permission
23
+ * Other conduct which could reasonably be considered inappropriate in a professional setting
24
+
25
+ ## Our Responsibilities
26
+
27
+ Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28
+
29
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30
+
31
+ ## Scope
32
+
33
+ This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34
+
35
+ ## Enforcement
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at alexgenco@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38
+
39
+ Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40
+
41
+ ## Attribution
42
+
43
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44
+
45
+ [homepage]: http://contributor-covenant.org
46
+ [version]: http://contributor-covenant.org/version/1/4/
data/README.md CHANGED
@@ -74,9 +74,9 @@ When you add or update a plugin, you will need to call `:UpdateRemotePlugins` to
74
74
 
75
75
  Refer to the [`Neovim::Plugin::DSL` docs](http://www.rubydoc.info/github/alexgenco/neovim-ruby/master/Neovim/Plugin/DSL) for a more complete overview of the `Neovim.plugin` DSL.
76
76
 
77
- ### Legacy Plugin Support
77
+ ### Vim Plugin Support
78
78
 
79
- 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).
79
+ The Neovim gem also acts as a compatibility layer for Ruby plugins written for `vim`. The `:ruby`, `:rubyfile`, and `:rubydo` commands are intended to match their original behavior, and their documentation can be found [here](https://neovim.io/doc/user/if_ruby.html).
80
80
 
81
81
  ## Links
82
82
 
data/Rakefile CHANGED
@@ -14,14 +14,14 @@ end
14
14
  namespace :spec do
15
15
  desc "Run functional specs"
16
16
  RSpec::Core::RakeTask.new(:functional) do |t|
17
- t.exclude_pattern = "spec/integration_spec.rb,spec/integration/**/*"
17
+ t.exclude_pattern = "spec/acceptance_spec.rb,spec/acceptance/**/*"
18
18
  end
19
19
 
20
- desc "Run integration specs"
21
- RSpec::Core::RakeTask.new(:integration) do |t|
22
- t.pattern = "spec/integration_spec.rb"
20
+ desc "Run acceptance specs"
21
+ RSpec::Core::RakeTask.new(:acceptance) do |t|
22
+ t.pattern = "spec/acceptance_spec.rb"
23
+ t.rspec_opts = "--format documentation"
23
24
  end
24
25
  end
25
26
 
26
- RSpec::Core::RakeTask.new(:spec)
27
- task :default => :spec
27
+ task :default => ["spec:functional", "spec:acceptance"]
@@ -1,7 +1,8 @@
1
1
  require "neovim/client"
2
+ require "neovim/session"
3
+ require "neovim/event_loop"
2
4
  require "neovim/executable"
3
5
  require "neovim/logging"
4
- require "neovim/session"
5
6
  require "neovim/version"
6
7
 
7
8
  # The main entrypoint to the +Neovim+ gem. It allows you to connect to a
@@ -59,27 +60,27 @@ module Neovim
59
60
  # @param host [String] The hostname or IP address
60
61
  # @param port [Integer] The port
61
62
  # @return [Client]
62
- # @see Session.tcp
63
+ # @see EventLoop.tcp
63
64
  def self.attach_tcp(host, port)
64
- Client.new Session.tcp(host, port)
65
+ Client.from_event_loop EventLoop.tcp(host, port)
65
66
  end
66
67
 
67
68
  # Connect to a running +nvim+ instance over a UNIX domain socket.
68
69
  #
69
70
  # @param socket_path [String] The socket path
70
71
  # @return [Client]
71
- # @see Session.unix
72
+ # @see EventLoop.unix
72
73
  def self.attach_unix(socket_path)
73
- Client.new Session.unix(socket_path)
74
+ Client.from_event_loop EventLoop.unix(socket_path)
74
75
  end
75
76
 
76
77
  # Spawn and connect to a child +nvim+ process.
77
78
  #
78
79
  # @param argv [Array] The arguments to pass to the spawned process
79
80
  # @return [Client]
80
- # @see Session.child
81
+ # @see EventLoop.child
81
82
  def self.attach_child(argv=[executable.path])
82
- Client.new Session.child(argv)
83
+ Client.from_event_loop EventLoop.child(argv)
83
84
  end
84
85
 
85
86
  # Placeholder method for exposing the remote plugin DSL. This gets
@@ -0,0 +1,87 @@
1
+ module Neovim
2
+ # @api private
3
+ class API
4
+ attr_reader :channel_id
5
+
6
+ def initialize(payload)
7
+ @channel_id, @api_info = payload
8
+ end
9
+
10
+ # Return all functions defined by the API.
11
+ def functions
12
+ @functions ||= @api_info.fetch("functions").inject({}) do |acc, func|
13
+ function = Function.new(func)
14
+ acc.merge(function.name => function)
15
+ end
16
+ end
17
+
18
+ # Return information about +nvim+ types. Used for registering MessagePack
19
+ # +ext+ types.
20
+ def types
21
+ @types ||= @api_info.fetch("types")
22
+ end
23
+
24
+ def function_for_object_method(obj, method_name)
25
+ functions[function_name(obj, method_name)]
26
+ end
27
+
28
+ def functions_for_object(obj)
29
+ pattern = function_pattern(obj)
30
+ functions.values.select { |func| func.name =~ pattern }
31
+ end
32
+
33
+ # Truncate the output of inspect so console sessions are more pleasant.
34
+ def inspect
35
+ "#<#{self.class}:0x%x @channel_id=#{@channel_id.inspect} @types={...} @functions={...}>" % (object_id << 1)
36
+ end
37
+
38
+ private
39
+
40
+ def function_name(obj, method_name)
41
+ case obj
42
+ when Client
43
+ "nvim_#{method_name}"
44
+ when Buffer
45
+ "nvim_buf_#{method_name}"
46
+ when Window
47
+ "nvim_win_#{method_name}"
48
+ when Tabpage
49
+ "nvim_tabpage_#{method_name}"
50
+ else
51
+ raise "Unknown object #{obj.inspect}"
52
+ end
53
+ end
54
+
55
+ def function_pattern(obj)
56
+ case obj
57
+ when Client
58
+ /^nvim_(?!(buf|win|tabpage)_)/
59
+ when Buffer
60
+ /^nvim_buf_/
61
+ when Window
62
+ /^nvim_win_/
63
+ when Tabpage
64
+ /^nvim_tabpage_/
65
+ else
66
+ raise "Unknown object #{obj.inspect}"
67
+ end
68
+ end
69
+
70
+ class Function
71
+ attr_reader :name
72
+
73
+ def initialize(attributes)
74
+ @name = attributes.fetch("name")
75
+ end
76
+
77
+ def method_name
78
+ @name.sub(/^nvim_(win_|buf_|tabpage_)?/, "").to_sym
79
+ end
80
+
81
+ # Apply this function to a running RPC session.
82
+ def call(session, *args)
83
+ session.request(name, *args)
84
+ end
85
+ end
86
+ end
87
+ end
@@ -4,7 +4,7 @@ require "neovim/line_range"
4
4
  module Neovim
5
5
  # Class representing an +nvim+ buffer.
6
6
  #
7
- # The methods documented here were generated using NVIM v0.2.0
7
+ # The methods documented here were generated using NVIM v0.2.1
8
8
  class Buffer < RemoteObject
9
9
  attr_reader :lines
10
10
 
@@ -176,6 +176,12 @@ module Neovim
176
176
  @param [Buffer] buffer
177
177
  @return [Integer]
178
178
 
179
+ @method get_keymap(buffer, mode)
180
+ See +:h nvim_buf_get_keymap()+
181
+ @param [Buffer] buffer
182
+ @param [String] mode
183
+ @return [Array<Hash>]
184
+
179
185
  @method set_var(buffer, name, value)
180
186
  See +:h nvim_buf_set_var()+
181
187
  @param [Buffer] buffer
@@ -1,4 +1,6 @@
1
+ require "neovim/api"
1
2
  require "neovim/current"
3
+ require "neovim/session"
2
4
 
3
5
  module Neovim
4
6
  # Client to a running +nvim+ instance. The interface is generated at
@@ -6,20 +8,25 @@ module Neovim
6
8
  # +RemoteObject+ subclasses (i.e. +Buffer+, +Window+, or +Tabpage+),
7
9
  # which similarly have dynamically generated interfaces.
8
10
  #
9
- # The methods documented here were generated using NVIM v0.2.0
11
+ # The methods documented here were generated using NVIM v0.2.1
10
12
  #
11
13
  # @see Buffer
12
14
  # @see Window
13
15
  # @see Tabpage
14
16
  class Client
15
- attr_reader :session, :channel_id
17
+ attr_reader :session, :api
16
18
 
17
- def initialize(session)
18
- session.discover_api
19
+ def self.from_event_loop(event_loop)
20
+ session = Session.new(event_loop)
21
+ api = API.new(session.request(:nvim_get_api_info))
22
+ event_loop.register_types(api, session)
19
23
 
24
+ new(session, api)
25
+ end
26
+
27
+ def initialize(session, api)
20
28
  @session = session
21
- @api = session.api
22
- @channel_id = session.channel_id
29
+ @api = api
23
30
  end
24
31
 
25
32
  # Intercept method calls and delegate to appropriate RPC methods.
@@ -129,6 +136,16 @@ module Neovim
129
136
  See +:h nvim_command()+
130
137
  @return [void]
131
138
 
139
+ @method get_hl_by_name(rgb)
140
+ See +:h nvim_get_hl_by_name()+
141
+ @param [Boolean] rgb
142
+ @return [Hash]
143
+
144
+ @method get_hl_by_id(rgb)
145
+ See +:h nvim_get_hl_by_id()+
146
+ @param [Boolean] rgb
147
+ @return [Hash]
148
+
132
149
  @method feedkeys(mode, escape_csi)
133
150
  See +:h nvim_feedkeys()+
134
151
  @param [String] mode
@@ -159,6 +176,11 @@ module Neovim
159
176
  @param [Array] args
160
177
  @return [Object]
161
178
 
179
+ @method execute_lua(args)
180
+ See +:h nvim_execute_lua()+
181
+ @param [Array] args
182
+ @return [Object]
183
+
162
184
  @method strwidth
163
185
  See +:h nvim_strwidth()+
164
186
  @return [Integer]
@@ -272,6 +294,10 @@ module Neovim
272
294
  See +:h nvim_get_mode()+
273
295
  @return [Hash]
274
296
 
297
+ @method get_keymap
298
+ See +:h nvim_get_keymap()+
299
+ @return [Array<Hash>]
300
+
275
301
  @method get_api_info
276
302
  See +:h nvim_get_api_info()+
277
303
  @return [Array]
@@ -0,0 +1,114 @@
1
+ require "neovim/logging"
2
+ require "neovim/event_loop/connection"
3
+ require "neovim/event_loop/message_builder"
4
+ require "neovim/event_loop/serializer"
5
+
6
+ module Neovim
7
+ class EventLoop
8
+ include Logging
9
+
10
+ # Connect to a TCP socket.
11
+ def self.tcp(host, port)
12
+ new Connection.tcp(host, port)
13
+ end
14
+
15
+ # Connect to a UNIX domain socket.
16
+ def self.unix(path)
17
+ new Connection.unix(path)
18
+ end
19
+
20
+ # Spawn and connect to a child +nvim+ process.
21
+ def self.child(argv)
22
+ new Connection.child(argv)
23
+ end
24
+
25
+ # Connect to the current process's standard streams. This is used to
26
+ # promote the current process to a Ruby plugin host.
27
+ def self.stdio
28
+ new Connection.stdio
29
+ end
30
+
31
+ def initialize(connection)
32
+ @running = false
33
+ @shutdown = false
34
+ @connection = connection
35
+ @serializer = Serializer.new
36
+ @message_builder = MessageBuilder.new
37
+ end
38
+
39
+ def stop
40
+ @running = false
41
+ end
42
+
43
+ def shutdown
44
+ stop
45
+ @shutdown = true
46
+ end
47
+
48
+ def request(method, *args, &response_handler)
49
+ log(:debug) { {:name => method, :arguments => arg} }
50
+ write(:request, method, args, response_handler)
51
+ end
52
+
53
+ def respond(request_id, return_value, error)
54
+ log(:debug) do
55
+ {
56
+ :request_id => request_id,
57
+ :return_value => return_value,
58
+ :error => error
59
+ }
60
+ end
61
+
62
+ write(:response, request_id, return_value, error)
63
+ end
64
+
65
+ def notify(method, *args)
66
+ log(:debug) { {:name => method, :arguments => args} }
67
+ write(:notification, method, args)
68
+ end
69
+
70
+ def run(&callback)
71
+ @running = true
72
+
73
+ loop do
74
+ break if !@running
75
+ break if @shutdown
76
+
77
+ @connection.read do |bytes|
78
+ @serializer.read(bytes) do |obj|
79
+ @message_builder.read(obj, &callback)
80
+ end
81
+ end
82
+ end
83
+ rescue EOFError => ex
84
+ log_exception(:debug, ex, __method__)
85
+ rescue => ex
86
+ log_exception(:fatal, ex, __method__)
87
+ ensure
88
+ @connection.close if @shutdown
89
+ end
90
+
91
+ # Register msgpack ext types using the provided API and session
92
+ def register_types(api, session)
93
+ api.types.each do |type, info|
94
+ id = info.fetch("id")
95
+ klass = Neovim.const_get(type)
96
+ log(:debug) { {:type => type, :id => id} }
97
+
98
+ @serializer.register_type(id) do |index|
99
+ klass.new(index, session, api)
100
+ end
101
+ end
102
+ end
103
+
104
+ private
105
+
106
+ 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
112
+ end
113
+ end
114
+ end