Sha256: f09ebc38f6970fa8270631eb22aa0f4d46f1bc2204e0edeeebde8676208d9208

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

require "neovim/client"
require "neovim/event_loop"
require "neovim/logging"
require "neovim/remote_module/dsl"
require "neovim/session"

module Neovim
  class RemoteModule
    include Logging

    def self.from_config_block(&block)
      new(DSL::new(&block).handlers)
    end

    def initialize(handlers)
      @handlers = handlers
    end

    def start
      event_loop = EventLoop.stdio
      session = Session.new(event_loop)
      client = nil

      session.run do |message|
        case message
        when Message::Request
          begin
            client ||= Client.from_event_loop(event_loop, session)
            args = message.arguments.flatten(1)

            @handlers[message.method_name].call(client, *args).tap do |rv|
              session.respond(message.id, rv, nil) if message.sync?
            end
          rescue => e
            log_exception(:error, e, __method__)
            session.respond(message.id, nil, e.message) if message.sync?
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
neovim-0.10.0 lib/neovim/remote_module.rb