runtime_analysis 1.0.0

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.
Files changed (267) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +115 -0
  3. data/LICENSE.txt +96 -0
  4. data/README.md +164 -0
  5. data/editor/nvim/README.md +278 -0
  6. data/editor/nvim/lua/runtime_analysis/connected.lua +565 -0
  7. data/editor/nvim/lua/runtime_analysis/go_to_class.lua +63 -0
  8. data/editor/nvim/lua/runtime_analysis/inline.lua +138 -0
  9. data/editor/nvim/lua/runtime_analysis/lens.lua +50 -0
  10. data/editor/nvim/lua/runtime_analysis/lsp.lua +92 -0
  11. data/editor/nvim/lua/runtime_analysis/menu.lua +98 -0
  12. data/editor/nvim/lua/runtime_analysis/preview.lua +70 -0
  13. data/editor/nvim/lua/runtime_analysis/project.lua +28 -0
  14. data/editor/nvim/lua/runtime_analysis/rerun.lua +39 -0
  15. data/editor/nvim/lua/runtime_analysis/text.lua +23 -0
  16. data/editor/nvim/lua/runtime_analysis/value_popup.lua +45 -0
  17. data/editor/nvim/plugin/runtime_analysis.lua +71 -0
  18. data/examples/trackers/PROMPT.md +86 -0
  19. data/examples/trackers/honeybadger.rb +19 -0
  20. data/examples/trackers/sentry.rb +16 -0
  21. data/ext/runtime_analysis/extconf.rb +68 -0
  22. data/ext/runtime_analysis/fast.c +775 -0
  23. data/ext/runtime_analysis/fast.h +59 -0
  24. data/ext/runtime_analysis/hold.c +560 -0
  25. data/ext/runtime_analysis/init.c +36 -0
  26. data/ext/runtime_analysis/names.c +78 -0
  27. data/ext/runtime_analysis/names.h +28 -0
  28. data/ext/runtime_analysis/novelty.c +139 -0
  29. data/ext/runtime_analysis/novelty.h +22 -0
  30. data/ext/runtime_analysis/os.c +73 -0
  31. data/ext/runtime_analysis/os.h +32 -0
  32. data/ext/runtime_analysis/ring.c +445 -0
  33. data/ext/runtime_analysis/rows.c +304 -0
  34. data/ext/runtime_analysis/sink.c +485 -0
  35. data/ext/runtime_analysis/sink.h +240 -0
  36. data/ext/runtime_analysis/state.c +254 -0
  37. data/ext/runtime_analysis/state.h +57 -0
  38. data/ext/runtime_analysis/wrapper.c +278 -0
  39. data/ext/runtime_analysis/wrapper.h +24 -0
  40. data/lib/runtime_analysis/errors.rb +34 -0
  41. data/lib/runtime_analysis/failsafe.rb +123 -0
  42. data/lib/runtime_analysis/host/controller_entry_point.rb +18 -0
  43. data/lib/runtime_analysis/host/declared.rb +152 -0
  44. data/lib/runtime_analysis/host/inject.rb +90 -0
  45. data/lib/runtime_analysis/host/job_runners.rb +27 -0
  46. data/lib/runtime_analysis/host/middleware.rb +23 -0
  47. data/lib/runtime_analysis/host/minitest_integration.rb +22 -0
  48. data/lib/runtime_analysis/host/railtie.rb +42 -0
  49. data/lib/runtime_analysis/host/reports.rb +54 -0
  50. data/lib/runtime_analysis/host/rspec_integration.rb +17 -0
  51. data/lib/runtime_analysis/host/web.rb +22 -0
  52. data/lib/runtime_analysis/host.rb +34 -0
  53. data/lib/runtime_analysis/inject.rb +5 -0
  54. data/lib/runtime_analysis/minitest.rb +9 -0
  55. data/lib/runtime_analysis/native/build.rb +17 -0
  56. data/lib/runtime_analysis/native/byte_size.rb +27 -0
  57. data/lib/runtime_analysis/native/call_site_logger/definitions.rb +51 -0
  58. data/lib/runtime_analysis/native/call_site_logger/held.rb +35 -0
  59. data/lib/runtime_analysis/native/call_site_logger/rows.rb +110 -0
  60. data/lib/runtime_analysis/native/call_site_logger/segments.rb +100 -0
  61. data/lib/runtime_analysis/native/call_site_logger/streams.rb +110 -0
  62. data/lib/runtime_analysis/native/call_site_logger.rb +80 -0
  63. data/lib/runtime_analysis/native/rotation_policy.rb +28 -0
  64. data/lib/runtime_analysis/native/sanitizer_runtime.rb +50 -0
  65. data/lib/runtime_analysis/native/sink.rb +12 -0
  66. data/lib/runtime_analysis/native.rb +74 -0
  67. data/lib/runtime_analysis/platform.rb +30 -0
  68. data/lib/runtime_analysis/query/index/anonymise.rb +98 -0
  69. data/lib/runtime_analysis/query/index/graph.rb +107 -0
  70. data/lib/runtime_analysis/query/index/graph_cache.rb +32 -0
  71. data/lib/runtime_analysis/query/index/reading/declared.rb +42 -0
  72. data/lib/runtime_analysis/query/index/reading/dict.rb +43 -0
  73. data/lib/runtime_analysis/query/index/reading/frame.rb +27 -0
  74. data/lib/runtime_analysis/query/index/reading/node.rb +45 -0
  75. data/lib/runtime_analysis/query/index/reading/path.rb +21 -0
  76. data/lib/runtime_analysis/query/index/reading/reruns.rb +30 -0
  77. data/lib/runtime_analysis/query/index/reading/rows.rb +128 -0
  78. data/lib/runtime_analysis/query/index/reading/stream.rb +82 -0
  79. data/lib/runtime_analysis/query/index/reading/tree.rb +66 -0
  80. data/lib/runtime_analysis/query/index/reading/tree_builder.rb +135 -0
  81. data/lib/runtime_analysis/query/index/reading/values.rb +49 -0
  82. data/lib/runtime_analysis/query/index/reading.rb +80 -0
  83. data/lib/runtime_analysis/query/index/shapes.rb +142 -0
  84. data/lib/runtime_analysis/query/index/signatures/active_support.rb +31 -0
  85. data/lib/runtime_analysis/query/index/signatures/core.json +1 -0
  86. data/lib/runtime_analysis/query/index/signatures/layers.rb +29 -0
  87. data/lib/runtime_analysis/query/index/signatures/lineage.rb +57 -0
  88. data/lib/runtime_analysis/query/index/signatures/overloads.rb +32 -0
  89. data/lib/runtime_analysis/query/index/signatures/rbs/entry.rb +95 -0
  90. data/lib/runtime_analysis/query/index/signatures/rbs/export.rb +76 -0
  91. data/lib/runtime_analysis/query/index/signatures/rbs/library.rb +43 -0
  92. data/lib/runtime_analysis/query/index/signatures/rbs/overload.rb +66 -0
  93. data/lib/runtime_analysis/query/index/signatures/rbs/project.rb +69 -0
  94. data/lib/runtime_analysis/query/index/signatures/rbs/types.rb +79 -0
  95. data/lib/runtime_analysis/query/index/signatures/rbs.rb +57 -0
  96. data/lib/runtime_analysis/query/index/signatures/sorbet/sig.rb +48 -0
  97. data/lib/runtime_analysis/query/index/signatures/sorbet/signed.rb +69 -0
  98. data/lib/runtime_analysis/query/index/signatures/sorbet/table.rb +43 -0
  99. data/lib/runtime_analysis/query/index/signatures/sorbet/types.rb +96 -0
  100. data/lib/runtime_analysis/query/index/signatures/sorbet.rb +150 -0
  101. data/lib/runtime_analysis/query/index/signatures/sources.rb +80 -0
  102. data/lib/runtime_analysis/query/index/signatures/written.rb +45 -0
  103. data/lib/runtime_analysis/query/index/signatures.rb +93 -0
  104. data/lib/runtime_analysis/query/index/source_named_graph.rb +84 -0
  105. data/lib/runtime_analysis/query/index/static/change_set.rb +20 -0
  106. data/lib/runtime_analysis/query/index/static/changes.rb +80 -0
  107. data/lib/runtime_analysis/query/index/static/code_visitor.rb +144 -0
  108. data/lib/runtime_analysis/query/index/static/klass.rb +13 -0
  109. data/lib/runtime_analysis/query/index/static/method.rb +19 -0
  110. data/lib/runtime_analysis/query/index/static/params.rb +52 -0
  111. data/lib/runtime_analysis/query/index/static/source.rb +69 -0
  112. data/lib/runtime_analysis/query/index/static/stub.rb +14 -0
  113. data/lib/runtime_analysis/query/index/static/stub_visitor.rb +133 -0
  114. data/lib/runtime_analysis/query/index/static/value.rb +17 -0
  115. data/lib/runtime_analysis/query/index/static/values.rb +71 -0
  116. data/lib/runtime_analysis/query/index/static/visibility.rb +40 -0
  117. data/lib/runtime_analysis/query/index/static.rb +85 -0
  118. data/lib/runtime_analysis/query/index.rb +32 -0
  119. data/lib/runtime_analysis/query/nodes.rb +60 -0
  120. data/lib/runtime_analysis/query/project/config.rb +108 -0
  121. data/lib/runtime_analysis/query/project.rb +40 -0
  122. data/lib/runtime_analysis/query/report/document.rb +84 -0
  123. data/lib/runtime_analysis/query/report/finding.rb +15 -0
  124. data/lib/runtime_analysis/query/report/json_renderer.rb +51 -0
  125. data/lib/runtime_analysis/query/report/list.rb +15 -0
  126. data/lib/runtime_analysis/query/report/location.rb +14 -0
  127. data/lib/runtime_analysis/query/report/one_row.rb +14 -0
  128. data/lib/runtime_analysis/query/report/outline.rb +15 -0
  129. data/lib/runtime_analysis/query/report/paint.rb +34 -0
  130. data/lib/runtime_analysis/query/report/related.rb +11 -0
  131. data/lib/runtime_analysis/query/report/table.rb +15 -0
  132. data/lib/runtime_analysis/query/report/text.rb +13 -0
  133. data/lib/runtime_analysis/query/report/text_renderer.rb +102 -0
  134. data/lib/runtime_analysis/query/report.rb +35 -0
  135. data/lib/runtime_analysis/query/surfaces/class_value.rb +17 -0
  136. data/lib/runtime_analysis/query/surfaces/cli/answer.rb +32 -0
  137. data/lib/runtime_analysis/query/surfaces/cli/command_line.rb +77 -0
  138. data/lib/runtime_analysis/query/surfaces/cli/usage.rb +32 -0
  139. data/lib/runtime_analysis/query/surfaces/cli.rb +101 -0
  140. data/lib/runtime_analysis/query/surfaces/crystallise/lexical.rb +44 -0
  141. data/lib/runtime_analysis/query/surfaces/crystallise/notation.rb +33 -0
  142. data/lib/runtime_analysis/query/surfaces/crystallise/observed.rb +102 -0
  143. data/lib/runtime_analysis/query/surfaces/crystallise/outline.rb +111 -0
  144. data/lib/runtime_analysis/query/surfaces/crystallise/rbs_file.rb +100 -0
  145. data/lib/runtime_analysis/query/surfaces/crystallise/rbs_member.rb +50 -0
  146. data/lib/runtime_analysis/query/surfaces/crystallise/rbs_notation.rb +44 -0
  147. data/lib/runtime_analysis/query/surfaces/crystallise/seen.rb +74 -0
  148. data/lib/runtime_analysis/query/surfaces/crystallise/sig_text.rb +49 -0
  149. data/lib/runtime_analysis/query/surfaces/crystallise/sorbet_edit.rb +106 -0
  150. data/lib/runtime_analysis/query/surfaces/crystallise/sorbet_notation.rb +48 -0
  151. data/lib/runtime_analysis/query/surfaces/crystallise/subject.rb +55 -0
  152. data/lib/runtime_analysis/query/surfaces/crystallise.rb +94 -0
  153. data/lib/runtime_analysis/query/surfaces/mcp.rb +89 -0
  154. data/lib/runtime_analysis/query/surfaces/record/commands.rb +45 -0
  155. data/lib/runtime_analysis/query/surfaces/record/environment.rb +48 -0
  156. data/lib/runtime_analysis/query/surfaces/record/ignore.rb +62 -0
  157. data/lib/runtime_analysis/query/surfaces/record/question.rb +55 -0
  158. data/lib/runtime_analysis/query/surfaces/record/run.rb +30 -0
  159. data/lib/runtime_analysis/query/surfaces/record.rb +122 -0
  160. data/lib/runtime_analysis/query/surfaces/rerun.rb +87 -0
  161. data/lib/runtime_analysis/query/surfaces/setup/agents.rb +76 -0
  162. data/lib/runtime_analysis/query/surfaces/setup/changes.rb +107 -0
  163. data/lib/runtime_analysis/query/surfaces/setup/project.rb +80 -0
  164. data/lib/runtime_analysis/query/surfaces/setup/steps.md +205 -0
  165. data/lib/runtime_analysis/query/surfaces/setup.rb +98 -0
  166. data/lib/runtime_analysis/query/surfaces.rb +14 -0
  167. data/lib/runtime_analysis/query/tools/base.rb +86 -0
  168. data/lib/runtime_analysis/query/tools/method_lookup.rb +37 -0
  169. data/lib/runtime_analysis/query/tools/namespaces.rb +36 -0
  170. data/lib/runtime_analysis/query/tools/origins.rb +47 -0
  171. data/lib/runtime_analysis/query/tools/stubs.rb +53 -0
  172. data/lib/runtime_analysis/query/tools/unknown_method.rb +11 -0
  173. data/lib/runtime_analysis/query/tools/verify_mock.rb +145 -0
  174. data/lib/runtime_analysis/query/tools/what_calls.rb +67 -0
  175. data/lib/runtime_analysis/query/tools/what_it_receives.rb +142 -0
  176. data/lib/runtime_analysis/query/tools/where_nil_comes_from.rb +105 -0
  177. data/lib/runtime_analysis/query/tools/who_actually_answered.rb +82 -0
  178. data/lib/runtime_analysis/query/tools.rb +34 -0
  179. data/lib/runtime_analysis/query.rb +33 -0
  180. data/lib/runtime_analysis/recording/blob.rb +13 -0
  181. data/lib/runtime_analysis/recording/format.rb +32 -0
  182. data/lib/runtime_analysis/recording/opcodes.rb +30 -0
  183. data/lib/runtime_analysis/recording/raise_ids.rb +15 -0
  184. data/lib/runtime_analysis/recording/ruby_sink.rb +176 -0
  185. data/lib/runtime_analysis/recording/run_manifest.rb +110 -0
  186. data/lib/runtime_analysis/recording/seen/nothing.rb +15 -0
  187. data/lib/runtime_analysis/recording/seen/tally.rb +48 -0
  188. data/lib/runtime_analysis/recording/seen.rb +63 -0
  189. data/lib/runtime_analysis/recording/sink.rb +19 -0
  190. data/lib/runtime_analysis/recording/source_blob.rb +20 -0
  191. data/lib/runtime_analysis/recording.rb +52 -0
  192. data/lib/runtime_analysis/rspec.rb +8 -0
  193. data/lib/runtime_analysis/ruby_parsing/packages.rb +17 -0
  194. data/lib/runtime_analysis/ruby_parsing.rb +98 -0
  195. data/lib/runtime_analysis/trace/configuration/capturing.rb +32 -0
  196. data/lib/runtime_analysis/trace/configuration/per_run.rb +31 -0
  197. data/lib/runtime_analysis/trace/configuration/tier.rb +27 -0
  198. data/lib/runtime_analysis/trace/configuration.rb +115 -0
  199. data/lib/runtime_analysis/trace/entries.rb +47 -0
  200. data/lib/runtime_analysis/trace/hold/raises.rb +28 -0
  201. data/lib/runtime_analysis/trace/hold/requests.rb +47 -0
  202. data/lib/runtime_analysis/trace/hold/telling.rb +45 -0
  203. data/lib/runtime_analysis/trace/hold/unwound.rb +30 -0
  204. data/lib/runtime_analysis/trace/hold.rb +142 -0
  205. data/lib/runtime_analysis/trace/inclusion.rb +46 -0
  206. data/lib/runtime_analysis/trace/installer/alias_repair.rb +68 -0
  207. data/lib/runtime_analysis/trace/installer/answers.rb +24 -0
  208. data/lib/runtime_analysis/trace/installer/body_sync.rb +25 -0
  209. data/lib/runtime_analysis/trace/installer/built_classes.rb +43 -0
  210. data/lib/runtime_analysis/trace/installer/called_names.rb +33 -0
  211. data/lib/runtime_analysis/trace/installer/class_builders.rb +50 -0
  212. data/lib/runtime_analysis/trace/installer/deferral.rb +42 -0
  213. data/lib/runtime_analysis/trace/installer/hook.rb +170 -0
  214. data/lib/runtime_analysis/trace/installer/included_gems.rb +53 -0
  215. data/lib/runtime_analysis/trace/installer/probe.rb +28 -0
  216. data/lib/runtime_analysis/trace/installer/reflection.rb +50 -0
  217. data/lib/runtime_analysis/trace/installer/registry.rb +78 -0
  218. data/lib/runtime_analysis/trace/installer/sorbet.rb +29 -0
  219. data/lib/runtime_analysis/trace/installer/wrapping/ivar_writes.rb +62 -0
  220. data/lib/runtime_analysis/trace/installer/wrapping.rb +66 -0
  221. data/lib/runtime_analysis/trace/installer.rb +149 -0
  222. data/lib/runtime_analysis/trace/mechanism/block_entries.rb +29 -0
  223. data/lib/runtime_analysis/trace/mechanism/frame_readers.rb +61 -0
  224. data/lib/runtime_analysis/trace/mechanism/native_asks.rb +36 -0
  225. data/lib/runtime_analysis/trace/mechanism/native_sync.rb +28 -0
  226. data/lib/runtime_analysis/trace/mechanism/pure_wrapper.rb +41 -0
  227. data/lib/runtime_analysis/trace/mechanism/ruby_wrapper.rb +141 -0
  228. data/lib/runtime_analysis/trace/mechanism/wrapper.rb +79 -0
  229. data/lib/runtime_analysis/trace/mechanism/wrapper_shape.rb +40 -0
  230. data/lib/runtime_analysis/trace/mechanism.rb +28 -0
  231. data/lib/runtime_analysis/trace/nil_origin/answers.rb +24 -0
  232. data/lib/runtime_analysis/trace/nil_origin/beyond.rb +182 -0
  233. data/lib/runtime_analysis/trace/nil_origin/index.rb +164 -0
  234. data/lib/runtime_analysis/trace/nil_origin/lifetime.rb +29 -0
  235. data/lib/runtime_analysis/trace/nil_origin/named.rb +48 -0
  236. data/lib/runtime_analysis/trace/nil_origin/objects.rb +78 -0
  237. data/lib/runtime_analysis/trace/nil_origin/provenance.rb +136 -0
  238. data/lib/runtime_analysis/trace/nil_origin/receiver.rb +121 -0
  239. data/lib/runtime_analysis/trace/nil_origin/rows.rb +43 -0
  240. data/lib/runtime_analysis/trace/nil_origin/source.rb +315 -0
  241. data/lib/runtime_analysis/trace/nil_origin/stored.rb +159 -0
  242. data/lib/runtime_analysis/trace/nil_origin/told.rb +152 -0
  243. data/lib/runtime_analysis/trace/nil_origin/values.rb +47 -0
  244. data/lib/runtime_analysis/trace/nil_origin/weighed.rb +70 -0
  245. data/lib/runtime_analysis/trace/nil_origin/writers.rb +79 -0
  246. data/lib/runtime_analysis/trace/nil_origin.rb +278 -0
  247. data/lib/runtime_analysis/trace/novelty.rb +17 -0
  248. data/lib/runtime_analysis/trace/pure/novelty.rb +43 -0
  249. data/lib/runtime_analysis/trace/pure/state.rb +94 -0
  250. data/lib/runtime_analysis/trace/pure.rb +15 -0
  251. data/lib/runtime_analysis/trace/recorder/class_name.rb +63 -0
  252. data/lib/runtime_analysis/trace/recorder/fingerprint.rb +39 -0
  253. data/lib/runtime_analysis/trace/recorder/frame_key.rb +27 -0
  254. data/lib/runtime_analysis/trace/recorder/paths.rb +89 -0
  255. data/lib/runtime_analysis/trace/recorder/raise_site.rb +36 -0
  256. data/lib/runtime_analysis/trace/recorder/reachability.rb +46 -0
  257. data/lib/runtime_analysis/trace/recorder/row_emission.rb +137 -0
  258. data/lib/runtime_analysis/trace/recorder/safe_steps.rb +84 -0
  259. data/lib/runtime_analysis/trace/recorder/tree_steps.rb +42 -0
  260. data/lib/runtime_analysis/trace/recorder/unwinding.rb +23 -0
  261. data/lib/runtime_analysis/trace/recorder.rb +149 -0
  262. data/lib/runtime_analysis/trace/state.rb +16 -0
  263. data/lib/runtime_analysis/trace.rb +142 -0
  264. data/lib/runtime_analysis/version.rb +6 -0
  265. data/lib/runtime_analysis/web.rb +6 -0
  266. data/lib/runtime_analysis.rb +125 -0
  267. metadata +330 -0
@@ -0,0 +1,278 @@
1
+ # Runtime Analysis for Neovim
2
+
3
+ Two things, both answered from the recording under `tmp/runtime_analysis` in the project. It needs
4
+ Neovim 0.10 or later.
5
+
6
+ - A sidebar that lists what the code under the cursor is connected to by recorded calls: the methods
7
+ that reach it and the methods it reaches. With the cursor inside a method it shows that method;
8
+ outside any method it shows the whole file.
9
+ - Diagnostics, hover, code lens and references from `ra lsp`, the gem's language server.
10
+ - `gf` on a class, or on a value the recording saw, opens where its class is declared.
11
+
12
+ ## Free and Pro
13
+
14
+ The inline types, the hover, `gf` to a class, `:RaRerun` and the `verify_mock` diagnostics on spec
15
+ files work with the gem's own `ra`. The sidebar, the call stack, the nil trail, code lens and
16
+ references ask Pro tools, which the `ra` binary answers with a licence. Without it the sidebar shows
17
+ what `ra` said.
18
+
19
+ ## Install
20
+
21
+ Neovim's own packages need only a link:
22
+
23
+ ```sh
24
+ ln -s /path/to/runtime_analysis/gem/editor/nvim ~/.config/nvim/pack/local/start/runtime_analysis
25
+ ```
26
+
27
+ With a plugin manager, point it at this directory.
28
+
29
+ ## Every tool, from one menu
30
+
31
+ `<leader>ra` or `:Ra` lists every tool with what it answers. Pick one and it asks what to ask it
32
+ about: a method, class or namespace is picked from the ones the recording holds, and a file starts
33
+ as the one you are editing. The answer opens in a window below, where `Enter` on a `file:line` goes
34
+ there and `q` closes it.
35
+
36
+ The picking is `vim.ui.select`, so it is whatever picker your editor has: Telescope, fzf-lua, snacks,
37
+ or the plain numbered list.
38
+
39
+ ## How it runs `ra`
40
+
41
+ Neovim starts `ra` as a process, in the project's root. A shell function or alias called `ra` is
42
+ not there for it. So the plugin looks, in this order, for:
43
+
44
+ 1. `ra` on the `PATH`, the binary. It answers every tool and hands recording to the gem.
45
+ 2. `bin/ra` in the project, a binstub.
46
+
47
+ With neither it asks for `ra` by name, so that the editor says it is not installed. It never runs
48
+ `bundle exec ra`: the gem ships no `ra`, so a bundle has none to run.
49
+
50
+ `:LspLog` shows what the server said if it did not start.
51
+
52
+ ## Use
53
+
54
+ `<leader>rc` or `:RaConnected` opens and closes the sidebar. Inside it:
55
+
56
+ | Key | Does |
57
+ |---------------|------------------------------------------------------|
58
+ | `Enter` | Opens the method under the cursor at its definition |
59
+ | `o` | Steps through the call stack to the method |
60
+ | `1`, `2`, `3` | Follows that many files away |
61
+ | `a` | Follows all the way |
62
+ | `?` | Shows and hides these keys in the sidebar |
63
+ | `q` | Closes the sidebar |
64
+
65
+ `o` replaces the list with one recorded call stack, from the example or script that started it down
66
+ to the method: the route taken most often between the row and the method you are in. Each frame
67
+ sits on the line it made the next call from. Moving with `j` and `k` shows each frame in the window
68
+ beside the sidebar, the way a quickfix preview does. `Enter` opens the frame and stays there. `Esc`
69
+ puts the window back where it was and brings the list back.
70
+
71
+ ## Diagnostics
72
+
73
+ A Ruby buffer in a project with a recording is attached to `ra lsp`.
74
+
75
+ A line where a method was called on nil in a recorded run carries an error that names the method the
76
+ nil came from and where that method is. That method carries a warning of its own, pointing forward
77
+ at the line that raised.
78
+
79
+ The error's related locations are the trail the nil took: each method that returned it or was handed
80
+ it. Errors and warnings are drawn beneath their line with that trail, and the code they are about is
81
+ underlined. `:RaNilTrail` puts the trail in the location list, so `:lnext` steps from the crash back
82
+ to the origin. Recording the trail needs tier 4.
83
+
84
+ Diagnostics follow the recording and the file. When a run finishes, the server reads the recording
85
+ again and the open buffers update. A crash that a later run of the same example does not repeat is
86
+ dropped. A crash recorded before its file was edited turns into a warning that says so, on the line
87
+ its code has moved to.
88
+
89
+ `:RaRerun`, or `<leader>rr`, records again the examples that reached the file you are in, by
90
+ running `ra rerun` on it. Use it after an edit: a crash you fixed goes away, and one you put back
91
+ shows up again. It runs the file as saved.
92
+
93
+ Above each recorded method, with the Pro build of `ra`, two code lenses: `9 examples · 3 app runs`
94
+ and `▶ Record again`. Put the cursor on the method's line and run `vim.lsp.codelens.run()`, mapped to
95
+ a key of your choosing, then pick one. The count puts those examples in the quickfix list. **Record
96
+ again** runs `ra rerun` on each spec file they are in. A method that ran but no example reached
97
+ shows its count alone.
98
+
99
+ ```lua
100
+ require("runtime_analysis.inline").setup({
101
+ severity = "WARN", -- the mildest severity drawn beneath the code: ERROR, WARN, INFO or HINT. false draws none.
102
+ })
103
+ ```
104
+
105
+ The lines use `RuntimeAnalysisInlineError`, `RuntimeAnalysisInlineWarn`, `RuntimeAnalysisInlineInfo`
106
+ and `RuntimeAnalysisInlineHint`, which link to the `Diagnostic` groups, and the first line adds
107
+ `RuntimeAnalysisInlineTitle`, which is bold.
108
+
109
+ Set `vim.g.runtime_analysis_no_lsp = true` before the plugin loads to leave the language server off.
110
+
111
+ ## Types
112
+
113
+ Beside each parameter of a method that ran in a recording, the server shows the classes its argument
114
+ was given: `def active?(input)` reads `def active?(input: String | Time)`. A question mark means it
115
+ was sometimes nil, and `bool` stands for true and false. A class in the same namespace as the method
116
+ is given without it. Recording argument classes needs tier 2.
117
+
118
+ Inside a method, an assignment and a block parameter get the same, and the signature ends with what
119
+ the method returned:
120
+
121
+ ```ruby
122
+ def plan(title: String) -> String?
123
+ lesson: Lesson? = @catalog.find(title)
124
+ heading: String = lesson.summary
125
+ ```
126
+
127
+ An Array says what it held when a run recorded that: `def titles -> Array<String>`. A block's first
128
+ parameter takes its type from there, and an Array built by `map` is worked out from what its block
129
+ returns.
130
+
131
+ A local variable is never recorded. It is typed by the recorded call it was assigned from, and
132
+ failing that by the calls it was passed to or that were made on it. Returns need tier 3.
133
+
134
+ No run records inside a Hash, or inside an Array that no method returns. For those the server
135
+ reads what the source puts in: `@paths[id] = Path.new(...)` in one method makes `@paths = {}` in
136
+ another read `@paths: ~Hash<Integer, Path> = {}`, and `@names << name` does the same for an
137
+ Array. An instance variable is read from every method of its class in the file, and a local from
138
+ its own method. A key or a value that cannot be worked out is `untyped`. A block on such a Hash
139
+ gets its parameters typed from it: `@paths.each { |id: Integer, path: Path| ... }`.
140
+
141
+ A type with a `~` in front was worked out, not observed. Only the app's own methods are recorded,
142
+ so for a call on a core class the server uses the signatures Ruby ships: a String's `downcase`
143
+ returns a String. `const_name = event.payload_type.downcase.camelize` reads `const_name: ~String`.
144
+ Where a signature says what an Array holds, the type does too: `body.split(",")` is
145
+ `~Array<String>`, and the block that goes through it gets `|part: ~String|`.
146
+
147
+ A project that declares types has them used the same way, for whatever no run recorded. The server
148
+ reads Sorbet sigs in the app's own source, the RBI files under `sorbet/rbi`, the RBS files under
149
+ `sig`, and the gems' RBS that `rbs collection install` fetched:
150
+
151
+ ```ruby
152
+ sig { params(teacher: Teacher, notes: T::Array[String]).returns(T::Hash[Symbol, Integer]) }
153
+ def review(teacher, notes = [])
154
+ name: ~String = teacher.name
155
+ words: ~Array<String> = notes.flat_map { |note: ~String| note.split(" ") }
156
+ others: ~Array<Lesson> = Lesson.where_title(name)
157
+ ```
158
+
159
+ What a run observed comes first, and a declared type fills in where there was no run. A sig written
160
+ right above a method is not repeated in hints beside it. A declaration kept in another file, an
161
+ RBI or an RBS file, is shown: `def unsigned(count: ~Integer) -> ~Lesson?`.
162
+
163
+ Nothing of Sorbet's is loaded, since a sig is read as it is written. RBS takes the rbs gem, which
164
+ Ruby ships. When the app's bundle does not include it, the server reads the RBS with a second
165
+ Ruby started outside the bundle. The declarations are read again when a file is saved.
166
+
167
+ A method the receiver answers through `method_missing` is recorded with the name it was asked for,
168
+ so `event.payload_type` is typed as observed. A recording made before that was recorded knows only
169
+ that `method_missing` ran. For those, the `method_missing` calls on the same line stand in, and the
170
+ type carries a `~`. The popup says which it was.
171
+
172
+ Rest the cursor on a variable, a parameter or a call and a popup shows its classes with how often
173
+ each was seen, and the messages the same objects were sent afterwards, anywhere in the call tree,
174
+ with the methods that sent them. Objects are matched by the ids recorded at tier 3, and only
175
+ messages to methods the app defines are recorded, so a String shows none. `K` shows the same on
176
+ demand, and describes the method when the cursor is not on a value. `K` is only mapped when you
177
+ have no mapping of your own for it.
178
+
179
+ ```lua
180
+ require("runtime_analysis.lsp").setup({
181
+ inlay_hints = true, -- false to leave the inline types off
182
+ code_lens = true, -- false to leave the code lenses off
183
+ value_popup = 500, -- milliseconds the cursor rests before the popup shows. false for none.
184
+ hover_key = "K", -- false to leave the key alone
185
+ class_key = "gf", -- false to leave the key alone
186
+ })
187
+ ```
188
+
189
+ The types are inlay hints, which Neovim draws with the `LspInlayHint` group. They are on for a
190
+ buffer attached to `ra lsp`. `<leader>rt`, or `:RaTypes`, hides them everywhere and shows them
191
+ again. The popup still works while they are hidden.
192
+
193
+ ## Go to a class
194
+
195
+ `gf` goes to the class under the cursor, in a buffer attached to `ra lsp`:
196
+
197
+ | Cursor on | Opens |
198
+ |-----------------------------------------|----------------------------------------|
199
+ | A constant, `Lesson` or `Vx::Lesson` | Where that class or module is declared |
200
+ | A variable or parameter | The class the recording saw it hold |
201
+ | A call | The class the call returned |
202
+ | Any of those holding an `Array<Lesson>` | `Lesson` |
203
+ | Anything else, such as a file's name | What `gf` opened before |
204
+
205
+ Only classes your project declares have somewhere to go, so on a String the key does what it did
206
+ before: Vim's own `gf`, or the mapping another plugin such as vim-rails gave it. `Ctrl-O` and
207
+ `Ctrl-T` come back.
208
+
209
+ When a value was seen as several of your classes, `gf` opens the one seen most and puts them all
210
+ in the location list, for `:lnext` and `:lopen`. A class opened in more than one file is listed
211
+ the same way.
212
+
213
+ A constant is found by its name in the source under `app` and `lib`, whether or not a run
214
+ reached it. Other editors get the same from the language server as "go to type definition".
215
+
216
+ ## Configure
217
+
218
+ Every setting is optional. The values shown are the defaults.
219
+
220
+ ```lua
221
+ require("runtime_analysis.connected").setup({
222
+ width = 64, -- columns
223
+ depth = "all", -- how many files away to follow: a number, or "all"
224
+ debounce = 150, -- milliseconds the cursor must rest before asking
225
+ theme = "vivid", -- or "scheme", see below
226
+ heat = { warm = 100, hot = 1000 }, -- call counts at which the number at the right changes colour
227
+ highlights = {}, -- overrides, see below
228
+ })
229
+ ```
230
+
231
+ Set `vim.g.runtime_analysis_no_mappings = true` before the plugin loads to leave `<leader>rc`,
232
+ `<leader>rr` and `<leader>rt` alone, and map `<Plug>(RaConnected)`, `<Plug>(RaRerun)` and
233
+ `<Plug>(RaTypes)` yourself.
234
+
235
+ ## Colours
236
+
237
+ There are two themes.
238
+
239
+ - `vivid`, the default, is the sidebar's own palette: the colours of the code samples on the website,
240
+ which are VS Code's Dark+ and Light+, picked by `background`.
241
+ - `scheme` links every group to a standard one, so the sidebar looks like the rest of your editor.
242
+
243
+ Colour is spent where it tells you something. A method is coloured by how it is called and how its
244
+ name ends. The namespace is dimmer than the class, the directory dimmer than the file. The callers'
245
+ heading and the callees' heading differ. The call count at the right warms up as it grows.
246
+
247
+ | Group | Colours | `vivid`, dark | `scheme` |
248
+ |---------------------------------------|------------------------------|---------------|---------------------------|
249
+ | `RuntimeAnalysisCallers` | "reaches unlock_next" | blue, bold | `Title` |
250
+ | `RuntimeAnalysisCallees` | "unlock_next reaches" | purple, bold | `Title` |
251
+ | `RuntimeAnalysisTally` | "(3 files)" | green | `Comment` |
252
+ | `RuntimeAnalysisNamespace` | `Billing::` before the class | dim teal | `Type` |
253
+ | `RuntimeAnalysisClass` | the class | teal | `Type` |
254
+ | `RuntimeAnalysisMethod` | `#method` | yellow | `Function` |
255
+ | `RuntimeAnalysisBangMethod` | `#method!` | red | `DiagnosticWarn` |
256
+ | `RuntimeAnalysisPredicateMethod` | `#method?` | light blue | `Boolean` |
257
+ | `RuntimeAnalysisClassMethod` | `.method` | lilac | `Special` |
258
+ | `RuntimeAnalysisClassBangMethod` | `.method!` | red, bold | `DiagnosticWarn`, in bold |
259
+ | `RuntimeAnalysisClassPredicateMethod` | `.method?` | light blue, bold | `Boolean`, in bold |
260
+ | `RuntimeAnalysisDirectory` | `app/models/` | grey | `Comment` |
261
+ | `RuntimeAnalysisFile` | `invoice.rb` | orange | `Comment` |
262
+ | `RuntimeAnalysisLine` | `:42` | pale green | `LineNr` |
263
+ | `RuntimeAnalysisCalls` | a count under `heat.warm` | grey | `Number` |
264
+ | `RuntimeAnalysisCallsWarm` | a count from `heat.warm` | yellow | `Number` |
265
+ | `RuntimeAnalysisCallsHot` | a count from `heat.hot` | orange, bold | `Number`, in bold |
266
+ | `RuntimeAnalysisMessage` | "asking ra…" and errors | green, italic | `Comment` |
267
+
268
+ Change any of them through `setup`, with anything `nvim_set_hl` accepts. These are applied over the
269
+ theme, and again whenever the colour scheme changes:
270
+
271
+ ```lua
272
+ require("runtime_analysis.connected").setup({
273
+ highlights = {
274
+ RuntimeAnalysisMethod = { fg = "#e0af68", bold = true },
275
+ RuntimeAnalysisFile = { link = "NonText" },
276
+ },
277
+ })
278
+ ```