Class: Neovim::API

Inherits:
Object
  • Object
show all
Defined in:
lib/neovim/api.rb

Defined Under Namespace

Classes: Function

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ API

Returns a new instance of API.



11
12
13
# File 'lib/neovim/api.rb', line 11

def initialize(data)
  @data = data
end

Class Method Details

.nullAPI

Represents an unknown API. Used as a stand-in when the API hasn’t been discovered yet via the vim_get_api_info RPC call.

Returns:



7
8
9
# File 'lib/neovim/api.rb', line 7

def self.null
  new([nil, {"functions" => [], "types" => []}])
end

Instance Method Details

#channel_idFixnum?

Return the channel ID of the current RPC session.

Returns:

  • (Fixnum, nil)


36
37
38
# File 'lib/neovim/api.rb', line 36

def channel_id
  @channel_id ||= @data.fetch(0)
end

#function(name) ⇒ Function?

Find a function with the given name.

Parameters:

  • name (String)

    The name of the function

Returns:



54
55
56
57
58
# File 'lib/neovim/api.rb', line 54

def function(name)
  functions.find do |func|
    func.name == name.to_s
  end
end

#functionsArray<Function>

Return all functions defined by the API, as Function objects.

Returns:

See Also:



19
20
21
22
23
# File 'lib/neovim/api.rb', line 19

def functions
  @functions ||= @data.fetch(1).fetch("functions").map do |func|
    Function.new(func["name"], func["async"])
  end
end

#functions_with_prefix(prefix) ⇒ Array<Function>

Return a list of functions with the given name prefix.

Parameters:

  • prefix (String)

    The function prefix

Returns:



44
45
46
47
48
# File 'lib/neovim/api.rb', line 44

def functions_with_prefix(prefix)
  functions.select do |function|
    function.name =~ /\A#{prefix}/
  end
end

#inspectString

Truncate the output of inspect so console sessions are more pleasant.

Returns:

  • (String)


63
64
65
# File 'lib/neovim/api.rb', line 63

def inspect
  "#<#{self.class}:0x%x @types={...} @functions={...}>" % (object_id << 1)
end

#typesHash

Return information about nvim types. Used for registering MessagePack ext types.

Returns:

  • (Hash)


29
30
31
# File 'lib/neovim/api.rb', line 29

def types
  @types ||= @data.fetch(1).fetch("types")
end