vimamsa 0.1.28 → 0.1.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -153,7 +153,7 @@ class Buffer < String
153
153
  # created during startup before editor.rb requires langservp, so require
154
154
  # it on demand. require is idempotent, so this is cheap after first load.
155
155
  require "vimamsa/langservp"
156
- @lsp = LangSrv.get(@lang)
156
+ @lsp = LangSrv.get(@lang, @fname)
157
157
 
158
158
  if @lang == "php"
159
159
  # Ripl.start :binding => binding
@@ -16,7 +16,10 @@ module Vimamsa
16
16
  # menu item again, the key log's ✕, or switching to a buffer that isn't one
17
17
  # of the demo's (or the file explorer).
18
18
  # The buttons above the key log (and the help.demo.* actions) pause and
19
- # continue it and change its speed. When it stops, the key log panel is
19
+ # continue it and change its speed. While it plays, the user's keys and mouse
20
+ # clicks in the text are ignored (DemoPlayer.blocks_input?); paused, the
21
+ # editor can be used, and if a demo buffer was changed (its text, cursor,
22
+ # mode or the current buffer), continuing starts the demo from the beginning. When it stops, the key log panel is
20
23
  # hidden again if it wasn't shown before.
21
24
  class DemoPlayer
22
25
  DIR = File.expand_path("../../scripts/demo", __dir__)
@@ -102,6 +105,20 @@ class DemoPlayer
102
105
  nil
103
106
  end
104
107
 
108
+ # A demo is playing (not paused): the GUI ignores the user's keys and
109
+ # mouse clicks in the text, which would change what the demo's keys do
110
+ def self.blocks_input?
111
+ !!(@current&.running? && !@current.paused?)
112
+ end
113
+
114
+ # Called by the GUI for an ignored key or click
115
+ def self.input_blocked
116
+ t = Process.clock_gettime(Process::CLOCK_MONOTONIC)
117
+ return if @blocked_msg_at && t - @blocked_msg_at < 2
118
+ @blocked_msg_at = t
119
+ message("A demo is playing: pause it (the button above the key log) to use the editor")
120
+ end
121
+
105
122
  def self.pause_toggle = playing&.toggle_pause
106
123
  def self.faster = playing&.faster
107
124
  def self.slower = playing&.slower
@@ -142,6 +159,7 @@ class DemoPlayer
142
159
  return if !@running || @paused
143
160
  @paused = true
144
161
  remove_timer
162
+ @paused_state = state
145
163
  show_controls
146
164
  message("Demo paused")
147
165
  end
@@ -150,9 +168,18 @@ class DemoPlayer
150
168
  def resume
151
169
  return if !@running || !@paused
152
170
  @paused = false
171
+ changed = @paused_state && state != @paused_state
172
+ @paused_state = nil
153
173
  show_controls
154
- message("Demo continues")
155
- run_next
174
+ # Edited while paused (or the cursor moved): the rest of the steps would
175
+ # not do what they should, so the demo starts from the beginning
176
+ if changed && (demo_buf?(vma.buf) || explorer_buf?(vma.buf))
177
+ message("The demo starts from the beginning (the buffer was changed while paused)")
178
+ restart(next_round: false)
179
+ else
180
+ message("Demo continues")
181
+ run_next
182
+ end
156
183
  end
157
184
 
158
185
  def toggle_pause
@@ -304,8 +331,11 @@ class DemoPlayer
304
331
 
305
332
  # The file as it was at the start, and the cursor at the top, for the
306
333
  # next round
307
- def restart
308
- @rounds += 1
334
+ # next_round: false starts this round again (after edits while paused)
335
+ def restart(next_round: true)
336
+ @rounds += 1 if next_round
337
+ remove_timer
338
+ vma.buf.end_visual_mode if demo_buf?(vma.buf) && vma.buf.visual_mode?
309
339
  vma.kbd.set_mode(:command)
310
340
  # The files as at the start, and the buffer history in the same order
311
341
  @bufs.zip(@originals).reverse_each { |b, text|
@@ -317,6 +347,12 @@ class DemoPlayer
317
347
  begin_round
318
348
  end
319
349
 
350
+ # What a pause and continue compares: the current buffer, the mode, and
351
+ # each demo buffer's text and cursor
352
+ def state
353
+ [vma.buf.object_id, vma.kbd.get_mode, @bufs.map { |b| [b.to_s, b.pos] }]
354
+ end
355
+
320
356
  def remove_timer
321
357
  GLib::Source.remove(@timer) rescue nil if @timer
322
358
  @timer = nil
@@ -246,12 +246,11 @@ class Editor
246
246
  require "vimamsa/audio"
247
247
  end
248
248
 
249
- if cnf.lsp.enabled?
250
- require "vimamsa/langservp"
251
- @langsrv["ruby"] = LangSrv.new("ruby")
252
- @langsrv["cpp"] = LangSrv.new("cpp")
253
- #TODO: if language enabled in config?
254
- end
249
+ # LSP servers start when a file of their language is opened (LangSrv.get,
250
+ # in the file's project), not here: a server started at startup ran in the
251
+ # editor's current directory (often the home directory, which ruby-lsp
252
+ # then indexed whole) and blocked startup while it initialized
253
+ require "vimamsa/langservp" if cnf.lsp.enabled?
255
254
 
256
255
  # Load each module that is enabled in settings.
257
256
  # Each module lives in modules/<name>/<name>.rb and may optionally define
@@ -337,6 +336,9 @@ class Editor
337
336
  test_files = ARGV.select { |a| a.end_with?(".rb") && File.file?(a) }
338
337
  run_as_idle proc {
339
338
  test_files.each { |f| load f }
339
+ # VMA_TEST_CLASSES: the class filter when run_tests.rb started another
340
+ # build (VMA_TEST_APP, e.g. an AppImage)
341
+ $vma_test_class_filter ||= ENV["VMA_TEST_CLASSES"].to_s.split(",") if !ENV["VMA_TEST_CLASSES"].to_s.empty?
340
342
  classes = if $vma_test_class_filter
341
343
  $vma_test_class_filter.filter_map { |name|
342
344
  begin
@@ -454,8 +456,7 @@ class Editor
454
456
 
455
457
  # After a restart (restart_editor) reopen the previous files silently.
456
458
  if ENV["VIMAMSA_RESTORE_SESSION"]
457
- restore_session_files(fnames)
458
- message("Session restored: #{fnames.size} file(s)")
459
+ restore_session_files(fnames) { message("Session restored: #{fnames.size} file(s)") }
459
460
  return
460
461
  end
461
462
 
@@ -469,24 +470,51 @@ class Editor
469
470
  },
470
471
  :callback => proc { |x|
471
472
  if x["yes_btn"] == "submit"
472
- restore_session_files(fnames)
473
- message("Session restored: #{label}")
473
+ restore_session_files(fnames) { message("Session restored: #{label}") }
474
474
  end
475
475
  },
476
476
  }
477
477
  PopupFormGenerator.new(params).run
478
478
  end
479
479
 
480
- def restore_session_files(fnames)
480
+ # Opens the session's files one per main loop turn, showing "Restoring
481
+ # session: 7/19" in the status bar, so the window stays responsive and shows
482
+ # how far it got; then calls the block. A file that fails to open is
483
+ # reported and skipped.
484
+ def restore_session_files(fnames, &done)
481
485
  initial = vma.buffers.list.find { |b| b.fname.nil? }
482
- fnames.each { |f| b = load_buffer(f); b&.needs_autosave_check = true }
483
- initial&.close
484
- # Loading the session switches to its last file; cnf.startup_file stays
485
- # the buffer shown on startup.
486
- if @startup_fname and (id = vma.buffers.get_buffer_by_filename(@startup_fname))
487
- vma.buffers.set_current_buffer(id)
488
- end
489
- gui.restore_column2_buffer
486
+ n = fnames.size
487
+ i = 0
488
+ finish = lambda {
489
+ gui.set_status_indicator(:session_restore, nil)
490
+ initial&.close if vma.buffers.list.any? { |b| b.equal?(initial) }
491
+ # Loading the session switches to its last file; cnf.startup_file stays
492
+ # the buffer shown on startup.
493
+ if @startup_fname and (id = vma.buffers.get_buffer_by_filename(@startup_fname))
494
+ vma.buffers.set_current_buffer(id)
495
+ end
496
+ gui.restore_column2_buffer
497
+ done&.call
498
+ }
499
+ step = lambda {
500
+ if i >= n
501
+ finish.call
502
+ next
503
+ end
504
+ f = fnames[i]
505
+ i += 1
506
+ gui.set_status_indicator(:session_restore, "Restoring session: #{i}/#{n} #{File.basename(f)}")
507
+ begin
508
+ b = load_buffer(f)
509
+ b&.needs_autosave_check = true
510
+ rescue StandardError => e
511
+ message("Could not restore #{f}: #{e.message}")
512
+ end
513
+ # Idle: lower priority than drawing, so the status shows between files
514
+ GLib::Idle.add { step.call; false }
515
+ }
516
+ gui.set_status_indicator(:session_restore, "Restoring session: 0/#{n}")
517
+ GLib::Idle.add { step.call; false }
490
518
  end
491
519
 
492
520
  def add_content_search_path(pathstr)
data/lib/vimamsa/gui.rb CHANGED
@@ -581,6 +581,11 @@ class VMAgui
581
581
  # @entry_has_focus is set explicitly via notify_entry_focus by those widgets.
582
582
  next false if @entry_has_focus
583
583
  next false if @kbd_passthrough
584
+ # A playing demo types its own keys (demo_player.rb)
585
+ if DemoPlayer.blocks_input?
586
+ DemoPlayer.input_blocked
587
+ next true
588
+ end
584
589
  name = Gdk::Keyval.to_name(keyval)
585
590
  uki = Gdk::Keyval.to_unicode(keyval)
586
591
  keystr = uki.chr("UTF-8")
@@ -605,6 +610,7 @@ class VMAgui
605
610
  press.signal_connect "key-released" do |gesture, keyval, keycode, y|
606
611
  next false if @entry_has_focus
607
612
  next false if @kbd_passthrough
613
+ next true if DemoPlayer.blocks_input?
608
614
  name = Gdk::Keyval.to_name(keyval)
609
615
  uki = Gdk::Keyval.to_unicode(keyval)
610
616
  keystr = uki.chr("UTF-8")
@@ -68,7 +68,7 @@ class FuncPanel
68
68
  set_placeholder("(no LSP)")
69
69
  return
70
70
  end
71
- lsp = LangSrv.get(buf.lang)
71
+ lsp = LangSrv.get(buf.lang, buf.fname)
72
72
  unless lsp
73
73
  set_placeholder("(no LSP)")
74
74
  return
@@ -258,6 +258,7 @@ class VSourceView < GtkSource::View
258
258
  @cnt_mo = Gtk::EventControllerMotion.new
259
259
  self.add_controller(@cnt_mo)
260
260
  @cnt_mo.signal_connect "motion" do |gesture, x, y|
261
+ next if DemoPlayer.blocks_input?
261
262
  if !@range_start.nil? and !x.nil? and !y.nil? and buf.visual_mode?
262
263
  i = coord_to_iter(x, y, true)
263
264
  @bufo.set_pos(i) if !i.nil? and @last_iter != i
@@ -269,6 +270,9 @@ class VSourceView < GtkSource::View
269
270
  @cnt_drag = Gtk::GestureDrag.new
270
271
  self.add_controller(@cnt_drag)
271
272
  @cnt_drag.signal_connect "drag-begin" do |gesture, x, y|
273
+ # A playing demo: no mouse selections (see "pressed")
274
+ @demo_blocked = DemoPlayer.blocks_input?
275
+ next if @demo_blocked
272
276
  debug "drag-begin", 2
273
277
  @drag_start_x = x
274
278
  @drag_start_y = y
@@ -286,6 +290,7 @@ class VSourceView < GtkSource::View
286
290
  end
287
291
 
288
292
  @cnt_drag.signal_connect "drag-update" do |gesture, offset_x, offset_y|
293
+ next if @demo_blocked
289
294
  if @move_sel
290
295
  t = drop_pos(@drag_start_x + offset_x, @drag_start_y + offset_y)
291
296
  # Dropping inside (or right after) the selection would not move it
@@ -307,6 +312,7 @@ class VSourceView < GtkSource::View
307
312
 
308
313
  @cnt_drag.signal_connect "drag-end" do |gesture, offsetx, offsety|
309
314
  debug "drag-end", 2
315
+ next if @demo_blocked
310
316
  if @move_sel
311
317
  r = @move_sel
312
318
  @move_sel = nil
@@ -351,6 +357,7 @@ class VSourceView < GtkSource::View
351
357
  rightclick.button = 3
352
358
  self.add_controller(rightclick)
353
359
  rightclick.signal_connect "pressed" do |gesture, n_press, x, y, z|
360
+ next true if DemoPlayer.blocks_input?
354
361
  puts "SourceView, GestureClick rightclick released button=#{gesture.button} x=#{x} y=#{y}"
355
362
  if gesture.button == 3
356
363
  show_context_menu(x, y)
@@ -360,6 +367,11 @@ class VSourceView < GtkSource::View
360
367
 
361
368
  click.signal_connect "pressed" do |gesture, n_press, x, y, z|
362
369
  debug "SourceView, GestureClick released x=#{x} y=#{y}"
370
+ # A playing demo: a click would move the cursor under it (demo_player.rb)
371
+ if DemoPlayer.blocks_input?
372
+ DemoPlayer.input_blocked
373
+ next true
374
+ end
363
375
  vma.gui.instance_variable_set(:@kbd_passthrough, false)
364
376
 
365
377
  xloc = (x - gutter_width).to_i
@@ -408,6 +420,7 @@ class VSourceView < GtkSource::View
408
420
 
409
421
  click.signal_connect "released" do |gesture, n_press, x, y, z|
410
422
  debug "SourceView, GestureClick released x=#{x} y=#{y} button=#{gesture.button}"
423
+ next true if DemoPlayer.blocks_input?
411
424
  next true if @move_sel # drag-end handles it
412
425
 
413
426
  xloc = (x - gutter_width).to_i
@@ -22,7 +22,6 @@ HELP_PAGES = %w[intro vim_intro]
22
22
  # action's description; tests check the action against the live bindings.
23
23
  VIM_INTRO_KEYS = [
24
24
  ["C", "s", "change a character", "jump.easy"],
25
- ["C", "C", "change to end of line", "grep.files"],
26
25
  ["C", "O", "open a line above", "move.line.end"],
27
26
  ["C", "X", "delete a character back", "edit.line.below"],
28
27
  ["C", "space <char>", "right, then a command", "edit.insert.char"],
@@ -53,7 +53,7 @@ class KeyBindingTree
53
53
  attr_accessor :C, :I, :cur_state, :root, :match_state, :last_action, :cur_action, :modifiers, :next_command_count, :method_handles_repeat, :default_mode
54
54
  attr_accessor :action_handler, :on_action_error, :logger, :fatal_handler, :error_handler
55
55
  attr_reader :mode_root_state, :state_trail, :act_bindings, :default_mode_stack, :actions
56
- # [mode, keys] of the shared vim bindings bound by bind_vim_bindings (vim_core.rb)
56
+ # [mode, keys] of the shared vim bindings bound by bind_vim_bindings (key_bindings_vim_core.rb)
57
57
  attr_accessor :vim_added
58
58
  # Keywords added to every binding made inside with_keywords
59
59
  attr_reader :extra_keywords
@@ -440,7 +440,7 @@ def vim_binding_conflicts_report(rows = vim_binding_conflicts)
440
440
  out << "Bindings that modules and `custom.rb` add at startup are not included.\n\n"
441
441
  out << "| | Count |\n|---|---|\n"
442
442
  out << "| Conflicts (the vim binding can't be used in vimlike) | #{by.fetch(:conflict, []).size} |\n"
443
- out << "| Added to vimlike from the shared table (`VIM_BINDINGS`, vim_core.rb) | #{by.fetch(:added, []).size} |\n"
443
+ out << "| Added to vimlike from the shared table (`VIM_BINDINGS`, key_bindings_vim_core.rb) | #{by.fetch(:added, []).size} |\n"
444
444
  out << "| Missing from vimlike (no conflict, could be added) | #{by.fetch(:missing, []).size} |\n"
445
445
  out << "| vim keymap only (left out of vimlike on purpose) | #{by.fetch(:vim_only, []).size} |\n"
446
446
  out << "| Shared (same keys, same action) | #{by.fetch(:shared, []).size} |\n\n"
@@ -462,7 +462,7 @@ def vim_binding_conflicts_report(rows = vim_binding_conflicts)
462
462
  vim_conflict_rows_grouped(by.fetch(:missing, [])).each { |r|
463
463
  out << "| #{r[:mode]} | #{code.(r[:keys].join(" "))} | #{act.(r[:action])} |\n"
464
464
  }
465
- out << "\n## vim keymap only\n\nLeft out of vimlike on purpose (`VIM_KEYMAP_ONLY`, vim_core.rb).\n\n"
465
+ out << "\n## vim keymap only\n\nLeft out of vimlike on purpose (`VIM_KEYMAP_ONLY`, key_bindings_vim_core.rb).\n\n"
466
466
  out << "| Mode | Vim keys | Vim action | Why |\n|---|---|---|---|\n"
467
467
  by.fetch(:vim_only, []).each { |r|
468
468
  out << "| #{r[:mode]} | #{code.(r[:keys].join(" "))} | #{act.(r[:action])} | #{r[:why]} |\n"
@@ -1,6 +1,6 @@
1
1
  # Vim keybinding scheme: standard vim behavior, as close as the current
2
2
  # action inventory allows. Does not load vimlike. The Vim bindings themselves
3
- # are the shared VIM_BINDINGS table (vim_core.rb), which vimlike also loads
3
+ # are the shared VIM_BINDINGS table (key_bindings_vim_core.rb), which vimlike also loads
4
4
  # where it doesn't conflict; this file adds the modes and the vim keymap's own
5
5
  # deviations. Selected via cnf.keybindings.scheme = "vim" (applied on restart).
6
6
  #
@@ -58,7 +58,7 @@ def insert_move(op)
58
58
  _insert_move(op)
59
59
  end
60
60
 
61
- # Vim behavior: the shared table and its actions, see vim_core.rb
61
+ # Vim behavior: the shared table and its actions, see key_bindings_vim_core.rb
62
62
  bind_vim_bindings
63
63
 
64
64
  # ── vim keymap's own bindings (not Vim behavior) ─────────────────────────────
@@ -97,8 +97,4 @@ bindkey "audio left", ["audio.backward", proc { Audio.seek_forward(-5.0) }, "See
97
97
  bindkey "audio space", "audio.stop"
98
98
  bindkey "audio q || audio esc", "mode.prev"
99
99
 
100
- # vim i_ctrl-r: insert a register. Here, not in VIM_BINDINGS, so vimlike
101
- # doesn't get a new ctrl chord from the shared table.
102
- bindkey "I ctrl-r <char>", "edit.insert.register", keywords: "vim insert"
103
-
104
100
  end # module Vimamsa
@@ -230,6 +230,7 @@ VIM_BINDINGS = {
230
230
  "I backspace" => "edit.backspace",
231
231
  "I ctrl-h" => "edit.backspace", # vim i_ctrl-h = backspace
232
232
  "I ctrl-j" => "edit.newline", # vim i_ctrl-j = new line
233
+ "I ctrl-r <char>" => "edit.insert.register", # vim i_ctrl-r: insert register <char>
233
234
 
234
235
  # Completion (vim i_ctrl-n / i_ctrl-p; popup guards first)
235
236
  "I tab(vma.buf.view.autocp_active)" => "edit.complete.next",
@@ -291,7 +292,7 @@ VIM_BINDINGS = {
291
292
  # Vim keymap bindings left out of vimlike on purpose, with the reason. The
292
293
  # conflicts report lists them separately instead of as missing.
293
294
  VIM_KEYMAP_ONLY = {
294
- "I ctrl-r <char>" => "no new ctrl chords in vimlike",
295
+
295
296
  }
296
297
 
297
298
  # Whether keys are bound in mode m, with or without a condition ("C 0" is
@@ -359,7 +359,7 @@ add_keys "core cat:view", {
359
359
  }
360
360
 
361
361
  add_keys "core cat:grep", {
362
- "C C" => "grep.files",
362
+ # "C C" => "grep.files",
363
363
  "C , a" => "ack.search",
364
364
  }
365
365
 
@@ -451,7 +451,7 @@ bindkey "C , i p", "edit.insert.password", keywords: "cat:edit"
451
451
  # (c O, g U O, > O, ...; vim_operators.rb)
452
452
  vma.kbd.key_set_add(:motion, "O" => :line_end)
453
453
 
454
- # Vim bindings from the shared table (vim_core.rb) that don't conflict with
454
+ # Vim bindings from the shared table (key_bindings_vim_core.rb) that don't conflict with
455
455
  # the bindings above; the rest are listed in doc/vimlike_vim_conflicts.md.
456
456
  # Keep this last, so every vimlike binding counts as taken.
457
457
  bind_vim_bindings(only_free: true)
@@ -5,6 +5,10 @@ LSP = LanguageServer::Protocol
5
5
 
6
6
  class LangSrv
7
7
  @@languages = {}
8
+ # Languages whose server failed to start: not retried for every buffer (each
9
+ # try blocks the GTK thread, so a session of N files stalled N times) until
10
+ # LangSrv.restart
11
+ @@failed = {}
8
12
  attr_accessor :error
9
13
  attr_reader :completion_supported, :position_encoding
10
14
 
@@ -28,6 +32,7 @@ class LangSrv
28
32
  def self.restart(lang)
29
33
  lang = LSP_LANG.fetch(lang, lang)
30
34
  @@languages.delete(lang)&.shutdown
35
+ @@failed.delete(lang)
31
36
  vma.buffers.list.each do |b|
32
37
  next if b.fname.nil? || b.lang.nil?
33
38
  next unless LSP_LANG.fetch(b.lang, b.lang) == lang
@@ -36,21 +41,55 @@ class LangSrv
36
41
  @@languages[lang]
37
42
  end
38
43
 
39
- def self.get(lang)
44
+ # The server for lang, started if needed. fname: the file it is wanted
45
+ # for; a new server runs in that file's project (project_root).
46
+ def self.get(lang, fname = nil)
40
47
  lang = LSP_LANG.fetch(lang, lang)
41
- if @@languages[lang].nil?
42
- @@languages[lang] = LangSrv.new(lang)
43
- @@languages[lang] = nil if @@languages[lang].error
48
+ if @@languages[lang].nil? && !@@failed[lang]
49
+ srv = LangSrv.new(lang, root: project_root(fname))
50
+ if srv.error
51
+ # Only a configured server that did not start counts as failed
52
+ @@failed[lang] = true if srv.configured?
53
+ else
54
+ @@languages[lang] = srv
55
+ end
44
56
  end
45
57
  return @@languages[lang]
46
58
  end
47
59
 
60
+ # Files and dirs that mark a project's top folder
61
+ PROJECT_MARKERS = %w[.git Gemfile compile_commands.json compile_flags.txt]
62
+
63
+ # The folder a server for fname works in (its working directory and
64
+ # rootUri): the nearest folder up from fname with a PROJECT_MARKERS entry,
65
+ # else fname's own folder. Never the home directory or /: ruby-lsp indexes
66
+ # its whole workspace, so a file directly in ~ gets an empty folder.
67
+ def self.project_root(fname)
68
+ return nil if fname.nil?
69
+ home = File.expand_path("~")
70
+ dir = File.dirname(File.expand_path(fname))
71
+ d = dir
72
+ until d == home || d == "/" || d == "."
73
+ return d if PROJECT_MARKERS.any? { |m| File.exist?(File.join(d, m)) }
74
+ d = File.dirname(d)
75
+ end
76
+ return dir if dir != home && dir != "/"
77
+ @@empty_root ||= Dir.mktmpdir("vimamsa-lsp-")
78
+ end
79
+
80
+ # A server is configured for this language (whether or not it started)
81
+ def configured?
82
+ @configured
83
+ end
84
+
48
85
  def new_id()
49
86
  return @id += 1
50
87
  end
51
88
 
52
- def initialize(lang)
89
+ # root: the project folder to run the server in (project_root)
90
+ def initialize(lang, root: nil)
53
91
  @error = true
92
+ @root = root
54
93
 
55
94
  # Use LSP server specified by user if available
56
95
  @lang = lang
@@ -58,11 +97,12 @@ class LangSrv
58
97
  lspconf = nil
59
98
  ret = (cnf.lsp.server? || {}).find { |k, v| v[:languages].include?(@lang) }
60
99
  lspconf = ret[1] unless ret.nil?
100
+ @configured = !lspconf.nil?
61
101
 
62
102
  if !lspconf.nil?
63
103
  error = false
64
104
  begin
65
- @io = IO.popen(lspconf[:command], "r+")
105
+ @io = @root ? IO.popen(lspconf[:command], "r+", chdir: @root) : IO.popen(lspconf[:command], "r+")
66
106
  rescue Errno::ENOENT => e
67
107
  pp e
68
108
  error = true
@@ -95,6 +135,10 @@ class LangSrv
95
135
 
96
136
  pid = Process.pid
97
137
 
138
+ # The project folder, unless workspace folders are configured
139
+ if wf.empty? && @root
140
+ wf << LSP::Interface::WorkspaceFolder.new(uri: file_uri(@root), name: File.basename(@root))
141
+ end
98
142
  root_uri = lspconf[:rooturi] || (wf.empty? ? nil : wf.first.uri)
99
143
  initp = LSP::Interface::InitializeParams.new(
100
144
  process_id: pid,
@@ -115,7 +159,9 @@ class LangSrv
115
159
 
116
160
  @writer.write(id: init_id, params: initp, method: "initialize")
117
161
 
162
+ @server_gone = false
118
163
  @lst = Thread.new {
164
+ begin
119
165
  @reader.read do |r|
120
166
  if r[:method] == "textDocument/publishDiagnostics"
121
167
  path = uri_to_path(r.dig(:params, :uri)) rescue nil
@@ -128,12 +174,20 @@ class LangSrv
128
174
  GLib::Idle.add { cb.call(r); false } if cb
129
175
  pp r
130
176
  end
177
+ rescue StandardError => e
178
+ debug "LSP reader stopped: #{e}"
179
+ ensure
180
+ # EOF or unreadable output: the server is gone, stop waiting for it
181
+ @server_gone = true
182
+ end
131
183
  }
132
184
 
133
185
  # LSP spec: wait for initialize result, then send initialized notification.
134
186
  # Servers such as ruby-lsp will not respond to any request until this is done.
135
187
  init_result = wait_for_response(init_id)
136
188
  if init_result.nil?
189
+ message("LSP server #{lspconf[:name]} did not start (command: #{lspconf[:command]})")
190
+ shutdown
137
191
  @error = true
138
192
  return
139
193
  end
@@ -218,6 +272,7 @@ class LangSrv
218
272
  t = Time.now
219
273
  debug "Waiting for response id:#{id}"
220
274
  while @resp[id].nil?
275
+ return @resp[id] if @server_gone # a last reply may have come with EOF
221
276
  sleep 0.03
222
277
  if Time.now - t > timeout
223
278
  debug "Timeout LSP call id:#{id}"
@@ -554,7 +609,7 @@ end
554
609
 
555
610
  def lsp_print_functions
556
611
  return unless vma.buf&.fname
557
- lsp = LangSrv.get(vma.buf.lang)
612
+ lsp = LangSrv.get(vma.buf.lang, vma.buf.fname)
558
613
  if lsp.nil?
559
614
  message("No LSP server available for #{vma.buf.lang}")
560
615
  return
data/lib/vimamsa/rbvma.rb CHANGED
@@ -79,7 +79,7 @@ require "vimamsa/buffer_cursor"
79
79
  require "vimamsa/buffer_changetext"
80
80
  require "vimamsa/text_objects"
81
81
  require "vimamsa/vim_operators"
82
- require "vimamsa/vim_core"
82
+ require "vimamsa/key_bindings_vim_core"
83
83
  require "vimamsa/fold"
84
84
  # require "vimamsa/buffer_list"
85
85
  require "vimamsa/buffer_list"
@@ -1,3 +1,3 @@
1
1
  module Vimamsa
2
- VERSION = "0.1.28"
2
+ VERSION = "0.1.29"
3
3
  end
data/run_tests_vm.rb CHANGED
@@ -14,6 +14,10 @@
14
14
  # ./run_tests_vm.rb # full suite
15
15
  # ./run_tests_vm.rb undo # tests/test_undo.rb only
16
16
  # FORCE_PROVISION=1 ./run_tests_vm.rb # re-run apt provisioning
17
+ # ./run_tests_vm.rb --appimage build/appimage/Vimamsa-0.1.28-x86_64.AppImage [filter]
18
+ # # test that AppImage (its own code)
19
+ # ./run_tests_vm.rb --appimage-dev FILE.AppImage [filter]
20
+ # # this tree's code on its runtime
17
21
  # VMA_UPDATE_DOC=1 ./run_tests_vm.rb vim_conflicts # also copy back generated docs
18
22
  #
19
23
  # Env:
@@ -43,6 +47,21 @@ TAR_EXCLUDES = %w[
43
47
  __pycache__ *.log claude-log.* dot_git_old ./build 2del_* bug*.txt *.mp3 *.wav
44
48
  ]
45
49
 
50
+ # --appimage FILE / --appimage-dev FILE: test an AppImage instead of a build of
51
+ # this tree. The tests are this tree's; with --appimage-dev the code is too,
52
+ # run on the AppImage's Ruby, gems and libraries. The rest of ARGV goes to
53
+ # exe/run_tests.rb as before (filters, --headless).
54
+ appimage = nil
55
+ appimage_dev = false
56
+ %w[--appimage --appimage-dev].each { |opt|
57
+ next if (i = ARGV.index(opt)).nil?
58
+ appimage = ARGV[i + 1]
59
+ appimage_dev = opt == "--appimage-dev"
60
+ fail!("#{opt} needs an AppImage file", 2) if appimage.nil? || !File.file?(appimage)
61
+ appimage = File.expand_path(appimage)
62
+ ARGV.slice!(i, 2)
63
+ }
64
+
46
65
  missing = missing_env("VM_NAME", "VM_USER", "VM_PASS")
47
66
  if missing.any?
48
67
  fail!("Not set: #{missing.join(" ")}. Export VM_NAME (VirtualBox VM), VM_USER (guest user)\n" \
@@ -96,6 +115,11 @@ begin
96
115
  run!(*gc, "copyto", *cred, tarball.path, "#{guest_home}/vimamsa_src.tgz", label: "VBoxManage copyto")
97
116
  run!(*gc, "copyto", *cred, File.join(repo, "vm_guest_run.sh"), "#{guest_home}/vm_guest_run.sh",
98
117
  label: "VBoxManage copyto")
118
+ guest_appimage = "#{guest_home}/vimamsa.AppImage"
119
+ if appimage
120
+ step "Copying #{File.basename(appimage)} into guest#{appimage_dev ? " (this tree's code on its runtime)" : ""}"
121
+ run!(*gc, "copyto", *cred, appimage, guest_appimage, label: "VBoxManage copyto")
122
+ end
99
123
 
100
124
  # 4. Run the guest script, streaming its output. VBoxManage doesn't pass on
101
125
  # the guest's exit code, so pass/fail comes from the VMA_SUITE_EXIT sentinel
@@ -105,6 +129,7 @@ begin
105
129
  "SUDO_PASS" => ENV["VM_PASS"], "VMA_DISPLAY" => display, "VMA_TEST_ARGS" => ARGV.join(" "),
106
130
  "FORCE_PROVISION" => ENV["FORCE_PROVISION"].to_s, "VMA_E2E_INTERACTIVE" => ENV["VMA_E2E_INTERACTIVE"].to_s,
107
131
  "VMA_UPDATE_DOC" => ENV["VMA_UPDATE_DOC"].to_s,
132
+ "VMA_APPIMAGE" => appimage ? guest_appimage : "", "VMA_APPIMAGE_DEV" => appimage_dev ? "1" : "",
108
133
  }.map { |k, v| "--putenv=#{k}=#{v}" }
109
134
  out, = run_streaming(*gc, "run", *cred, "--exe=/bin/bash", "--wait-stdout", "--wait-stderr",
110
135
  *putenv, "--", "#{guest_home}/vm_guest_run.sh")
@@ -51,4 +51,11 @@ fi
51
51
  # without putting the bundled ruby itself first on PATH.
52
52
  export PATH="$U/lib/vimamsa/bin:$PATH"
53
53
 
54
+ # VMA_SOURCE=<a vimamsa checkout>: run its exe/vimamsa (its lib/, modules/)
55
+ # on this image's Ruby, gems and libraries, e.g. to try code that isn't in a
56
+ # release yet (run_tests_vm.rb --appimage-dev)
57
+ if [ -n "${VMA_SOURCE:-}" ]; then
58
+ exec "$U/bin/ruby" "$VMA_SOURCE/exe/vimamsa" "$@"
59
+ fi
60
+
54
61
  exec "$U/bin/ruby" "$U/bin/vimamsa" "$@"
@@ -140,9 +140,19 @@ step "AppRun, desktop entry, icon"
140
140
  cp /src/scripts/appimage/AppRun "$APPDIR/AppRun" && chmod +x "$APPDIR/AppRun"
141
141
  # ruby-lsp / rufo on PATH without the bundled ruby (see AppRun)
142
142
  mkdir -p "$U/lib/vimamsa/bin"
143
+ # Without BUNDLE_GEMFILE, ruby-lsp composes a bundle from the project's
144
+ # Gemfile (.ruby-lsp/Gemfile) and runs `bundle install`, which tries to write
145
+ # the project's gems into the read-only image (Bundler::ReadOnlyFileSystemError)
146
+ # and stalls the server's startup. Point it at a fixed bundle of just ruby-lsp,
147
+ # locked here from the installed gems: it then starts at once, offline.
148
+ mkdir -p "$U/lib/vimamsa/lsp"
149
+ printf 'source "https://rubygems.org"\ngem "ruby-lsp"\n' > "$U/lib/vimamsa/lsp/Gemfile"
150
+ (cd "$U/lib/vimamsa/lsp" && bundle lock --local)
143
151
  for t in ruby-lsp rufo; do
144
152
  # (the editor has put the user's GEM_HOME etc. back by the time these run)
145
- printf '#!/bin/sh\nunset GEM_HOME GEM_PATH RUBYOPT RUBYLIB\nexec "$(dirname "$(readlink -f "$0")")/../../../bin/%s" "$@"\n' "$t" > "$U/lib/vimamsa/bin/$t"
153
+ gemfile=""
154
+ [ "$t" = ruby-lsp ] && gemfile='export BUNDLE_GEMFILE="$d/../lsp/Gemfile"\n'
155
+ printf "#!/bin/sh\nunset GEM_HOME GEM_PATH RUBYOPT RUBYLIB\nd=\"\$(dirname \"\$(readlink -f \"\$0\")\")\"\n${gemfile}exec \"\$d/../../../bin/%s\" \"\$@\"\n" "$t" > "$U/lib/vimamsa/bin/$t"
146
156
  chmod +x "$U/lib/vimamsa/bin/$t"
147
157
  done
148
158
  cat > "$APPDIR/vimamsa.desktop" <<EOF
@@ -9,7 +9,7 @@ REPO="$(git -C "$(dirname "$0")" rev-parse --show-toplevel)"
9
9
  TESTS="${SMOKE_TESTS:-tests/test_basic_editing.rb tests/test_bundling.rb}"
10
10
 
11
11
  docker run --rm -v "$APPIMAGE:/app/Vimamsa.AppImage:ro" -v "$REPO/tests:/src/tests:ro" \
12
- -v "$REPO/exe:/src/exe:ro" -e TESTS="$TESTS" ubuntu:24.04 bash -c '
12
+ -v "$REPO/exe:/src/exe:ro" -v "$REPO/lib:/src/lib:ro" -e TESTS="$TESTS" ubuntu:24.04 bash -c '
13
13
  set -e
14
14
  apt-get update -qq >/dev/null
15
15
  DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \