lib/neovim/ruby_provider.rb in neovim-0.2.5 vs lib/neovim/ruby_provider.rb in neovim-0.3.0
- old
+ new
@@ -3,11 +3,11 @@
require "neovim/ruby_provider/window_ext"
module Neovim
# This class is used to define a +Neovim::Plugin+ to act as a backend for the
# legacy +:ruby+, +:rubyfile+, and +:rubydo+ Vim commands. It is autoloaded
- # from +nvim+ and not intended to be loaded directly.
+ # from +nvim+ and not intended to be required directly.
#
# @api private
module RubyProvider
def self.__define_plugin!
Thread.abort_on_exception = true
@@ -22,11 +22,11 @@
# Evaluate the provided Ruby code, exposing the +VIM+ constant for
# interactions with the editor.
#
# This is used by the +:ruby+ command.
def self.__define_ruby_execute(plug)
- plug.rpc(:ruby_execute, sync: true) do |nvim, ruby|
+ plug.__send__(:rpc, :ruby_execute) do |nvim, ruby|
__wrap_client(nvim) do
eval(ruby, TOPLEVEL_BINDING, __FILE__, __LINE__)
end
end
end
@@ -35,11 +35,11 @@
# Evaluate the provided Ruby file, exposing the +VIM+ constant for
# interactions with the editor.
#
# This is used by the +:rubyfile+ command.
def self.__define_ruby_execute_file(plug)
- plug.rpc(:ruby_execute_file, sync: true) do |nvim, path|
+ plug.__send__(:rpc, :ruby_execute_file) do |nvim, path|
__wrap_client(nvim) { load(path) }
end
end
private_class_method :__define_ruby_execute_file
@@ -50,11 +50,11 @@
# variables and methods are available to the user. Thus the +__+ prefix
# obfuscation.
#
# This is used by the +:rubydo+ command.
def self.__define_ruby_do_range(__plug)
- __plug.rpc(:ruby_do_range, sync: true) do |__nvim, *__args|
+ __plug.__send__(:rpc, :ruby_do_range) do |__nvim, *__args|
__wrap_client(__nvim) do
__start, __stop, __ruby = __args
__buffer = __nvim.get_current_buffer
__update_lines_in_chunks(__buffer, __start, __stop, 5000) do |__lines|
@@ -67,11 +67,10 @@
end
end
end
private_class_method :__define_ruby_do_range
- # @api private
def self.__wrap_client(client)
__with_globals(client) do
__with_vim_constant(client) do
__with_redirect_streams(client) do
yield
@@ -80,38 +79,34 @@
end
nil
end
private_class_method :__wrap_client
- # @api private
def self.__with_globals(client)
@__buffer_cache ||= {}
@__window_cache ||= {}
- __bufnr = client.evaluate("bufnr('%')")
- __winnr = client.evaluate("winnr()")
+ bufnr, winnr = client.evaluate("[bufnr('%'), winnr()]")
- $curbuf = @__buffer_cache.fetch(__bufnr) do
- @__buffer_cache[__bufnr] = client.get_current_buffer
+ $curbuf = @__buffer_cache.fetch(bufnr) do
+ @__buffer_cache[bufnr] = client.get_current_buffer
end
- $curwin = @__window_cache.fetch(__winnr) do
- @__window_cache[__winnr] = client.get_current_window
+ $curwin = @__window_cache.fetch(winnr) do
+ @__window_cache[winnr] = client.get_current_window
end
yield
end
private_class_method :__with_globals
- # @api private
def self.__with_vim_constant(client)
::VIM.__client = client
yield
end
private_class_method :__with_vim_constant
- # @api private
def self.__with_redirect_streams(client)
@__with_redirect_streams ||= begin
$stdout.define_singleton_method(:write) do |string|
client.out_write(string)
end
@@ -125,10 +120,9 @@
yield
end
private_class_method :__with_redirect_streams
- # @api private
def self.__update_lines_in_chunks(buffer, start, stop, size)
(start..stop).each_slice(size) do |linenos|
_start, _stop = linenos[0]-1, linenos[-1]
lines = buffer.get_lines(_start, _stop, true)