lib/neovim/ruby_provider.rb in neovim-0.7.0 vs lib/neovim/ruby_provider.rb in neovim-0.7.1
- old
+ new
@@ -1,8 +1,9 @@
require "neovim/ruby_provider/vim"
require "neovim/ruby_provider/buffer_ext"
require "neovim/ruby_provider/window_ext"
+require "stringio"
module Neovim
# This class is used to define a +Neovim::Plugin+ to act as a backend for the
# +:ruby+, +:rubyfile+, and +:rubydo+ Vim commands. It is autoloaded from
# +nvim+ and not intended to be required directly.
@@ -19,14 +20,11 @@
__define_ruby_do_range(plug)
__define_ruby_chdir(plug)
end
end
- # Bootstrap the provider client:
- #
- # 1. Monkeypatch +$stdout+ and +$stderr+ to write to +nvim+.
- # 2. Define the +DirChanged+ event to update the provider's pwd.
+ # Define the +DirChanged+ event to update the provider's pwd.
def self.__define_setup(plug)
plug.__send__(:setup) do |client|
begin
cid = client.api.channel_id
client.command("au DirChanged * call rpcrequest(#{cid}, 'ruby_chdir', v:event)")
@@ -106,16 +104,14 @@
nil
end
private_class_method :__wrap_client
def self.__with_exception_handling(client)
- begin
- yield
- rescue ScriptError, StandardError => e
- msg = [e.class, e.message].join(": ")
- client.err_writeln(msg)
- end
+ yield
+ rescue ScriptError, StandardError => e
+ msg = [e.class, e.message].join(": ")
+ client.err_writeln(msg)
end
private_class_method :__with_exception_handling
def self.__with_std_streams(client)
old_stdout = $stdout.dup
@@ -124,24 +120,24 @@
$stdout, $stderr = StringIO.new, StringIO.new
begin
yield
- client.out_write($stdout.string + $/) if $stdout.length > 0
- client.err_writeln($stderr.string) if $stderr.length > 0
+ client.out_write($stdout.string + $/) if $stdout.size > 0
+ client.err_writeln($stderr.string) if $stderr.size > 0
ensure
$stdout = old_stdout
$stderr = old_stderr
end
end
private_class_method :__with_std_streams
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)
+ start, stop = linenos[0] - 1, linenos[-1]
+ lines = buffer.get_lines(start, stop, true)
- buffer.set_lines(_start, _stop, true, yield(lines))
+ buffer.set_lines(start, stop, true, yield(lines))
end
end
private_class_method :__update_lines_in_chunks
end
end