class Neovim::Client

Client to a running nvim instance. The interface is generated at runtime via the nvim_get_api_info RPC call. Some methods return RemoteObject subclasses (i.e. Buffer, Window, or Tabpage), which similarly have dynamically generated interfaces.

The methods documented here were generated using NVIM v0.5.0

@see Buffer @see Window @see Tabpage

Attributes

api[R]
session[R]

Public Class Methods

from_event_loop(event_loop, session=Session.new(event_loop)) click to toggle source
# File lib/neovim/client.rb, line 20
def self.from_event_loop(event_loop, session=Session.new(event_loop))
  api = API.new(session.request(:nvim_get_api_info))
  event_loop.register_types(api, session)

  new(session, api)
end
new(session, api) click to toggle source
# File lib/neovim/client.rb, line 27
def initialize(session, api)
  @session = session
  @api = api
end

Public Instance Methods

channel_id() click to toggle source
# File lib/neovim/client.rb, line 32
def channel_id
  @api.channel_id
end
current() click to toggle source

Access to objects belonging to the current nvim context.

@return [Current] @example Get the current buffer

client.current.buffer

@example Set the current line

client.current.line = "New line"

@see Current

# File lib/neovim/client.rb, line 63
def current
  @current ||= Current.new(@session)
end
evaluate(expr) click to toggle source

Evaluate the VimL expression (alias for nvim_eval).

@param expr [String] A VimL expression. @return [Object] @example Return a list from VimL

client.evaluate('[1, 2]') # => [1, 2]
# File lib/neovim/client.rb, line 73
def evaluate(expr)
  @api.function_for_object_method(self, :eval).call(@session, expr)
end
message(string) click to toggle source

Display a message.

@param string [String] The message. @return [void]

# File lib/neovim/client.rb, line 81
def message(string)
  out_write(string)
end
method_missing(method_name, *args) click to toggle source

Intercept method calls and delegate to appropriate RPC methods.

Calls superclass method
# File lib/neovim/client.rb, line 37
def method_missing(method_name, *args)
  if (func = @api.function_for_object_method(self, method_name))
    func.call(@session, *args)
  else
    super
  end
end
methods(*args) click to toggle source

Extend methods to include RPC methods.

Calls superclass method
# File lib/neovim/client.rb, line 51
def methods(*args)
  super | rpc_methods.to_a
end
respond_to_missing?(method_name, *) click to toggle source

Extend respond_to_missing? to support RPC methods.

Calls superclass method
# File lib/neovim/client.rb, line 46
def respond_to_missing?(method_name, *)
  super || rpc_methods.include?(method_name.to_sym)
end
set_option(*args) click to toggle source

Set an option.

@overload set_option(key, value)

@param [String] key
@param [String] value

@overload set_option(optstr)

@param [String] optstr

@example Set the timeoutlen option

client.set_option("timeoutlen", 0)
client.set_option("timeoutlen=0")
# File lib/neovim/client.rb, line 97
def set_option(*args)
  if args.size > 1
    @api.function_for_object_method(self, :set_option).call(@session, *args)
  else
    @api.function_for_object_method(self, :command).call(@session, "set #{args.first}")
  end
end
shutdown() click to toggle source
# File lib/neovim/client.rb, line 105
def shutdown
  @session.shutdown
end

Private Instance Methods

rpc_methods() click to toggle source
# File lib/neovim/client.rb, line 111
def rpc_methods
  @rpc_methods ||=
    @api.functions_for_object(self).map(&:method_name).to_set
end