File: client.rb

package info (click to toggle)
ruby-neovim 0.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 548 kB
  • sloc: ruby: 4,178; sh: 23; makefile: 4
file content (716 lines) | stat: -rw-r--r-- 15,670 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
require "neovim/api"
require "neovim/current"
require "neovim/session"
require "set"

module Neovim
  # 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.10.0
  #
  # @see Buffer
  # @see Window
  # @see Tabpage
  class Client
    attr_reader :session, :api

    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

    def initialize(session, api)
      @session = session
      @api = api
    end

    def channel_id
      @api.channel_id
    end

    # Intercept method calls and delegate to appropriate RPC methods.
    def method_missing(method_name, *args)
      if (func = @api.function_for_object_method(self, method_name))
        func.call(@session, *args)
      else
        super
      end
    end

    # Extend +respond_to_missing?+ to support RPC methods.
    def respond_to_missing?(method_name, *)
      super || rpc_methods.include?(method_name.to_sym)
    end

    # Extend +methods+ to include RPC methods.
    def methods(*args)
      super | rpc_methods.to_a
    end

    # 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
    def current
      @current ||= Current.new(@session)
    end

    # 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]
    def evaluate(expr)
      @api.function_for_object_method(self, :eval).call(@session, expr)
    end

    # Display a message.
    #
    # @param string [String] The message.
    # @return [void]
    def message(string)
      out_write(string)
    end

    # 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")
    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

    def shutdown
      @session.shutdown
    end

    private

    def rpc_methods
      @rpc_methods ||=
        @api.functions_for_object(self).map(&:method_name).to_set
    end

    public

# The following methods are dynamically generated.
=begin
@method get_autocmds(opts)
  See +:h nvim_get_autocmds()+
  @param [Hash] opts
  @return [Array]

@method create_autocmd(event, opts)
  See +:h nvim_create_autocmd()+
  @param [Object] event
  @param [Hash] opts
  @return [Integer]

@method del_autocmd(id)
  See +:h nvim_del_autocmd()+
  @param [Integer] id
  @return [void]

@method clear_autocmds(opts)
  See +:h nvim_clear_autocmds()+
  @param [Hash] opts
  @return [void]

@method create_augroup(name, opts)
  See +:h nvim_create_augroup()+
  @param [String] name
  @param [Hash] opts
  @return [Integer]

@method del_augroup_by_id(id)
  See +:h nvim_del_augroup_by_id()+
  @param [Integer] id
  @return [void]

@method del_augroup_by_name(name)
  See +:h nvim_del_augroup_by_name()+
  @param [String] name
  @return [void]

@method exec_autocmds(event, opts)
  See +:h nvim_exec_autocmds()+
  @param [Object] event
  @param [Hash] opts
  @return [void]

@method parse_cmd(str, opts)
  See +:h nvim_parse_cmd()+
  @param [String] str
  @param [Hash] opts
  @return [Hash]

@method cmd(cmd, opts)
  See +:h nvim_cmd()+
  @param [Hash] cmd
  @param [Hash] opts
  @return [String]

@method create_user_command(name, command, opts)
  See +:h nvim_create_user_command()+
  @param [String] name
  @param [Object] command
  @param [Hash] opts
  @return [void]

@method del_user_command(name)
  See +:h nvim_del_user_command()+
  @param [String] name
  @return [void]

@method get_commands(opts)
  See +:h nvim_get_commands()+
  @param [Hash] opts
  @return [Hash]

@method exec(src, output)
  See +:h nvim_exec()+
  @param [String] src
  @param [Boolean] output
  @return [String]

@method command_output(command)
  See +:h nvim_command_output()+
  @param [String] command
  @return [String]

@method execute_lua(code, args)
  See +:h nvim_execute_lua()+
  @param [String] code
  @param [Array] args
  @return [Object]

@method get_hl_by_id(hl_id, rgb)
  See +:h nvim_get_hl_by_id()+
  @param [Integer] hl_id
  @param [Boolean] rgb
  @return [Hash]

@method get_hl_by_name(name, rgb)
  See +:h nvim_get_hl_by_name()+
  @param [String] name
  @param [Boolean] rgb
  @return [Hash]

@method get_option_info(name)
  See +:h nvim_get_option_info()+
  @param [String] name
  @return [Hash]

@method get_option(name)
  See +:h nvim_get_option()+
  @param [String] name
  @return [Object]

@method call_atomic(calls)
  See +:h nvim_call_atomic()+
  @param [Array] calls
  @return [Array]

@method create_namespace(name)
  See +:h nvim_create_namespace()+
  @param [String] name
  @return [Integer]

@method get_namespaces
  See +:h nvim_get_namespaces()+
  @return [Hash]

@method set_decoration_provider(ns_id, opts)
  See +:h nvim_set_decoration_provider()+
  @param [Integer] ns_id
  @param [Hash] opts
  @return [void]

@method get_option_value(name, opts)
  See +:h nvim_get_option_value()+
  @param [String] name
  @param [Hash] opts
  @return [Object]

@method set_option_value(name, value, opts)
  See +:h nvim_set_option_value()+
  @param [String] name
  @param [Object] value
  @param [Hash] opts
  @return [void]

@method get_all_options_info
  See +:h nvim_get_all_options_info()+
  @return [Hash]

@method get_option_info2(name, opts)
  See +:h nvim_get_option_info2()+
  @param [String] name
  @param [Hash] opts
  @return [Hash]

@method ui_attach(width, height, options)
  See +:h nvim_ui_attach()+
  @param [Integer] width
  @param [Integer] height
  @param [Hash] options
  @return [void]

@method ui_set_focus(gained)
  See +:h nvim_ui_set_focus()+
  @param [Boolean] gained
  @return [void]

@method ui_detach
  See +:h nvim_ui_detach()+
  @return [void]

@method ui_try_resize(width, height)
  See +:h nvim_ui_try_resize()+
  @param [Integer] width
  @param [Integer] height
  @return [void]

@method ui_set_option(name, value)
  See +:h nvim_ui_set_option()+
  @param [String] name
  @param [Object] value
  @return [void]

@method ui_try_resize_grid(grid, width, height)
  See +:h nvim_ui_try_resize_grid()+
  @param [Integer] grid
  @param [Integer] width
  @param [Integer] height
  @return [void]

@method ui_pum_set_height(height)
  See +:h nvim_ui_pum_set_height()+
  @param [Integer] height
  @return [void]

@method ui_pum_set_bounds(width, height, row, col)
  See +:h nvim_ui_pum_set_bounds()+
  @param [Float] width
  @param [Float] height
  @param [Float] row
  @param [Float] col
  @return [void]

@method ui_term_event(event, value)
  See +:h nvim_ui_term_event()+
  @param [String] event
  @param [Object] value
  @return [void]

@method get_hl_id_by_name(name)
  See +:h nvim_get_hl_id_by_name()+
  @param [String] name
  @return [Integer]

@method get_hl(ns_id, opts)
  See +:h nvim_get_hl()+
  @param [Integer] ns_id
  @param [Hash] opts
  @return [Hash]

@method set_hl(ns_id, name, val)
  See +:h nvim_set_hl()+
  @param [Integer] ns_id
  @param [String] name
  @param [Hash] val
  @return [void]

@method get_hl_ns(opts)
  See +:h nvim_get_hl_ns()+
  @param [Hash] opts
  @return [Integer]

@method set_hl_ns(ns_id)
  See +:h nvim_set_hl_ns()+
  @param [Integer] ns_id
  @return [void]

@method set_hl_ns_fast(ns_id)
  See +:h nvim_set_hl_ns_fast()+
  @param [Integer] ns_id
  @return [void]

@method feedkeys(keys, mode, escape_ks)
  See +:h nvim_feedkeys()+
  @param [String] keys
  @param [String] mode
  @param [Boolean] escape_ks
  @return [void]

@method input(keys)
  See +:h nvim_input()+
  @param [String] keys
  @return [Integer]

@method input_mouse(button, action, modifier, grid, row, col)
  See +:h nvim_input_mouse()+
  @param [String] button
  @param [String] action
  @param [String] modifier
  @param [Integer] grid
  @param [Integer] row
  @param [Integer] col
  @return [void]

@method replace_termcodes(str, from_part, do_lt, special)
  See +:h nvim_replace_termcodes()+
  @param [String] str
  @param [Boolean] from_part
  @param [Boolean] do_lt
  @param [Boolean] special
  @return [String]

@method exec_lua(code, args)
  See +:h nvim_exec_lua()+
  @param [String] code
  @param [Array] args
  @return [Object]

@method notify(msg, log_level, opts)
  See +:h nvim_notify()+
  @param [String] msg
  @param [Integer] log_level
  @param [Hash] opts
  @return [Object]

@method strwidth(text)
  See +:h nvim_strwidth()+
  @param [String] text
  @return [Integer]

@method list_runtime_paths
  See +:h nvim_list_runtime_paths()+
  @return [Array<String>]

@method get_runtime_file(name, all)
  See +:h nvim_get_runtime_file()+
  @param [String] name
  @param [Boolean] all
  @return [Array<String>]

@method set_current_dir(dir)
  See +:h nvim_set_current_dir()+
  @param [String] dir
  @return [void]

@method get_current_line
  See +:h nvim_get_current_line()+
  @return [String]

@method set_current_line(line)
  See +:h nvim_set_current_line()+
  @param [String] line
  @return [void]

@method del_current_line
  See +:h nvim_del_current_line()+
  @return [void]

@method get_var(name)
  See +:h nvim_get_var()+
  @param [String] name
  @return [Object]

@method set_var(name, value)
  See +:h nvim_set_var()+
  @param [String] name
  @param [Object] value
  @return [void]

@method del_var(name)
  See +:h nvim_del_var()+
  @param [String] name
  @return [void]

@method get_vvar(name)
  See +:h nvim_get_vvar()+
  @param [String] name
  @return [Object]

@method set_vvar(name, value)
  See +:h nvim_set_vvar()+
  @param [String] name
  @param [Object] value
  @return [void]

@method echo(chunks, history, opts)
  See +:h nvim_echo()+
  @param [Array] chunks
  @param [Boolean] history
  @param [Hash] opts
  @return [void]

@method out_write(str)
  See +:h nvim_out_write()+
  @param [String] str
  @return [void]

@method err_write(str)
  See +:h nvim_err_write()+
  @param [String] str
  @return [void]

@method err_writeln(str)
  See +:h nvim_err_writeln()+
  @param [String] str
  @return [void]

@method list_bufs
  See +:h nvim_list_bufs()+
  @return [Array<Buffer>]

@method get_current_buf
  See +:h nvim_get_current_buf()+
  @return [Buffer]

@method set_current_buf(buffer)
  See +:h nvim_set_current_buf()+
  @param [Buffer] buffer
  @return [void]

@method list_wins
  See +:h nvim_list_wins()+
  @return [Array<Window>]

@method get_current_win
  See +:h nvim_get_current_win()+
  @return [Window]

@method set_current_win(window)
  See +:h nvim_set_current_win()+
  @param [Window] window
  @return [void]

@method create_buf(listed, scratch)
  See +:h nvim_create_buf()+
  @param [Boolean] listed
  @param [Boolean] scratch
  @return [Buffer]

@method open_term(buffer, opts)
  See +:h nvim_open_term()+
  @param [Buffer] buffer
  @param [Hash] opts
  @return [Integer]

@method chan_send(chan, data)
  See +:h nvim_chan_send()+
  @param [Integer] chan
  @param [String] data
  @return [void]

@method list_tabpages
  See +:h nvim_list_tabpages()+
  @return [Array<Tabpage>]

@method get_current_tabpage
  See +:h nvim_get_current_tabpage()+
  @return [Tabpage]

@method set_current_tabpage(tabpage)
  See +:h nvim_set_current_tabpage()+
  @param [Tabpage] tabpage
  @return [void]

@method paste(data, crlf, phase)
  See +:h nvim_paste()+
  @param [String] data
  @param [Boolean] crlf
  @param [Integer] phase
  @return [Boolean]

@method put(lines, type, after, follow)
  See +:h nvim_put()+
  @param [Array<String>] lines
  @param [String] type
  @param [Boolean] after
  @param [Boolean] follow
  @return [void]

@method subscribe(event)
  See +:h nvim_subscribe()+
  @param [String] event
  @return [void]

@method unsubscribe(event)
  See +:h nvim_unsubscribe()+
  @param [String] event
  @return [void]

@method get_color_by_name(name)
  See +:h nvim_get_color_by_name()+
  @param [String] name
  @return [Integer]

@method get_color_map
  See +:h nvim_get_color_map()+
  @return [Hash]

@method get_context(opts)
  See +:h nvim_get_context()+
  @param [Hash] opts
  @return [Hash]

@method load_context(dict)
  See +:h nvim_load_context()+
  @param [Hash] dict
  @return [Object]

@method get_mode
  See +:h nvim_get_mode()+
  @return [Hash]

@method get_keymap(mode)
  See +:h nvim_get_keymap()+
  @param [String] mode
  @return [Array<Hash>]

@method set_keymap(mode, lhs, rhs, opts)
  See +:h nvim_set_keymap()+
  @param [String] mode
  @param [String] lhs
  @param [String] rhs
  @param [Hash] opts
  @return [void]

@method del_keymap(mode, lhs)
  See +:h nvim_del_keymap()+
  @param [String] mode
  @param [String] lhs
  @return [void]

@method get_api_info
  See +:h nvim_get_api_info()+
  @return [Array]

@method set_client_info(name, version, type, methods, attributes)
  See +:h nvim_set_client_info()+
  @param [String] name
  @param [Hash] version
  @param [String] type
  @param [Hash] methods
  @param [Hash] attributes
  @return [void]

@method get_chan_info(chan)
  See +:h nvim_get_chan_info()+
  @param [Integer] chan
  @return [Hash]

@method list_chans
  See +:h nvim_list_chans()+
  @return [Array]

@method list_uis
  See +:h nvim_list_uis()+
  @return [Array]

@method get_proc_children(pid)
  See +:h nvim_get_proc_children()+
  @param [Integer] pid
  @return [Array]

@method get_proc(pid)
  See +:h nvim_get_proc()+
  @param [Integer] pid
  @return [Object]

@method select_popupmenu_item(item, insert, finish, opts)
  See +:h nvim_select_popupmenu_item()+
  @param [Integer] item
  @param [Boolean] insert
  @param [Boolean] finish
  @param [Hash] opts
  @return [void]

@method del_mark(name)
  See +:h nvim_del_mark()+
  @param [String] name
  @return [Boolean]

@method get_mark(name, opts)
  See +:h nvim_get_mark()+
  @param [String] name
  @param [Hash] opts
  @return [Array]

@method eval_statusline(str, opts)
  See +:h nvim_eval_statusline()+
  @param [String] str
  @param [Hash] opts
  @return [Hash]

@method exec2(src, opts)
  See +:h nvim_exec2()+
  @param [String] src
  @param [Hash] opts
  @return [Hash]

@method command(command)
  See +:h nvim_command()+
  @param [String] command
  @return [void]

@method eval(expr)
  See +:h nvim_eval()+
  @param [String] expr
  @return [Object]

@method call_function(fn, args)
  See +:h nvim_call_function()+
  @param [String] fn
  @param [Array] args
  @return [Object]

@method call_dict_function(dict, fn, args)
  See +:h nvim_call_dict_function()+
  @param [Object] dict
  @param [String] fn
  @param [Array] args
  @return [Object]

@method parse_expression(expr, flags, highlight)
  See +:h nvim_parse_expression()+
  @param [String] expr
  @param [String] flags
  @param [Boolean] highlight
  @return [Hash]

@method open_win(buffer, enter, config)
  See +:h nvim_open_win()+
  @param [Buffer] buffer
  @param [Boolean] enter
  @param [Hash] config
  @return [Window]

=end
  end
end