vimamsa 0.1.27 → 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.
- checksums.yaml +4 -4
- data/.github/workflows/appimage.yml +17 -10
- data/Dockerfile +2 -2
- data/README.md +162 -90
- data/custom_example.rb +33 -15
- data/doc/TODO.md +334 -110
- data/doc/action_names_plan.md +442 -0
- data/doc/bundling_plan.md +2 -1
- data/doc/delta_syntax_plan.md +293 -0
- data/doc/demo_recording_plan.md +288 -0
- data/doc/design_goals.md +27 -0
- data/doc/intro_page_plan.md +266 -0
- data/doc/key_bindings_report_plan.md +45 -0
- data/doc/line_tree_plan.md +89 -0
- data/doc/missing_vim_bindings.md +34 -44
- data/doc/modules_settings_plan.md +1 -1
- data/doc/registries_plan.md +202 -0
- data/doc/startup_speed_plan.md +97 -0
- data/doc/test_commands.md +232 -0
- data/doc/treap_visualizer.html +585 -0
- data/doc/vim_compatibility_plan.md +186 -31
- data/doc/vimlike_vim_conflicts.md +236 -228
- data/doc/vm_snapshots_plan.md +4 -4
- data/doc/wysiwyg_plan.md +231 -0
- data/docker_cmd.sh +1 -1
- data/exe/run_tests.rb +85 -3
- data/exe/vimamsa +49 -6
- data/help/intro.txt +30 -0
- data/help/vim_intro.txt +31 -0
- data/img/demo.gif +0 -0
- data/img/demo.mp4 +0 -0
- data/lang/hyperplaintext.lang +1 -1
- data/lib/vimamsa/ack.rb +2 -0
- data/lib/vimamsa/actions.rb +381 -36
- data/lib/vimamsa/bookmarks.rb +8 -8
- data/lib/vimamsa/buffer.rb +84 -38
- data/lib/vimamsa/buffer_changetext.rb +58 -36
- data/lib/vimamsa/buffer_list.rb +2 -2
- data/lib/vimamsa/buffer_manager.rb +6 -6
- data/lib/vimamsa/cli_help.rb +75 -0
- data/lib/vimamsa/clipboard.rb +6 -3
- data/lib/vimamsa/conf.rb +9 -0
- data/lib/vimamsa/crash_handler.rb +2 -2
- data/lib/vimamsa/debug.rb +2 -2
- data/lib/vimamsa/demo_player.rb +494 -0
- data/lib/vimamsa/demo_recorder.rb +277 -0
- data/lib/vimamsa/diff_buffer.rb +1 -1
- data/lib/vimamsa/dot_repeat.rb +104 -0
- data/lib/vimamsa/easy_jump.rb +54 -3
- data/lib/vimamsa/editor.rb +136 -65
- data/lib/vimamsa/file_history.rb +1 -1
- data/lib/vimamsa/file_manager.rb +23 -23
- data/lib/vimamsa/form_input.rb +388 -0
- data/lib/vimamsa/gui.rb +89 -13
- data/lib/vimamsa/gui_command_line.rb +44 -5
- data/lib/vimamsa/gui_form_generator.rb +17 -6
- data/lib/vimamsa/gui_func_panel.rb +1 -1
- data/lib/vimamsa/gui_key_hint.rb +165 -0
- data/lib/vimamsa/gui_keylog_panel.rb +164 -2
- data/lib/vimamsa/gui_menu.rb +69 -50
- data/lib/vimamsa/gui_select_window.rb +77 -43
- data/lib/vimamsa/gui_settings.rb +9 -5
- data/lib/vimamsa/gui_sourceview.rb +28 -81
- data/lib/vimamsa/gui_theme.rb +11 -2
- data/lib/vimamsa/hook.rb +2 -0
- data/lib/vimamsa/intro_page.rb +367 -0
- data/lib/vimamsa/key_actions.rb +315 -225
- data/lib/vimamsa/key_binding_tree.rb +228 -61
- data/lib/vimamsa/key_bindings_notepad.rb +18 -16
- data/lib/vimamsa/key_bindings_report.rb +290 -67
- data/lib/vimamsa/key_bindings_vim.rb +43 -297
- data/lib/vimamsa/key_bindings_vim_core.rb +356 -0
- data/lib/vimamsa/key_bindings_vimlike.rb +347 -339
- data/lib/vimamsa/key_names.rb +80 -0
- data/lib/vimamsa/langservp.rb +62 -7
- data/lib/vimamsa/line_tree.rb +367 -0
- data/lib/vimamsa/macro.rb +20 -3
- data/lib/vimamsa/rbvma.rb +15 -0
- data/lib/vimamsa/registers.rb +125 -0
- data/lib/vimamsa/run_ruby.rb +64 -0
- data/lib/vimamsa/search_replace.rb +4 -4
- data/lib/vimamsa/string_util.rb +17 -3
- data/lib/vimamsa/tests.rb +8 -8
- data/lib/vimamsa/text_objects.rb +11 -54
- data/lib/vimamsa/text_transforms.rb +4 -0
- data/lib/vimamsa/tmp_user_dir.rb +39 -0
- data/lib/vimamsa/user_dirs.rb +83 -0
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa/vim_operators.rb +365 -0
- data/modules/calculator/calculator.rb +5 -5
- data/modules/color_highlight/color_highlight.rb +3 -3
- data/modules/dictation/dictation.rb +32 -32
- data/modules/ollama/ollama.rb +5 -5
- data/modules/terminal/terminal.rb +5 -5
- data/modules/tts/tts.rb +10 -10
- data/run_e2e_vm.sh +3 -3
- data/run_tests_vm.rb +163 -0
- data/scripts/appimage/AppRun +7 -0
- data/scripts/appimage/build_in_container.sh +11 -1
- data/scripts/appimage/smoke_test.sh +1 -1
- data/scripts/demo/demo_easyjump_steps.txt +60 -0
- data/scripts/demo/demo_files_steps.txt +52 -0
- data/scripts/demo/demo_steps.txt +9 -1
- data/scripts/demo/notes.txt +6 -0
- data/scripts/demo/record_demo.rb +60 -81
- data/scripts/demo/report.rb +7 -0
- data/scripts/demo/shapes.rb +1 -0
- data/scripts/demo/square/shapes.rb +29 -0
- data/scripts/demo/square/steps.txt +185 -0
- data/scripts/lib/perf_startup.rb +138 -0
- data/scripts/lib/script_helpers.rb +53 -0
- data/scripts/perf_compare.rb +34 -0
- data/scripts/profile_startup.rb +72 -0
- data/tests/test_action_ids.rb +232 -0
- data/tests/test_auto_format.rb +2 -2
- data/tests/test_autocomplete.rb +1 -1
- data/tests/test_basic_editing.rb +18 -18
- data/tests/test_bookmarks.rb +6 -6
- data/tests/test_bracket_match.rb +3 -0
- data/tests/test_cli_help.rb +64 -0
- data/tests/test_color_highlight.rb +2 -2
- data/tests/test_command_line.rb +1 -1
- data/tests/test_context_menu_file.rb +18 -0
- data/tests/test_copy_paste.rb +33 -33
- data/tests/test_custom_two_phase.rb +1 -1
- data/tests/test_demo_player.rb +355 -0
- data/tests/test_demo_recorder.rb +202 -0
- data/tests/test_dictation.rb +16 -16
- data/tests/test_dot_repeat.rb +88 -0
- data/tests/test_easy_jump.rb +93 -0
- data/tests/test_extract_file_links.rb +3 -3
- data/tests/test_file_panel.rb +2 -2
- data/tests/test_flash.rb +1 -1
- data/tests/test_fold.rb +1 -1
- data/tests/test_form_input.rb +203 -0
- data/tests/test_func_panel.rb +2 -2
- data/tests/test_gtk_sync.rb +7 -7
- data/tests/test_intro_page.rb +437 -0
- data/tests/test_key_categories.rb +163 -0
- data/tests/test_keylog_panel.rb +163 -3
- data/tests/test_line_ends.rb +51 -0
- data/tests/test_line_tree.rb +86 -0
- data/tests/test_lsp_clangd.rb +2 -2
- data/tests/test_lsp_root.rb +43 -0
- data/tests/test_macro.rb +2 -2
- data/tests/test_module_interface.rb +9 -9
- data/tests/test_notepad_bindings.rb +5 -5
- data/tests/test_perf_startup.rb +28 -0
- data/tests/test_random_edit.rb +27 -27
- data/tests/test_registers.rb +131 -0
- data/tests/test_run_ruby.rb +77 -0
- data/tests/test_startup_file.rb +45 -4
- data/tests/test_text_objects.rb +1 -1
- data/tests/test_text_transforms.rb +12 -0
- data/tests/test_tmp_user_dir.rb +79 -0
- data/tests/test_tts.rb +10 -10
- data/tests/test_undo.rb +34 -34
- data/tests/test_user_dirs.rb +122 -0
- data/tests/test_vim_bindings.rb +107 -6
- data/tests/test_vim_conflicts.rb +41 -4
- data/tests/test_vim_operators.rb +116 -0
- data/tests/test_window_layout.rb +83 -0
- data/vimamsa.gemspec +1 -1
- data/vm_guest_run.sh +75 -28
- metadata +60 -4
- data/run_tests.rb +0 -89
- data/run_tests_vm.sh +0 -130
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# Plan: registries for definitions that modules and custom.rb can change
|
|
2
|
+
|
|
3
|
+
TODO: not started. Act next on step 1 of "Implementation order".
|
|
4
|
+
|
|
5
|
+
## Context
|
|
6
|
+
|
|
7
|
+
Several definition tables are Ruby constants, so nothing loaded later can change
|
|
8
|
+
them. A module can't add a key binding category, a setting to an existing
|
|
9
|
+
Settings section, or a context menu item. `custom.rb` can't rename or remove a
|
|
10
|
+
built-in one. When a module needs something like this today, it gets a special
|
|
11
|
+
case in core code: `all_settings_defs` (`gui_settings.rb`) builds the "Modules"
|
|
12
|
+
section, and `key_binding_category` (`key_bindings_report.rb`) makes the
|
|
13
|
+
automatic `module:<name>` category.
|
|
14
|
+
|
|
15
|
+
What a module adds must also go away when it is disabled. Today every module
|
|
16
|
+
does that cleanup by hand in `<name>_disable` (color_highlight, tts, ollama,
|
|
17
|
+
terminal, calculator, dictation), with `unbindkey` / `unreg_act` calls that have
|
|
18
|
+
to match its init code.
|
|
19
|
+
|
|
20
|
+
## Which tables
|
|
21
|
+
|
|
22
|
+
Tables that something might reasonably want to change after they're defined:
|
|
23
|
+
|
|
24
|
+
| Kind | Table | File |
|
|
25
|
+
|---|---|---|
|
|
26
|
+
| list | `KEY_CATEGORIES` | `key_bindings_report.rb` |
|
|
27
|
+
| list | `BASIC_ACTIONS` | `key_bindings_report.rb` |
|
|
28
|
+
| list | `SETTINGS_DEFS` (sections and the settings in each) | `gui_settings.rb` |
|
|
29
|
+
| list | `CONTEXT_MENU_ITEMS`, `CONTEXT_MENU_ITEMS_SELECTION` | `gui_sourceview.rb` |
|
|
30
|
+
| map | `ACTION_NS_CATEGORY`, `KEY_WORD_CATEGORY`, `KEY_MODE_CATEGORY` | `key_bindings_report.rb` |
|
|
31
|
+
| map | `KEY_CONDITIONS`, `KEY_MODE_NAMES` | `key_bindings_report.rb` |
|
|
32
|
+
| map | `SHEBANG_LANGS` | `buffer.rb` |
|
|
33
|
+
| map | `MARKUP_OVERLAY_STYLES` | `gui_settings.rb` |
|
|
34
|
+
| map | `ACTION_ALIASES` | `actions.rb` |
|
|
35
|
+
|
|
36
|
+
Borderline, decide when they come up: `TEXT_OBJECT_BRACKETS`,
|
|
37
|
+
`THEME_COLOR_DEFAULTS` / `CYBER_COLOR_DEFAULTS`, `VIM_BINDINGS`.
|
|
38
|
+
`GUESS_ENCODING_ORDER` is a user choice and belongs in `cnf`.
|
|
39
|
+
|
|
40
|
+
These stay constants. They are fixed facts, not definitions: `VOWELS`,
|
|
41
|
+
`CONSONANTS`, the LSP kind numbers (`COMPLETION_KINDS`, `FUNCTION_KINDS`,
|
|
42
|
+
`CLASS_KINDS`), `LSP_LANG`, `VIM_CONFLICT_WHY`, `DEMO_FILES`, the GUI size
|
|
43
|
+
defaults.
|
|
44
|
+
|
|
45
|
+
## Design
|
|
46
|
+
|
|
47
|
+
### 1. `Registry`: ordered entries by id
|
|
48
|
+
|
|
49
|
+
A new `lib/vimamsa/registry.rb` (add it to `rbvma.rb`). One class serves both
|
|
50
|
+
lists and maps: entries are kept in insertion order and keyed by id, and each
|
|
51
|
+
entry has a value plus the owner that added it.
|
|
52
|
+
|
|
53
|
+
```ruby
|
|
54
|
+
r = vma.registry(:key_categories)
|
|
55
|
+
|
|
56
|
+
# one entry
|
|
57
|
+
r.add("ai", "AI assistant")
|
|
58
|
+
|
|
59
|
+
# several entries in one call: an Array of [id, value] pairs or a Hash
|
|
60
|
+
r.add([["ai", "AI assistant"], ["speech", "Speech"]])
|
|
61
|
+
vma.registry(:action_ns_category).add("ollama" => "ai", "tts" => "speech")
|
|
62
|
+
|
|
63
|
+
# entries whose value is a Hash of fields (settings, context menu)
|
|
64
|
+
vma.registry(:settings).add([:ollama, :model], section: "modules", label: "Model", type: :string)
|
|
65
|
+
vma.registry(:settings).add([
|
|
66
|
+
[[:ollama, :model], { section: "modules", label: "Model", type: :string }],
|
|
67
|
+
[[:ollama, :url], { section: "modules", label: "Server URL", type: :string }],
|
|
68
|
+
])
|
|
69
|
+
|
|
70
|
+
r.remove("ai") # also: r.remove(["ai", "speech"])
|
|
71
|
+
r.replace("ai", "AI") # change the value and keep the position
|
|
72
|
+
r["ai"] # value, or nil
|
|
73
|
+
r.include?("ai")
|
|
74
|
+
r.each { |id, value| ... } # in order
|
|
75
|
+
r.ids, r.values, r.to_h
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Rules:
|
|
79
|
+
|
|
80
|
+
- `add` with an existing id is an error that names both owners, so two modules
|
|
81
|
+
don't overwrite each other without noticing. To change an entry on purpose,
|
|
82
|
+
use `replace`, or `remove` and then `add`.
|
|
83
|
+
- A batch `add` checks every entry before adding any of them: either the whole
|
|
84
|
+
batch goes in or nothing does.
|
|
85
|
+
- There are no ordering rules (`after:`/`before:`). Entries keep the order they
|
|
86
|
+
were added in, so built-in entries come first and those from modules and
|
|
87
|
+
custom.rb follow. Where position matters, a module reuses an existing entry
|
|
88
|
+
instead (e.g. puts its bindings in the `code` category) rather than adding
|
|
89
|
+
one.
|
|
90
|
+
- Values are stored as given; the registry doesn't copy or freeze them.
|
|
91
|
+
|
|
92
|
+
### 2. Built-ins use the same API
|
|
93
|
+
|
|
94
|
+
Each table keeps its literal data in the file where it's defined, as the
|
|
95
|
+
initial entries:
|
|
96
|
+
|
|
97
|
+
```ruby
|
|
98
|
+
define_registry(:key_categories, [
|
|
99
|
+
["motion", "Moving the cursor"],
|
|
100
|
+
["search", "Searching and jumping"],
|
|
101
|
+
...
|
|
102
|
+
])
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`define_registry` creates the registry with owner `"core"`. Built-in entries
|
|
106
|
+
aren't special, so custom.rb can `replace` or `remove` them. Code that read the
|
|
107
|
+
constant reads the registry. During the conversion the constant can stay as an
|
|
108
|
+
alias (`KEY_CATEGORIES = ...` replaced by a method) only where outside code
|
|
109
|
+
might use it; the codebase itself is switched over in the same step.
|
|
110
|
+
|
|
111
|
+
`SETTINGS_DEFS` becomes two registries: `:settings_sections` (id → label) and
|
|
112
|
+
`:settings` (key → fields including `section:`). A module can then add a
|
|
113
|
+
setting to an existing section such as Font, not only to "Modules", and the
|
|
114
|
+
special case in `all_settings_defs` goes away: the module loader registers each
|
|
115
|
+
module's enable switch.
|
|
116
|
+
|
|
117
|
+
### 3. Owners, so disabling a module undoes it
|
|
118
|
+
|
|
119
|
+
Every `add` records the current owner, set the same way as
|
|
120
|
+
`KeyBindingTree#with_keywords`:
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
with_owner("module:ollama") { ollama_init } # done by the module loader
|
|
124
|
+
remove_owned("module:ollama") # done by the loader on disable
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
- The loader already wraps module init (startup and Settings) and the three
|
|
128
|
+
places custom.rb runs in `with_keywords`; the same places set the owner
|
|
129
|
+
(`"module:<name>"`, `"custom"`). Outside them the owner is `"core"`.
|
|
130
|
+
- `remove_owned` removes that owner's entries from every registry, so modules
|
|
131
|
+
write no cleanup for registry entries.
|
|
132
|
+
- Later (step 6) `reg_act` and `bindkey` record the owner too, and
|
|
133
|
+
`remove_owned` also unregisters the actions and unbinds the keys. Then most
|
|
134
|
+
`<name>_disable` functions become unnecessary; a module keeps one only for
|
|
135
|
+
cleanup the registries don't know about (stopping a thread, closing a
|
|
136
|
+
window).
|
|
137
|
+
- `r.owner(id)` returns who added an entry, for error messages and debugging.
|
|
138
|
+
|
|
139
|
+
### 4. Change listeners for consumers that cache
|
|
140
|
+
|
|
141
|
+
```ruby
|
|
142
|
+
vma.registry(:context_menu).on_change { |reg| ... }
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
runs after any `add`, `replace` or `remove` (once per batch call). Needed
|
|
146
|
+
where something is built once:
|
|
147
|
+
|
|
148
|
+
- the context menu creates its `Gio::SimpleAction`s in `init_context_menu`,
|
|
149
|
+
at startup;
|
|
150
|
+
- the Settings dialog builds its widgets when it opens, so it only needs to
|
|
151
|
+
rebuild if it's open.
|
|
152
|
+
|
|
153
|
+
The key bindings page reads the registries each time it's shown and needs no
|
|
154
|
+
listener.
|
|
155
|
+
|
|
156
|
+
### 5. `cnf` stays separate
|
|
157
|
+
|
|
158
|
+
`cnf` holds the values the user chooses; registries hold what exists to choose
|
|
159
|
+
from. A setting's definition (label, type, range, section) goes in the
|
|
160
|
+
`:settings` registry, and its value stays in `cnf`.
|
|
161
|
+
|
|
162
|
+
### 6. Discoverability
|
|
163
|
+
|
|
164
|
+
- `vma.registries` lists the registry names, so the command line can show
|
|
165
|
+
them (`:vma.registries`), and `vma.registry(:x).to_h` shows the contents.
|
|
166
|
+
- An unknown name in `vma.registry(:x)` is an error with a did-you-mean
|
|
167
|
+
suggestion (as for action ids), not a new empty registry, so a typo doesn't
|
|
168
|
+
fail silently. Registries are created only by `define_registry`.
|
|
169
|
+
- `custom_example.rb` gets a short example: rename a key binding category,
|
|
170
|
+
add a context menu item.
|
|
171
|
+
|
|
172
|
+
## Implementation order
|
|
173
|
+
|
|
174
|
+
1. `Registry`, `define_registry`, `vma.registry`, `with_owner` /
|
|
175
|
+
`remove_owned`, `on_change`, with single and batch `add`/`remove`.
|
|
176
|
+
Unit-style tests in `tests/test_registry.rb`: order, duplicate-id error with
|
|
177
|
+
owners, all-or-nothing batch, owner removal, listener called once per
|
|
178
|
+
batch, unknown-name error.
|
|
179
|
+
2. Convert the key bindings page tables (`KEY_CATEGORIES`, `BASIC_ACTIONS`,
|
|
180
|
+
`ACTION_NS_CATEGORY`, `KEY_WORD_CATEGORY`, `KEY_MODE_CATEGORY`,
|
|
181
|
+
`KEY_CONDITIONS`, `KEY_MODE_NAMES`). They are new and used in one file. The
|
|
182
|
+
module loader sets the owner around module init and custom.rb. Test: a
|
|
183
|
+
module-owned category appears on the page and disappears after
|
|
184
|
+
`remove_owned`. `test_every_binding_has_a_category` keeps passing.
|
|
185
|
+
3. Context menu (`CONTEXT_MENU_ITEMS`, `CONTEXT_MENU_ITEMS_SELECTION`), with
|
|
186
|
+
an `on_change` listener that creates the missing Gio actions. Test: an item
|
|
187
|
+
added after startup shows up in the menu and runs its action.
|
|
188
|
+
4. `SETTINGS_DEFS` → `:settings_sections` + `:settings`; module enable
|
|
189
|
+
switches registered by the loader; `all_settings_defs` reads the
|
|
190
|
+
registries. Test: a module setting in an existing section is shown and
|
|
191
|
+
saved.
|
|
192
|
+
5. `SHEBANG_LANGS`, `MARKUP_OVERLAY_STYLES`, `ACTION_ALIASES`.
|
|
193
|
+
6. Owner tags on `reg_act` and `bindkey`; `remove_owned` unregisters and
|
|
194
|
+
unbinds them; remove the parts of `<name>_disable` that become
|
|
195
|
+
unnecessary. Test per module: enable, disable, and no actions, bindings or
|
|
196
|
+
registry entries of that module remain.
|
|
197
|
+
|
|
198
|
+
Run the full suite in the test VM after each step (`./run_tests_vm.rb`).
|
|
199
|
+
|
|
200
|
+
## DONE
|
|
201
|
+
|
|
202
|
+
(nothing yet)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Plan: faster startup
|
|
2
|
+
|
|
3
|
+
TODO: not started. Act next on step 1 of "Implementation order".
|
|
4
|
+
|
|
5
|
+
## Context
|
|
6
|
+
|
|
7
|
+
Investigated 2026-11-21. Measured on the development machine, not the test VM: the VM
|
|
8
|
+
was at its login screen. The editor reached its first idle after about 2.6–3.0 s:
|
|
9
|
+
about 1.9 s loading code and about 0.9 s building the window and running `Editor#start`.
|
|
10
|
+
"Saves" below is the fastest of 5 runs, compared with the same version without the
|
|
11
|
+
change (`scripts/lib/perf_startup.rb`).
|
|
12
|
+
|
|
13
|
+
Tools:
|
|
14
|
+
- `ruby -r ./scripts/profile_startup.rb exe/vimamsa [file]` prints, at exit, the slow
|
|
15
|
+
requires and the slow calls of vimamsa's own methods, as trees with start offsets
|
|
16
|
+
and inclusive times. Method tracing starts once the code is loaded, so method times
|
|
17
|
+
are a bit too high.
|
|
18
|
+
- `./run_tests_vm.rb perf_startup [ref=REF] [runs=N]` compares startup time with
|
|
19
|
+
another commit. Use it to confirm each step.
|
|
20
|
+
|
|
21
|
+
## Where the time goes
|
|
22
|
+
|
|
23
|
+
| Part | Time |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `require "colors"` (the red-colors gem, required by cairo) | 0.6–0.8 s |
|
|
26
|
+
| The GTK typelibs (gdk4, gio2, pango, gsk4, gtk4, gtksourceview5) | ≈0.9 s |
|
|
27
|
+
| Other Ruby requires (listen, openssl, vimamsa's own files) | ≈0.3 s |
|
|
28
|
+
| `@window.show` (first realize, renderer setup) | ≈0.2 s |
|
|
29
|
+
| Key bindings (`bind_vim_bindings`: `bind_template`, `vim_keys_taken?`) | 0.13–0.2 s |
|
|
30
|
+
| Opening the file (`gui_set_file_lang` 72 ms) | ≈0.11 s |
|
|
31
|
+
| GC: 27 runs (7 major), mostly marking the GObject wrappers | ≈0.3 s in total |
|
|
32
|
+
|
|
33
|
+
### What red-colors is
|
|
34
|
+
|
|
35
|
+
A color library from the Red Data Tools project. It has color models (RGB, HSL, HUSL,
|
|
36
|
+
XYZ, xyY, xterm256) with conversions, CSS/X11 color names, and the matplotlib and
|
|
37
|
+
seaborn colormaps (viridis, plasma, ...). When it is loaded,
|
|
38
|
+
`colors/colormap_data.rb` builds every colormap and a reversed copy of each:
|
|
39
|
+
thousands of `Colors::RGB` objects, many from Rationals. That is the slow part.
|
|
40
|
+
|
|
41
|
+
cairo loads it in `cairo/color.rb` only for `Cairo::Color.parse`, to turn a color
|
|
42
|
+
*name* into RGB. Hex strings and arrays don't need it. Vimamsa uses no colormaps.
|
|
43
|
+
|
|
44
|
+
## Changes
|
|
45
|
+
|
|
46
|
+
### Worth doing
|
|
47
|
+
|
|
48
|
+
1. **Load red-colors only when it is used.** A shim `colors.rb` (e.g.
|
|
49
|
+
`lib/vimamsa/lazy/colors.rb`) does
|
|
50
|
+
`Object.autoload(:Colors, File.join(Gem::Specification.find_by_name("red-colors").full_gem_path, "lib/colors.rb"))`.
|
|
51
|
+
Put its dir first on `$LOAD_PATH` only around `require "gtk4"` in `rbvma.rb`, so
|
|
52
|
+
cairo's `require "colors"` gets the shim. If the gem spec can't be found (e.g. the
|
|
53
|
+
AppImage), skip the shim and load normally. Checked: `Cairo::Color.parse("red")`
|
|
54
|
+
and `"#ff0000"` still work. **Saves ≈0.5 s** (3.00 → 2.49 s).
|
|
55
|
+
2. **GC off during startup.** `GC.disable` at the top of `exe/vimamsa`, and
|
|
56
|
+
`GC.enable` in the first idle after `Editor#start`. Peak memory is about 80 MB
|
|
57
|
+
higher until then. **Saves ≈0.24 s.** A larger initial heap
|
|
58
|
+
(`RUBY_GC_HEAP_*_INIT_SLOTS`) saved ≈0.1 s, but it must be set before Ruby
|
|
59
|
+
starts.
|
|
60
|
+
3. **Load openssl only when it is needed.** `buffer.rb:5` requires `openssl` but
|
|
61
|
+
doesn't use it. `encrypt.rb` needs it only when a file is actually encrypted or
|
|
62
|
+
decrypted: require it inside those methods. Saves ≈0.05 s.
|
|
63
|
+
4. **Remove `sleep(0.03)` in `Editor#start`** (`editor.rb:191`). Saves 0.03 s.
|
|
64
|
+
5. **Start the `listen` file listener after the window is up** (an idle after
|
|
65
|
+
startup), or replace it with a GLib file monitor (`Gio::File#monitor_directory`).
|
|
66
|
+
Requiring it loads rb-inotify and ffi. Saves ≈0.08–0.15 s.
|
|
67
|
+
6. **Reuse one `GtkSource::LanguageManager`.** `gui_set_file_lang` (`gui.rb:142`)
|
|
68
|
+
creates a new one on every call, which rescans the language files (72 ms). This
|
|
69
|
+
saves time for each extra file opened at startup and for every later file open.
|
|
70
|
+
7. **Generate the style scheme once.** `load_vimamsa_scheme` and
|
|
71
|
+
`gui_apply_color_mode` run for each buffer and again in `gui_refresh_colors`:
|
|
72
|
+
three times at startup. Saves ≈0.04 s.
|
|
73
|
+
|
|
74
|
+
### Possible, smaller or with trade-offs
|
|
75
|
+
|
|
76
|
+
- Optimize binding the key templates (`bind_template`, `vim_keys_taken?`): 0.1–0.2 s.
|
|
77
|
+
- Cache compiled Ruby code (as bootsnap does): compiling vimamsa's files takes ≈0.09 s
|
|
78
|
+
and loading them from binary ≈0.015 s, so at most ≈0.1 s. It adds complexity.
|
|
79
|
+
- `GSK_RENDERER=cairo` starts ≈0.18 s faster, but drawing is likely slower. Don't
|
|
80
|
+
make it the default.
|
|
81
|
+
|
|
82
|
+
### Not worth it
|
|
83
|
+
|
|
84
|
+
- YJIT (`--yjit`): ≈0.35 s slower.
|
|
85
|
+
- `GSK_RENDERER=gl` / `vulkan`: 0.1–0.4 s slower than the default (ngl).
|
|
86
|
+
- The rest (the GTK typelibs and the first draw) can't be avoided from Ruby.
|
|
87
|
+
|
|
88
|
+
## Implementation order
|
|
89
|
+
|
|
90
|
+
1. Items 1–4. Confirm the gain with `./run_tests_vm.rb perf_startup ref=HEAD`, and
|
|
91
|
+
run the full suite in the VM.
|
|
92
|
+
2. Items 5–7.
|
|
93
|
+
3. Optionally, the key template binding.
|
|
94
|
+
|
|
95
|
+
## DONE
|
|
96
|
+
|
|
97
|
+
(nothing yet)
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# Test commands
|
|
2
|
+
|
|
3
|
+
How to run the different kinds of tests, with a focus on the ones that a
|
|
4
|
+
plain `./run_tests_vm.rb` (no parameters) does **not** run.
|
|
5
|
+
|
|
6
|
+
## The default run
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
./run_tests_vm.rb
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
This syncs the working tree into the test VM (`$VM_NAME`) and runs
|
|
13
|
+
`ruby exe/run_tests.rb` without arguments on the VM's real desktop. That
|
|
14
|
+
runs every `tests/test_*.rb` file **except** the excluded ones listed below.
|
|
15
|
+
Some tests in the included files still skip themselves when an opt-in variable
|
|
16
|
+
or a tool is missing (see "Tests that skip in the default run").
|
|
17
|
+
|
|
18
|
+
Any arguments to `run_tests_vm.rb` go unchanged to `exe/run_tests.rb` inside
|
|
19
|
+
the guest, so every command below that uses `exe/run_tests.rb` also works
|
|
20
|
+
as `./run_tests_vm.rb <args>`. Run tests in the VM rather than locally where
|
|
21
|
+
you can.
|
|
22
|
+
|
|
23
|
+
### Argument forms (`exe/run_tests.rb`)
|
|
24
|
+
|
|
25
|
+
| Argument | Meaning |
|
|
26
|
+
|---|---|
|
|
27
|
+
| *(none)* | every `tests/test_*.rb` except the excluded files |
|
|
28
|
+
| `tests/test_foo.rb` | one file, by path |
|
|
29
|
+
| `foo` or `test_foo` | shorthand for `tests/test_foo.rb` |
|
|
30
|
+
| `foo,bar` | several files |
|
|
31
|
+
| `TestFoo` | only classes with that name (an argument starting with a capital letter) |
|
|
32
|
+
| `duration=N` | run time in seconds for `test_random_edit` |
|
|
33
|
+
| `ref=REF`, `runs=N` | comparison commit and run count for `test_perf_startup` |
|
|
34
|
+
| `--headless` | invisible display (see below) |
|
|
35
|
+
|
|
36
|
+
Naming a file explicitly bypasses the exclusion list, which is how the
|
|
37
|
+
excluded tests are run. An argument that is not recognized (for example a
|
|
38
|
+
mistyped file name) stops the run with exit code 2 instead of being ignored.
|
|
39
|
+
`ruby exe/run_tests.rb --help` lists all of this.
|
|
40
|
+
|
|
41
|
+
## Files excluded from the default run
|
|
42
|
+
|
|
43
|
+
These are listed in `excluded` in `exe/run_tests.rb` and run only when you
|
|
44
|
+
name them.
|
|
45
|
+
|
|
46
|
+
### Random edit stress test — `test_random_edit`
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
./run_tests_vm.rb test_random_edit # 300 s (DURATION default)
|
|
50
|
+
./run_tests_vm.rb test_random_edit duration=60 # shorter run
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
This runs random safe editor actions (moves, deletes, undo/redo, paste, mode
|
|
54
|
+
switches, random inserts) for the given time. It fails if any action raises an
|
|
55
|
+
exception. It is excluded because of how long it runs.
|
|
56
|
+
|
|
57
|
+
### Alternative key-binding schemes — `test_vim_bindings`, `test_notepad_bindings`
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
./run_tests_vm.rb vim_bindings
|
|
61
|
+
./run_tests_vm.rb notepad_bindings
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Each one loads a different binding scheme (`key_bindings_vim.rb` /
|
|
65
|
+
`key_bindings_notepad.rb`), and that permanently rebinds keys in the shared
|
|
66
|
+
test process. **Run each one by itself.** Don't combine them with each other
|
|
67
|
+
or with other files (`vim_bindings,undo`), or the files that run after them
|
|
68
|
+
will see the wrong bindings.
|
|
69
|
+
|
|
70
|
+
`test_vim_bindings` contains oracle tests. Each key sequence is replayed in a
|
|
71
|
+
real `nvim` or `vim` on the same text, and the two resulting buffers must
|
|
72
|
+
match. That needs `nvim` or `vim` on `PATH` (the VM provisioning installs
|
|
73
|
+
`vim`).
|
|
74
|
+
|
|
75
|
+
### Startup time regression — `test_perf_startup`
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
./run_tests_vm.rb perf_startup # vs the previous commit
|
|
79
|
+
./run_tests_vm.rb perf_startup ref=HEAD~10 runs=7 # vs another commit
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
This starts the editor several times at the current version and at `ref`
|
|
83
|
+
(default 5 runs each) and compares the fastest startups. It fails if the
|
|
84
|
+
current version is more than 25 % **and** more than 0.3 s slower. Without
|
|
85
|
+
`ref=` it compares against the previous commit, or against the current one
|
|
86
|
+
when `lib/`, `exe/` or `ext/` have uncommitted changes. It takes about a
|
|
87
|
+
minute, needs a display and a git checkout, and is excluded because of how
|
|
88
|
+
long it runs.
|
|
89
|
+
|
|
90
|
+
You can run the same check without the test runner:
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
ruby scripts/perf_compare.rb [--ref REF] [--runs N]
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Tests that skip in the default run
|
|
97
|
+
|
|
98
|
+
These files are part of the default run, but some of their tests skip unless
|
|
99
|
+
an environment variable is set or a tool is present. Skipped tests show up as
|
|
100
|
+
`SKIP:` lines under `Results:`.
|
|
101
|
+
|
|
102
|
+
### Keyboard E2E tests — `test_e2e_cmdline`, `test_e2e_replace_char`
|
|
103
|
+
|
|
104
|
+
These type real key events through a uinput virtual keyboard
|
|
105
|
+
(`tests/support/virtual_keyboard.rb`), so the editor window has to have focus
|
|
106
|
+
on a real Wayland seat. Wayland doesn't let a window launched through
|
|
107
|
+
`guestcontrol` take focus, so in the default VM run they wait 3 s and then skip
|
|
108
|
+
with "editor window is not focused".
|
|
109
|
+
|
|
110
|
+
To run them, use the semi-interactive wrapper:
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
./run_e2e_vm.sh # tests/test_e2e_cmdline.rb
|
|
114
|
+
./run_e2e_vm.sh e2e_replace_char
|
|
115
|
+
./run_e2e_vm.sh e2e_cmdline,e2e_replace_char
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
It sets `VMA_E2E_INTERACTIVE=1` and calls `run_tests_vm.rb`. When the prompt
|
|
119
|
+
`[E2E] Click the vimamsa window…` appears, click the editor window on the VM
|
|
120
|
+
desktop once, within 90 s. Every test after that finds the window already
|
|
121
|
+
focused.
|
|
122
|
+
|
|
123
|
+
Other requirements: writable `/dev/uinput` (the guest script sets it up on
|
|
124
|
+
every run), `xmodmap`, and the GTK Wayland backend. `test_e2e_replace_char`
|
|
125
|
+
also needs a keyboard layout with an `ä` key and skips without one. With
|
|
126
|
+
`--headless`, all of these tests always skip.
|
|
127
|
+
|
|
128
|
+
### Dictation E2E — `test_e2e_dictation`
|
|
129
|
+
|
|
130
|
+
```sh
|
|
131
|
+
VMA_E2E_DICTATION=1 ruby exe/run_tests.rb e2e_dictation
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
This one is opt-in. `run_tests_vm.rb` does **not** pass `VMA_E2E_DICTATION`
|
|
135
|
+
to the guest, so for now it runs only locally. The test uses a virtual
|
|
136
|
+
microphone (`tests/support/virtual_mic.rb`): it synthesizes a phrase with
|
|
137
|
+
`espeak-ng`/`espeak`, feeds it through the real GStreamer recorder and the
|
|
138
|
+
Whisper worker, and checks that the text arrives in the buffer. It needs
|
|
139
|
+
espeak and a Python that can `import faster_whisper`. The first run also
|
|
140
|
+
downloads the tiny Whisper model (~75 MB).
|
|
141
|
+
|
|
142
|
+
### Generated-doc check — `test_vim_conflicts`
|
|
143
|
+
|
|
144
|
+
```sh
|
|
145
|
+
VMA_UPDATE_DOC=1 ./run_tests_vm.rb vim_conflicts
|
|
146
|
+
# locally:
|
|
147
|
+
VMA_UPDATE_DOC=1 ruby exe/run_tests.rb --headless vim_conflicts
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The default run only checks that `doc/vimlike_vim_conflicts.md` matches the
|
|
151
|
+
current bindings, and fails if the file is out of date. `VMA_UPDATE_DOC=1`
|
|
152
|
+
regenerates the file instead. In the VM, `run_tests_vm.rb` copies the
|
|
153
|
+
regenerated file back into the working tree (see `GENERATED_DOCS`). Commit
|
|
154
|
+
the result.
|
|
155
|
+
|
|
156
|
+
### Tool-dependent tests
|
|
157
|
+
|
|
158
|
+
These skip when a tool is missing:
|
|
159
|
+
|
|
160
|
+
| Test | Needs | In the VM |
|
|
161
|
+
|---|---|---|
|
|
162
|
+
| `test_lsp_clangd` | `clangd` or `clangd-N` on `PATH` | **not installed**: skips |
|
|
163
|
+
| `test_ack` | `ack` / `ack-grep` | installed |
|
|
164
|
+
| `test_text_objects`, `test_vim_operators` (real-vim comparison) | `vim` | installed |
|
|
165
|
+
| `test_file_format`, `test_diff_buffer_name` | `git`, `diff` | installed |
|
|
166
|
+
|
|
167
|
+
To run the clangd tests in the VM, install it once in the guest
|
|
168
|
+
(`sudo apt-get install clangd`), then run `./run_tests_vm.rb lsp_clangd`.
|
|
169
|
+
|
|
170
|
+
## Headless runs (local)
|
|
171
|
+
|
|
172
|
+
```sh
|
|
173
|
+
ruby exe/run_tests.rb --headless # full default set
|
|
174
|
+
ruby exe/run_tests.rb --headless undo # one file
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
The editor runs on an invisible display, so the run doesn't interfere with
|
|
178
|
+
your desktop. It uses `xvfb-run` if it's installed (a private X server per
|
|
179
|
+
run) and otherwise GTK's Broadway backend on display `:9`. Expect more skips
|
|
180
|
+
than in the VM:
|
|
181
|
+
|
|
182
|
+
- all keyboard E2E tests (no real seat)
|
|
183
|
+
- window-maximize tests in `test_window_layout` (no window manager)
|
|
184
|
+
- under Broadway only: `test_bracket_match` and `test_keylog_panel`, because
|
|
185
|
+
nothing is drawn or laid out while no browser is connected. Install `xvfb`
|
|
186
|
+
to avoid this.
|
|
187
|
+
|
|
188
|
+
Three `test_autocomplete` tests (tab/enter completion) are skipped on every
|
|
189
|
+
run, the VM included, because they were unreliable under headless GTK.
|
|
190
|
+
|
|
191
|
+
Tests never read or write your real `~/.config/vimamsa`. They use
|
|
192
|
+
`~/.config/vimamsa-test`, which you can override with `VMA_USER_DIR`.
|
|
193
|
+
|
|
194
|
+
## AppImage smoke test
|
|
195
|
+
|
|
196
|
+
This isn't part of any `run_tests` invocation. It builds the AppImage and runs
|
|
197
|
+
a few test files with it in a clean Ubuntu 24.04 Docker container, which has no
|
|
198
|
+
GTK and no Ruby:
|
|
199
|
+
|
|
200
|
+
```sh
|
|
201
|
+
scripts/appimage/build.sh # HEAD; VMA_REF=WORKTREE for uncommitted changes
|
|
202
|
+
scripts/appimage/smoke_test.sh build/appimage/Vimamsa-<version>-x86_64.AppImage
|
|
203
|
+
SMOKE_TESTS="tests/test_undo.rb" scripts/appimage/smoke_test.sh <AppImage>
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
By default it runs `test_basic_editing` and `test_bundling`. The test
|
|
207
|
+
`test_bundling#test_appimage_children_get_host_environment` runs only from
|
|
208
|
+
inside the AppImage, when `APPDIR` is set, and skips everywhere else.
|
|
209
|
+
|
|
210
|
+
## VM runner options
|
|
211
|
+
|
|
212
|
+
| Variable | Effect |
|
|
213
|
+
|---|---|
|
|
214
|
+
| `VM_NAME`, `VM_USER`, `VM_PASS` | required: VM name, guest user, guest password |
|
|
215
|
+
| `VM_DISPLAY` | guest X display (default `:0`) |
|
|
216
|
+
| `FORCE_PROVISION=1` | rerun the apt/gem provisioning in the guest |
|
|
217
|
+
| `VMA_UPDATE_DOC=1` | copy regenerated docs back from the guest |
|
|
218
|
+
| `VMA_E2E_INTERACTIVE=1` | interactive focus wait for E2E tests (set by `run_e2e_vm.sh`) |
|
|
219
|
+
|
|
220
|
+
## Summary: what the default `./run_tests_vm.rb` leaves out
|
|
221
|
+
|
|
222
|
+
| What | Command |
|
|
223
|
+
|---|---|
|
|
224
|
+
| Random edit stress | `./run_tests_vm.rb test_random_edit duration=60` |
|
|
225
|
+
| Vim scheme (+ vim oracle) | `./run_tests_vm.rb vim_bindings` |
|
|
226
|
+
| Notepad scheme | `./run_tests_vm.rb notepad_bindings` |
|
|
227
|
+
| Startup time regression | `./run_tests_vm.rb perf_startup` |
|
|
228
|
+
| Keyboard E2E | `./run_e2e_vm.sh` (click the window once) |
|
|
229
|
+
| Dictation E2E | `VMA_E2E_DICTATION=1 ruby exe/run_tests.rb e2e_dictation` (local) |
|
|
230
|
+
| Regenerate the vim-conflicts doc | `VMA_UPDATE_DOC=1 ./run_tests_vm.rb vim_conflicts` |
|
|
231
|
+
| clangd LSP | install `clangd` in the guest, then `./run_tests_vm.rb lsp_clangd` |
|
|
232
|
+
| AppImage | `scripts/appimage/build.sh` + `scripts/appimage/smoke_test.sh` |
|