Class: Neovim::Host

Inherits:
Remote show all
Defined in:
lib/neovim/host.rb

Constant Summary collapse

BASE =
:base

Constants included from Logging

Logging::DEFAULT_LEVEL, Logging::LEVELS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Remote

#add_plugins, #execute_handler, #start, start_client

Methods inherited from Session

#execute_handler, #notify, open, #request, #run

Methods included from Logging

put

Constructor Details

#initialize(conn) ⇒ Host

Returns a new instance of Host.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/neovim/host.rb', line 26

def initialize conn
  super
  DslPlain.open BASE, self do |dsl|
    dsl.plain "poll" do
      start
      @plugins.each_value { |p| p.setup @conn.client }
      "ok"
    end
    dsl.plain "specs", nargs: 1 do |source|
      p = @plugins[ source]
      p or raise "Unknown plugin #{source}"
      p.specs
    end
    dsl.plain "nvim_error_event", nargs: 2 do |errid,msg|
      raise "#{@conn.error errid} from Neovim: #{msg}"
    end
  end
end

Instance Attribute Details

#pluginsObject (readonly)

Returns the value of attribute plugins.



22
23
24
# File 'lib/neovim/host.rb', line 22

def plugins
  @plugins
end

Class Method Details

.runObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/neovim/host.rb', line 63

def run
  $stdin.tty? and raise "This program expects to be called by Neovim. It can't run interactively."
  Host.start do |h|
    yield h
    h.run
    nil
  rescue Messager::Disconnected
    log :fatal, "Disconnected"
    nil
  rescue SignalException
    n = $!.signm
    log :fatal, "Signal was caught: #{n}"
    (n =~ /\A(?:SIG)?TERM\z/) ? 0 : 1
  rescue Exception
    log_exception :fatal
    2
  end
end

.startObject



14
15
16
17
18
# File 'lib/neovim/host.rb', line 14

def start
  super ConnectionStdio do |h|
    yield h
  end
end

Instance Method Details

#client_methodsObject



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

def client_methods
  r = {}
  @plugins[ BASE].options { |name,opts| r[ name] = opts }
  r
end

#client_nameObject



45
46
47
48
49
50
51
52
# File 'lib/neovim/host.rb', line 45

def client_name
  types = @plugins.map { |_,p| p.type if p.type != BASE }
  types.uniq!
  types.compact!
  name = types.join "-"
  log :info, "Client Name", name: name
  "ruby-#{name}-host"
end