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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +115 -0
- data/LICENSE.txt +96 -0
- data/README.md +164 -0
- data/editor/nvim/README.md +278 -0
- data/editor/nvim/lua/runtime_analysis/connected.lua +565 -0
- data/editor/nvim/lua/runtime_analysis/go_to_class.lua +63 -0
- data/editor/nvim/lua/runtime_analysis/inline.lua +138 -0
- data/editor/nvim/lua/runtime_analysis/lens.lua +50 -0
- data/editor/nvim/lua/runtime_analysis/lsp.lua +92 -0
- data/editor/nvim/lua/runtime_analysis/menu.lua +98 -0
- data/editor/nvim/lua/runtime_analysis/preview.lua +70 -0
- data/editor/nvim/lua/runtime_analysis/project.lua +28 -0
- data/editor/nvim/lua/runtime_analysis/rerun.lua +39 -0
- data/editor/nvim/lua/runtime_analysis/text.lua +23 -0
- data/editor/nvim/lua/runtime_analysis/value_popup.lua +45 -0
- data/editor/nvim/plugin/runtime_analysis.lua +71 -0
- data/examples/trackers/PROMPT.md +86 -0
- data/examples/trackers/honeybadger.rb +19 -0
- data/examples/trackers/sentry.rb +16 -0
- data/ext/runtime_analysis/extconf.rb +68 -0
- data/ext/runtime_analysis/fast.c +775 -0
- data/ext/runtime_analysis/fast.h +59 -0
- data/ext/runtime_analysis/hold.c +560 -0
- data/ext/runtime_analysis/init.c +36 -0
- data/ext/runtime_analysis/names.c +78 -0
- data/ext/runtime_analysis/names.h +28 -0
- data/ext/runtime_analysis/novelty.c +139 -0
- data/ext/runtime_analysis/novelty.h +22 -0
- data/ext/runtime_analysis/os.c +73 -0
- data/ext/runtime_analysis/os.h +32 -0
- data/ext/runtime_analysis/ring.c +445 -0
- data/ext/runtime_analysis/rows.c +304 -0
- data/ext/runtime_analysis/sink.c +485 -0
- data/ext/runtime_analysis/sink.h +240 -0
- data/ext/runtime_analysis/state.c +254 -0
- data/ext/runtime_analysis/state.h +57 -0
- data/ext/runtime_analysis/wrapper.c +278 -0
- data/ext/runtime_analysis/wrapper.h +24 -0
- data/lib/runtime_analysis/errors.rb +34 -0
- data/lib/runtime_analysis/failsafe.rb +123 -0
- data/lib/runtime_analysis/host/controller_entry_point.rb +18 -0
- data/lib/runtime_analysis/host/declared.rb +152 -0
- data/lib/runtime_analysis/host/inject.rb +90 -0
- data/lib/runtime_analysis/host/job_runners.rb +27 -0
- data/lib/runtime_analysis/host/middleware.rb +23 -0
- data/lib/runtime_analysis/host/minitest_integration.rb +22 -0
- data/lib/runtime_analysis/host/railtie.rb +42 -0
- data/lib/runtime_analysis/host/reports.rb +54 -0
- data/lib/runtime_analysis/host/rspec_integration.rb +17 -0
- data/lib/runtime_analysis/host/web.rb +22 -0
- data/lib/runtime_analysis/host.rb +34 -0
- data/lib/runtime_analysis/inject.rb +5 -0
- data/lib/runtime_analysis/minitest.rb +9 -0
- data/lib/runtime_analysis/native/build.rb +17 -0
- data/lib/runtime_analysis/native/byte_size.rb +27 -0
- data/lib/runtime_analysis/native/call_site_logger/definitions.rb +51 -0
- data/lib/runtime_analysis/native/call_site_logger/held.rb +35 -0
- data/lib/runtime_analysis/native/call_site_logger/rows.rb +110 -0
- data/lib/runtime_analysis/native/call_site_logger/segments.rb +100 -0
- data/lib/runtime_analysis/native/call_site_logger/streams.rb +110 -0
- data/lib/runtime_analysis/native/call_site_logger.rb +80 -0
- data/lib/runtime_analysis/native/rotation_policy.rb +28 -0
- data/lib/runtime_analysis/native/sanitizer_runtime.rb +50 -0
- data/lib/runtime_analysis/native/sink.rb +12 -0
- data/lib/runtime_analysis/native.rb +74 -0
- data/lib/runtime_analysis/platform.rb +30 -0
- data/lib/runtime_analysis/query/index/anonymise.rb +98 -0
- data/lib/runtime_analysis/query/index/graph.rb +107 -0
- data/lib/runtime_analysis/query/index/graph_cache.rb +32 -0
- data/lib/runtime_analysis/query/index/reading/declared.rb +42 -0
- data/lib/runtime_analysis/query/index/reading/dict.rb +43 -0
- data/lib/runtime_analysis/query/index/reading/frame.rb +27 -0
- data/lib/runtime_analysis/query/index/reading/node.rb +45 -0
- data/lib/runtime_analysis/query/index/reading/path.rb +21 -0
- data/lib/runtime_analysis/query/index/reading/reruns.rb +30 -0
- data/lib/runtime_analysis/query/index/reading/rows.rb +128 -0
- data/lib/runtime_analysis/query/index/reading/stream.rb +82 -0
- data/lib/runtime_analysis/query/index/reading/tree.rb +66 -0
- data/lib/runtime_analysis/query/index/reading/tree_builder.rb +135 -0
- data/lib/runtime_analysis/query/index/reading/values.rb +49 -0
- data/lib/runtime_analysis/query/index/reading.rb +80 -0
- data/lib/runtime_analysis/query/index/shapes.rb +142 -0
- data/lib/runtime_analysis/query/index/signatures/active_support.rb +31 -0
- data/lib/runtime_analysis/query/index/signatures/core.json +1 -0
- data/lib/runtime_analysis/query/index/signatures/layers.rb +29 -0
- data/lib/runtime_analysis/query/index/signatures/lineage.rb +57 -0
- data/lib/runtime_analysis/query/index/signatures/overloads.rb +32 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/entry.rb +95 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/export.rb +76 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/library.rb +43 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/overload.rb +66 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/project.rb +69 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/types.rb +79 -0
- data/lib/runtime_analysis/query/index/signatures/rbs.rb +57 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/sig.rb +48 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/signed.rb +69 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/table.rb +43 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/types.rb +96 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet.rb +150 -0
- data/lib/runtime_analysis/query/index/signatures/sources.rb +80 -0
- data/lib/runtime_analysis/query/index/signatures/written.rb +45 -0
- data/lib/runtime_analysis/query/index/signatures.rb +93 -0
- data/lib/runtime_analysis/query/index/source_named_graph.rb +84 -0
- data/lib/runtime_analysis/query/index/static/change_set.rb +20 -0
- data/lib/runtime_analysis/query/index/static/changes.rb +80 -0
- data/lib/runtime_analysis/query/index/static/code_visitor.rb +144 -0
- data/lib/runtime_analysis/query/index/static/klass.rb +13 -0
- data/lib/runtime_analysis/query/index/static/method.rb +19 -0
- data/lib/runtime_analysis/query/index/static/params.rb +52 -0
- data/lib/runtime_analysis/query/index/static/source.rb +69 -0
- data/lib/runtime_analysis/query/index/static/stub.rb +14 -0
- data/lib/runtime_analysis/query/index/static/stub_visitor.rb +133 -0
- data/lib/runtime_analysis/query/index/static/value.rb +17 -0
- data/lib/runtime_analysis/query/index/static/values.rb +71 -0
- data/lib/runtime_analysis/query/index/static/visibility.rb +40 -0
- data/lib/runtime_analysis/query/index/static.rb +85 -0
- data/lib/runtime_analysis/query/index.rb +32 -0
- data/lib/runtime_analysis/query/nodes.rb +60 -0
- data/lib/runtime_analysis/query/project/config.rb +108 -0
- data/lib/runtime_analysis/query/project.rb +40 -0
- data/lib/runtime_analysis/query/report/document.rb +84 -0
- data/lib/runtime_analysis/query/report/finding.rb +15 -0
- data/lib/runtime_analysis/query/report/json_renderer.rb +51 -0
- data/lib/runtime_analysis/query/report/list.rb +15 -0
- data/lib/runtime_analysis/query/report/location.rb +14 -0
- data/lib/runtime_analysis/query/report/one_row.rb +14 -0
- data/lib/runtime_analysis/query/report/outline.rb +15 -0
- data/lib/runtime_analysis/query/report/paint.rb +34 -0
- data/lib/runtime_analysis/query/report/related.rb +11 -0
- data/lib/runtime_analysis/query/report/table.rb +15 -0
- data/lib/runtime_analysis/query/report/text.rb +13 -0
- data/lib/runtime_analysis/query/report/text_renderer.rb +102 -0
- data/lib/runtime_analysis/query/report.rb +35 -0
- data/lib/runtime_analysis/query/surfaces/class_value.rb +17 -0
- data/lib/runtime_analysis/query/surfaces/cli/answer.rb +32 -0
- data/lib/runtime_analysis/query/surfaces/cli/command_line.rb +77 -0
- data/lib/runtime_analysis/query/surfaces/cli/usage.rb +32 -0
- data/lib/runtime_analysis/query/surfaces/cli.rb +101 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/lexical.rb +44 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/notation.rb +33 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/observed.rb +102 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/outline.rb +111 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/rbs_file.rb +100 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/rbs_member.rb +50 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/rbs_notation.rb +44 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/seen.rb +74 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/sig_text.rb +49 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/sorbet_edit.rb +106 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/sorbet_notation.rb +48 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/subject.rb +55 -0
- data/lib/runtime_analysis/query/surfaces/crystallise.rb +94 -0
- data/lib/runtime_analysis/query/surfaces/mcp.rb +89 -0
- data/lib/runtime_analysis/query/surfaces/record/commands.rb +45 -0
- data/lib/runtime_analysis/query/surfaces/record/environment.rb +48 -0
- data/lib/runtime_analysis/query/surfaces/record/ignore.rb +62 -0
- data/lib/runtime_analysis/query/surfaces/record/question.rb +55 -0
- data/lib/runtime_analysis/query/surfaces/record/run.rb +30 -0
- data/lib/runtime_analysis/query/surfaces/record.rb +122 -0
- data/lib/runtime_analysis/query/surfaces/rerun.rb +87 -0
- data/lib/runtime_analysis/query/surfaces/setup/agents.rb +76 -0
- data/lib/runtime_analysis/query/surfaces/setup/changes.rb +107 -0
- data/lib/runtime_analysis/query/surfaces/setup/project.rb +80 -0
- data/lib/runtime_analysis/query/surfaces/setup/steps.md +205 -0
- data/lib/runtime_analysis/query/surfaces/setup.rb +98 -0
- data/lib/runtime_analysis/query/surfaces.rb +14 -0
- data/lib/runtime_analysis/query/tools/base.rb +86 -0
- data/lib/runtime_analysis/query/tools/method_lookup.rb +37 -0
- data/lib/runtime_analysis/query/tools/namespaces.rb +36 -0
- data/lib/runtime_analysis/query/tools/origins.rb +47 -0
- data/lib/runtime_analysis/query/tools/stubs.rb +53 -0
- data/lib/runtime_analysis/query/tools/unknown_method.rb +11 -0
- data/lib/runtime_analysis/query/tools/verify_mock.rb +145 -0
- data/lib/runtime_analysis/query/tools/what_calls.rb +67 -0
- data/lib/runtime_analysis/query/tools/what_it_receives.rb +142 -0
- data/lib/runtime_analysis/query/tools/where_nil_comes_from.rb +105 -0
- data/lib/runtime_analysis/query/tools/who_actually_answered.rb +82 -0
- data/lib/runtime_analysis/query/tools.rb +34 -0
- data/lib/runtime_analysis/query.rb +33 -0
- data/lib/runtime_analysis/recording/blob.rb +13 -0
- data/lib/runtime_analysis/recording/format.rb +32 -0
- data/lib/runtime_analysis/recording/opcodes.rb +30 -0
- data/lib/runtime_analysis/recording/raise_ids.rb +15 -0
- data/lib/runtime_analysis/recording/ruby_sink.rb +176 -0
- data/lib/runtime_analysis/recording/run_manifest.rb +110 -0
- data/lib/runtime_analysis/recording/seen/nothing.rb +15 -0
- data/lib/runtime_analysis/recording/seen/tally.rb +48 -0
- data/lib/runtime_analysis/recording/seen.rb +63 -0
- data/lib/runtime_analysis/recording/sink.rb +19 -0
- data/lib/runtime_analysis/recording/source_blob.rb +20 -0
- data/lib/runtime_analysis/recording.rb +52 -0
- data/lib/runtime_analysis/rspec.rb +8 -0
- data/lib/runtime_analysis/ruby_parsing/packages.rb +17 -0
- data/lib/runtime_analysis/ruby_parsing.rb +98 -0
- data/lib/runtime_analysis/trace/configuration/capturing.rb +32 -0
- data/lib/runtime_analysis/trace/configuration/per_run.rb +31 -0
- data/lib/runtime_analysis/trace/configuration/tier.rb +27 -0
- data/lib/runtime_analysis/trace/configuration.rb +115 -0
- data/lib/runtime_analysis/trace/entries.rb +47 -0
- data/lib/runtime_analysis/trace/hold/raises.rb +28 -0
- data/lib/runtime_analysis/trace/hold/requests.rb +47 -0
- data/lib/runtime_analysis/trace/hold/telling.rb +45 -0
- data/lib/runtime_analysis/trace/hold/unwound.rb +30 -0
- data/lib/runtime_analysis/trace/hold.rb +142 -0
- data/lib/runtime_analysis/trace/inclusion.rb +46 -0
- data/lib/runtime_analysis/trace/installer/alias_repair.rb +68 -0
- data/lib/runtime_analysis/trace/installer/answers.rb +24 -0
- data/lib/runtime_analysis/trace/installer/body_sync.rb +25 -0
- data/lib/runtime_analysis/trace/installer/built_classes.rb +43 -0
- data/lib/runtime_analysis/trace/installer/called_names.rb +33 -0
- data/lib/runtime_analysis/trace/installer/class_builders.rb +50 -0
- data/lib/runtime_analysis/trace/installer/deferral.rb +42 -0
- data/lib/runtime_analysis/trace/installer/hook.rb +170 -0
- data/lib/runtime_analysis/trace/installer/included_gems.rb +53 -0
- data/lib/runtime_analysis/trace/installer/probe.rb +28 -0
- data/lib/runtime_analysis/trace/installer/reflection.rb +50 -0
- data/lib/runtime_analysis/trace/installer/registry.rb +78 -0
- data/lib/runtime_analysis/trace/installer/sorbet.rb +29 -0
- data/lib/runtime_analysis/trace/installer/wrapping/ivar_writes.rb +62 -0
- data/lib/runtime_analysis/trace/installer/wrapping.rb +66 -0
- data/lib/runtime_analysis/trace/installer.rb +149 -0
- data/lib/runtime_analysis/trace/mechanism/block_entries.rb +29 -0
- data/lib/runtime_analysis/trace/mechanism/frame_readers.rb +61 -0
- data/lib/runtime_analysis/trace/mechanism/native_asks.rb +36 -0
- data/lib/runtime_analysis/trace/mechanism/native_sync.rb +28 -0
- data/lib/runtime_analysis/trace/mechanism/pure_wrapper.rb +41 -0
- data/lib/runtime_analysis/trace/mechanism/ruby_wrapper.rb +141 -0
- data/lib/runtime_analysis/trace/mechanism/wrapper.rb +79 -0
- data/lib/runtime_analysis/trace/mechanism/wrapper_shape.rb +40 -0
- data/lib/runtime_analysis/trace/mechanism.rb +28 -0
- data/lib/runtime_analysis/trace/nil_origin/answers.rb +24 -0
- data/lib/runtime_analysis/trace/nil_origin/beyond.rb +182 -0
- data/lib/runtime_analysis/trace/nil_origin/index.rb +164 -0
- data/lib/runtime_analysis/trace/nil_origin/lifetime.rb +29 -0
- data/lib/runtime_analysis/trace/nil_origin/named.rb +48 -0
- data/lib/runtime_analysis/trace/nil_origin/objects.rb +78 -0
- data/lib/runtime_analysis/trace/nil_origin/provenance.rb +136 -0
- data/lib/runtime_analysis/trace/nil_origin/receiver.rb +121 -0
- data/lib/runtime_analysis/trace/nil_origin/rows.rb +43 -0
- data/lib/runtime_analysis/trace/nil_origin/source.rb +315 -0
- data/lib/runtime_analysis/trace/nil_origin/stored.rb +159 -0
- data/lib/runtime_analysis/trace/nil_origin/told.rb +152 -0
- data/lib/runtime_analysis/trace/nil_origin/values.rb +47 -0
- data/lib/runtime_analysis/trace/nil_origin/weighed.rb +70 -0
- data/lib/runtime_analysis/trace/nil_origin/writers.rb +79 -0
- data/lib/runtime_analysis/trace/nil_origin.rb +278 -0
- data/lib/runtime_analysis/trace/novelty.rb +17 -0
- data/lib/runtime_analysis/trace/pure/novelty.rb +43 -0
- data/lib/runtime_analysis/trace/pure/state.rb +94 -0
- data/lib/runtime_analysis/trace/pure.rb +15 -0
- data/lib/runtime_analysis/trace/recorder/class_name.rb +63 -0
- data/lib/runtime_analysis/trace/recorder/fingerprint.rb +39 -0
- data/lib/runtime_analysis/trace/recorder/frame_key.rb +27 -0
- data/lib/runtime_analysis/trace/recorder/paths.rb +89 -0
- data/lib/runtime_analysis/trace/recorder/raise_site.rb +36 -0
- data/lib/runtime_analysis/trace/recorder/reachability.rb +46 -0
- data/lib/runtime_analysis/trace/recorder/row_emission.rb +137 -0
- data/lib/runtime_analysis/trace/recorder/safe_steps.rb +84 -0
- data/lib/runtime_analysis/trace/recorder/tree_steps.rb +42 -0
- data/lib/runtime_analysis/trace/recorder/unwinding.rb +23 -0
- data/lib/runtime_analysis/trace/recorder.rb +149 -0
- data/lib/runtime_analysis/trace/state.rb +16 -0
- data/lib/runtime_analysis/trace.rb +142 -0
- data/lib/runtime_analysis/version.rb +6 -0
- data/lib/runtime_analysis/web.rb +6 -0
- data/lib/runtime_analysis.rb +125 -0
- metadata +330 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
-- Draws a finding beneath the line it is about: its message, then each related place, such as the
|
|
2
|
+
-- methods a nil passed through on its way to the line that raised. Neovim's own float shows the
|
|
3
|
+
-- message alone and leaves the related places out.
|
|
4
|
+
|
|
5
|
+
local M = {}
|
|
6
|
+
|
|
7
|
+
local HANDLER = "runtime_analysis_inline"
|
|
8
|
+
local severity = vim.diagnostic.severity
|
|
9
|
+
|
|
10
|
+
local config = {
|
|
11
|
+
severity = "WARN", -- the mildest severity drawn beneath the code: ERROR, WARN, INFO or HINT. false draws none.
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
local LOOK = {
|
|
15
|
+
[severity.ERROR] = { icon = "✗", group = "RuntimeAnalysisInlineError", link = "DiagnosticError" },
|
|
16
|
+
[severity.WARN] = { icon = "⚠", group = "RuntimeAnalysisInlineWarn", link = "DiagnosticWarn" },
|
|
17
|
+
[severity.INFO] = { icon = "ℹ", group = "RuntimeAnalysisInlineInfo", link = "DiagnosticInfo" },
|
|
18
|
+
[severity.HINT] = { icon = "·", group = "RuntimeAnalysisInlineHint", link = "DiagnosticHint" },
|
|
19
|
+
}
|
|
20
|
+
local TITLE = "RuntimeAnalysisInlineTitle"
|
|
21
|
+
|
|
22
|
+
local marks = {}
|
|
23
|
+
|
|
24
|
+
local function define_highlights()
|
|
25
|
+
for _, look in pairs(LOOK) do
|
|
26
|
+
vim.api.nvim_set_hl(0, look.group, { link = look.link, default = true })
|
|
27
|
+
end
|
|
28
|
+
vim.api.nvim_set_hl(0, TITLE, { bold = true, default = true })
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
local function wrap(text, width)
|
|
32
|
+
local lines, line = {}, ""
|
|
33
|
+
for word in text:gmatch("%S+") do
|
|
34
|
+
if line ~= "" and vim.fn.strdisplaywidth(line .. " " .. word) > width then
|
|
35
|
+
table.insert(lines, line)
|
|
36
|
+
line = word
|
|
37
|
+
else
|
|
38
|
+
line = line == "" and word or (line .. " " .. word)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
if line ~= "" then table.insert(lines, line) end
|
|
42
|
+
return lines
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
-- The columns left for text in the window showing the buffer, once the code's indentation is taken off.
|
|
46
|
+
local function room(bufnr, indent)
|
|
47
|
+
local window = vim.fn.bufwinid(bufnr)
|
|
48
|
+
if window == -1 then return 100 end
|
|
49
|
+
return math.max(40, vim.api.nvim_win_get_width(window) - vim.fn.getwininfo(window)[1].textoff - indent - 6)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
-- A place as the buffer would call it: a line of its own, a file beside it by name, anything else by
|
|
53
|
+
-- its path from the working directory.
|
|
54
|
+
local function label(location, bufnr)
|
|
55
|
+
local line = location.range.start.line + 1
|
|
56
|
+
local file = vim.uri_to_fname(location.uri)
|
|
57
|
+
local here = vim.api.nvim_buf_get_name(bufnr)
|
|
58
|
+
if file == here then return "line " .. line end
|
|
59
|
+
if vim.fs.dirname(file) == vim.fs.dirname(here) then return vim.fs.basename(file) .. ":" .. line end
|
|
60
|
+
return vim.fn.fnamemodify(file, ":.") .. ":" .. line
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
local function names(text, place)
|
|
64
|
+
local from, to = text:find(place, 1, true)
|
|
65
|
+
return from ~= nil and not text:sub(to + 1, to + 1):match("%d")
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
-- The related places, one line each. They are left out when the headline already names every one of
|
|
69
|
+
-- them, as it does for a nil that came straight from one method.
|
|
70
|
+
local function related_lines(diagnostic, bufnr, headline)
|
|
71
|
+
local lsp = diagnostic.user_data and diagnostic.user_data.lsp
|
|
72
|
+
local lines, unnamed = {}, false
|
|
73
|
+
for _, place in ipairs(lsp and lsp.relatedInformation or {}) do
|
|
74
|
+
local where = label(place.location, bufnr)
|
|
75
|
+
unnamed = unnamed or not names(headline, where)
|
|
76
|
+
table.insert(lines, "↳ " .. place.message .. " (" .. where .. ")")
|
|
77
|
+
end
|
|
78
|
+
return unnamed and lines or {}
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
-- The first row of the first paragraph carries the icon and is bold. Rows a paragraph wraps onto
|
|
82
|
+
-- are indented under it.
|
|
83
|
+
local function rows_for(diagnostic, bufnr)
|
|
84
|
+
local look = LOOK[diagnostic.severity]
|
|
85
|
+
local code = vim.api.nvim_buf_get_lines(bufnr, diagnostic.lnum, diagnostic.lnum + 1, false)[1] or ""
|
|
86
|
+
local indent = #code:match("^%s*")
|
|
87
|
+
local paragraphs = vim.split(diagnostic.message, "\n")
|
|
88
|
+
vim.list_extend(paragraphs, related_lines(diagnostic, bufnr, paragraphs[1]))
|
|
89
|
+
local rows = {}
|
|
90
|
+
for index, paragraph in ipairs(paragraphs) do
|
|
91
|
+
for part, text in ipairs(wrap(paragraph, room(bufnr, indent))) do
|
|
92
|
+
local title = index == 1 and part == 1
|
|
93
|
+
local lead = title and (look.icon .. " ") or (part == 1 and " " or " ")
|
|
94
|
+
table.insert(rows, { { string.rep(" ", indent) .. lead .. text, title and { look.group, TITLE } or look.group } })
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
return rows
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
local function drawn(diagnostic)
|
|
101
|
+
local floor = config.severity and severity[config.severity]
|
|
102
|
+
return floor and diagnostic.severity <= floor
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
local function show(namespace, bufnr, diagnostics)
|
|
106
|
+
marks[namespace] = marks[namespace] or vim.api.nvim_create_namespace(HANDLER .. "_" .. namespace)
|
|
107
|
+
vim.api.nvim_buf_clear_namespace(bufnr, marks[namespace], 0, -1)
|
|
108
|
+
for _, diagnostic in ipairs(diagnostics) do
|
|
109
|
+
if drawn(diagnostic) then
|
|
110
|
+
vim.api.nvim_buf_set_extmark(bufnr, marks[namespace], diagnostic.lnum, 0, { virt_lines = rows_for(diagnostic, bufnr) })
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
local function hide(namespace, bufnr)
|
|
116
|
+
if marks[namespace] and vim.api.nvim_buf_is_valid(bufnr) then
|
|
117
|
+
vim.api.nvim_buf_clear_namespace(bufnr, marks[namespace], 0, -1)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
function M.setup(options)
|
|
122
|
+
config = vim.tbl_deep_extend("force", config, options or {})
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
-- Turns the drawing on for one language client's diagnostics and leaves every other source as it is.
|
|
126
|
+
function M.enable(client)
|
|
127
|
+
define_highlights()
|
|
128
|
+
vim.diagnostic.handlers[HANDLER] = { show = show, hide = hide }
|
|
129
|
+
local namespace = vim.lsp.diagnostic.get_namespace(client.id, false)
|
|
130
|
+
vim.diagnostic.config({ [HANDLER] = true, virtual_text = false, virtual_lines = false }, namespace)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
vim.api.nvim_create_autocmd("ColorScheme", {
|
|
134
|
+
group = vim.api.nvim_create_augroup(HANDLER, { clear = true }),
|
|
135
|
+
callback = define_highlights,
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
return M
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
-- What the two code lenses `ra lsp` puts over a recorded method do when run with
|
|
2
|
+
-- vim.lsp.codelens.run(): the example count lists those examples in the quickfix list, and
|
|
3
|
+
-- "▶ Record again" records them again with `ra rerun`. Their command ids are the editor's to answer,
|
|
4
|
+
-- so without this module Neovim says the server does not support them.
|
|
5
|
+
|
|
6
|
+
local project = require("runtime_analysis.project")
|
|
7
|
+
local rerun = require("runtime_analysis.rerun")
|
|
8
|
+
|
|
9
|
+
local M = {}
|
|
10
|
+
|
|
11
|
+
-- `ra rerun` records a spec file whole, so example ids come down to their files, each once.
|
|
12
|
+
function M.spec_files(ids)
|
|
13
|
+
local files, seen = {}, {}
|
|
14
|
+
for _, id in ipairs(ids) do
|
|
15
|
+
local file = id:gsub("^%./", ""):gsub("%[[%d:]+%]$", ""):gsub(":%d+$", "")
|
|
16
|
+
if not seen[file] then
|
|
17
|
+
seen[file] = true
|
|
18
|
+
table.insert(files, file)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
return files
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
-- The arguments are the method's document, its position and an LSP Location for each example.
|
|
25
|
+
function M.show_examples(command)
|
|
26
|
+
local examples = command.arguments[3]
|
|
27
|
+
vim.fn.setqflist({}, " ", { title = "Examples", items = vim.lsp.util.locations_to_items(examples, "utf-16") })
|
|
28
|
+
vim.cmd.copen()
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
function M.run_specs(command, context)
|
|
32
|
+
local files = M.spec_files(command.arguments)
|
|
33
|
+
local what = #files == 1 and files[1] or (#files .. " spec files")
|
|
34
|
+
rerun.files(project.root(context.bufnr), files, what)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
vim.lsp.commands["runtime_analysis.showExamples"] = M.show_examples
|
|
38
|
+
vim.lsp.commands["runtime_analysis.runSpecs"] = M.run_specs
|
|
39
|
+
|
|
40
|
+
-- Draws the lenses in a buffer and keeps them current as it changes and as new recordings land.
|
|
41
|
+
function M.enable(bufnr)
|
|
42
|
+
vim.lsp.codelens.refresh({ bufnr = bufnr })
|
|
43
|
+
vim.api.nvim_create_autocmd({ "BufEnter", "InsertLeave", "BufWritePost" }, {
|
|
44
|
+
group = vim.api.nvim_create_augroup("runtime_analysis_lens_" .. bufnr, { clear = true }),
|
|
45
|
+
buffer = bufnr,
|
|
46
|
+
callback = function() vim.lsp.codelens.refresh({ bufnr = bufnr }) end,
|
|
47
|
+
})
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
return M
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
-- Attaches Ruby buffers to `ra lsp`, the language server that answers from the recording: hover, the
|
|
2
|
+
-- way to a class, code lens, references, implementations and diagnostics. Neovim starts one server
|
|
3
|
+
-- per project and reuses it for every buffer under the same root.
|
|
4
|
+
|
|
5
|
+
local project = require("runtime_analysis.project")
|
|
6
|
+
|
|
7
|
+
local M = {}
|
|
8
|
+
|
|
9
|
+
local config = {
|
|
10
|
+
inlay_hints = true, -- show observed types beside parameters, assignments and signatures
|
|
11
|
+
code_lens = true, -- show how many examples reached each method, with a lens to record them again
|
|
12
|
+
value_popup = 500, -- milliseconds the cursor rests on a value before its popup shows. false for none.
|
|
13
|
+
hover_key = "K", -- shows the same on demand, and the method when not on a value. false to leave the key.
|
|
14
|
+
class_key = "gf", -- goes to the class under the cursor, or does what the key did before. false to leave the key.
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function M.setup(options)
|
|
18
|
+
config = vim.tbl_extend("force", config, options or {})
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
function M.attach(bufnr)
|
|
22
|
+
if vim.bo[bufnr].buftype ~= "" or vim.api.nvim_buf_get_name(bufnr) == "" then return end
|
|
23
|
+
local root = project.root(bufnr)
|
|
24
|
+
if not project.has_recording(root) then return end
|
|
25
|
+
vim.lsp.start({
|
|
26
|
+
name = "runtime_analysis",
|
|
27
|
+
cmd = vim.list_extend(project.ra(root), { "lsp" }),
|
|
28
|
+
cmd_cwd = root, -- the recording and the bundle are found from here, wherever Neovim was started
|
|
29
|
+
root_dir = root,
|
|
30
|
+
on_init = function(client) require("runtime_analysis.inline").enable(client) end,
|
|
31
|
+
on_attach = function(client, attached)
|
|
32
|
+
if config.inlay_hints then vim.lsp.inlay_hint.enable(true, { bufnr = attached }) end
|
|
33
|
+
if config.code_lens and client:supports_method("textDocument/codeLens") then
|
|
34
|
+
require("runtime_analysis.lens").enable(attached)
|
|
35
|
+
end
|
|
36
|
+
if config.value_popup then require("runtime_analysis.value_popup").enable(client, attached, config.value_popup) end
|
|
37
|
+
if config.class_key then require("runtime_analysis.go_to_class").enable(attached, config.class_key) end
|
|
38
|
+
if config.hover_key and vim.fn.maparg(config.hover_key, "n") == "" then
|
|
39
|
+
vim.keymap.set("n", config.hover_key, vim.lsp.buf.hover, { buffer = attached, desc = "What the recording knows" })
|
|
40
|
+
end
|
|
41
|
+
end,
|
|
42
|
+
}, { bufnr = bufnr })
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
-- Shows or hides the inline types in every buffer attached to the server, and in ones attached later.
|
|
46
|
+
function M.toggle_types()
|
|
47
|
+
config.inlay_hints = not config.inlay_hints
|
|
48
|
+
for _, client in ipairs(vim.lsp.get_clients({ name = "runtime_analysis" })) do
|
|
49
|
+
for bufnr in pairs(client.attached_buffers) do
|
|
50
|
+
vim.lsp.inlay_hint.enable(config.inlay_hints, { bufnr = bufnr })
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
vim.notify("ra: types " .. (config.inlay_hints and "shown" or "hidden"))
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
-- For buffers that were open before the plugin loaded.
|
|
57
|
+
function M.attach_open_buffers()
|
|
58
|
+
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
|
|
59
|
+
if vim.api.nvim_buf_is_loaded(bufnr) and vim.bo[bufnr].filetype == "ruby" then M.attach(bufnr) end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
local function related_places(diagnostic)
|
|
64
|
+
local lsp = diagnostic.user_data and diagnostic.user_data.lsp
|
|
65
|
+
return lsp and lsp.relatedInformation
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
local function trail_items(diagnostic, places)
|
|
69
|
+
local raised = vim.split(diagnostic.message, "\n")[1]
|
|
70
|
+
local items = { { bufnr = diagnostic.bufnr, lnum = diagnostic.lnum + 1, text = raised } }
|
|
71
|
+
for _, place in ipairs(places) do
|
|
72
|
+
local start = place.location.range.start
|
|
73
|
+
table.insert(items, { filename = vim.uri_to_fname(place.location.uri), lnum = start.line + 1, text = place.message })
|
|
74
|
+
end
|
|
75
|
+
return items
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
-- Puts the trail of the diagnostic on the cursor's line in the location list: the line that raised,
|
|
79
|
+
-- then each place the nil passed through, ending at the method it came from.
|
|
80
|
+
function M.trail()
|
|
81
|
+
local line = vim.api.nvim_win_get_cursor(0)[1] - 1
|
|
82
|
+
for _, diagnostic in ipairs(vim.diagnostic.get(0, { lnum = line })) do
|
|
83
|
+
local places = related_places(diagnostic)
|
|
84
|
+
if places then
|
|
85
|
+
vim.fn.setloclist(0, {}, " ", { title = "Nil trail", items = trail_items(diagnostic, places) })
|
|
86
|
+
return vim.cmd.lopen()
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
vim.notify("No recorded trail on this line", vim.log.levels.INFO)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
return M
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
-- Every tool in one menu: pick a tool, pick what to ask it about, read the answer. The picking is
|
|
2
|
+
-- vim.ui.select, so it is whatever picker the editor has: Telescope, fzf-lua, snacks, or the plain
|
|
3
|
+
-- numbered list.
|
|
4
|
+
|
|
5
|
+
local project = require("runtime_analysis.project")
|
|
6
|
+
|
|
7
|
+
local M = {}
|
|
8
|
+
|
|
9
|
+
local RECORDED = { methods = true, classes = true, namespaces = true }
|
|
10
|
+
local EVERYTHING = { name = "", note = "everything recorded" }
|
|
11
|
+
|
|
12
|
+
local function ra(root, args, done)
|
|
13
|
+
vim.system(vim.list_extend(project.ra(root), args), { cwd = root, text = true }, vim.schedule_wrap(done))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
local function tool_label(tool)
|
|
17
|
+
return string.format("%-24s %s%s", tool.name, tool.description, tool.pro and " (Pro)" or "")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
local function name_label(item)
|
|
21
|
+
return item.note ~= "" and (item.name .. " " .. item.note) or item.name
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
-- An answer is read in a window of its own, opened below. Paths in it are relative to the project,
|
|
25
|
+
-- so the window's directory is the project's and Enter on `file:line` goes there.
|
|
26
|
+
local function show(root, asked, result)
|
|
27
|
+
local wrap = require("runtime_analysis.text").wrap
|
|
28
|
+
local lines = vim.split(vim.trim(result.stdout or ""), "\n", { plain = true })
|
|
29
|
+
local said = vim.trim((result.stderr or ""):gsub("^ra: ", ""))
|
|
30
|
+
if said ~= "" then
|
|
31
|
+
if lines[1] ~= "" then table.insert(lines, "") end
|
|
32
|
+
vim.list_extend(lines, wrap(said, math.max(vim.o.columns - 4, 20)))
|
|
33
|
+
end
|
|
34
|
+
vim.cmd("botright " .. math.min(math.max(#lines, 3), 18) .. "new")
|
|
35
|
+
vim.cmd("lcd " .. vim.fn.fnameescape(root))
|
|
36
|
+
local buf = vim.api.nvim_get_current_buf()
|
|
37
|
+
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
|
|
38
|
+
for option, value in pairs({ buftype = "nofile", bufhidden = "wipe", swapfile = false, modifiable = false,
|
|
39
|
+
filetype = "runtime_analysis" }) do
|
|
40
|
+
vim.bo[buf][option] = value
|
|
41
|
+
end
|
|
42
|
+
pcall(vim.api.nvim_buf_set_name, buf, "ra " .. asked)
|
|
43
|
+
vim.keymap.set("n", "q", "<cmd>close<cr>", { buffer = buf, desc = "Close this answer" })
|
|
44
|
+
vim.keymap.set("n", "<cr>", "gF", { buffer = buf, desc = "Go to the file and line under the cursor" })
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
local function answer(root, tool, argument)
|
|
48
|
+
local args = { tool.name }
|
|
49
|
+
if argument and argument ~= "" then table.insert(args, argument) end
|
|
50
|
+
ra(root, args, function(result) show(root, table.concat(args, " "), result) end)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
-- A method, class or namespace is picked from the ones the recording holds.
|
|
54
|
+
local function pick_recorded(root, tool, done)
|
|
55
|
+
ra(root, { "completion", tool.argument.completes }, function(result)
|
|
56
|
+
local names = tool.argument.required and {} or { EVERYTHING }
|
|
57
|
+
for line in (result.stdout or ""):gmatch("[^\n]+") do
|
|
58
|
+
local name, note = line:match("^([^\t]*)\t?(.*)$")
|
|
59
|
+
table.insert(names, { name = name, note = note })
|
|
60
|
+
end
|
|
61
|
+
vim.ui.select(names, { prompt = tool.name .. ": " .. tool.argument.name, format_item = name_label },
|
|
62
|
+
function(choice) if choice then done(choice.name) end end)
|
|
63
|
+
end)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
-- A file or directory starts as the one being edited, and can be typed over. What only the person
|
|
67
|
+
-- can say starts empty.
|
|
68
|
+
local function type_path(root, tool, bufnr, done)
|
|
69
|
+
local file = vim.api.nvim_buf_get_name(bufnr)
|
|
70
|
+
local here = vim.startswith(file, root .. "/") and file:sub(#root + 2) or ""
|
|
71
|
+
if tool.argument.completes == "directories" then here = vim.fs.dirname(here) end
|
|
72
|
+
if tool.argument.completes == "" then here = "" end
|
|
73
|
+
vim.ui.input({ prompt = tool.name .. " " .. tool.argument.name .. ": ", default = here },
|
|
74
|
+
function(typed) if typed then done(typed) end end)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
local function ask(root, tool, bufnr)
|
|
78
|
+
local done = function(argument) answer(root, tool, argument) end
|
|
79
|
+
if not tool.argument or tool.argument == vim.NIL then return done(nil) end
|
|
80
|
+
if RECORDED[tool.argument.completes] then return pick_recorded(root, tool, done) end
|
|
81
|
+
type_path(root, tool, bufnr, done)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
function M.open()
|
|
85
|
+
local bufnr = vim.api.nvim_get_current_buf()
|
|
86
|
+
local root = project.root(bufnr)
|
|
87
|
+
ra(root, { "tools", "--json" }, function(result)
|
|
88
|
+
local ok, tools = pcall(vim.json.decode, result.stdout or "")
|
|
89
|
+
if not ok or type(tools) ~= "table" then
|
|
90
|
+
return vim.notify("ra: " .. vim.trim(result.stderr or "the tools could not be listed"), vim.log.levels.WARN)
|
|
91
|
+
end
|
|
92
|
+
vim.ui.select(tools, { prompt = "Ask the recording", format_item = tool_label }, function(tool)
|
|
93
|
+
if tool then ask(root, tool, bufnr) end
|
|
94
|
+
end)
|
|
95
|
+
end)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
return M
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
-- Shows a place in a window while the cursor stays somewhere else, the way a quickfix preview does.
|
|
2
|
+
-- The window can be put back as it was, or left on what it shows.
|
|
3
|
+
|
|
4
|
+
local M = {}
|
|
5
|
+
|
|
6
|
+
local NAMESPACE = vim.api.nvim_create_namespace("runtime_analysis_preview")
|
|
7
|
+
local session = nil
|
|
8
|
+
|
|
9
|
+
local function clear_mark()
|
|
10
|
+
if session and session.marked and vim.api.nvim_buf_is_valid(session.marked) then
|
|
11
|
+
vim.api.nvim_buf_clear_namespace(session.marked, NAMESPACE, 0, -1)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
-- Buffers that exist only because they were previewed are closed again, except one to keep.
|
|
16
|
+
local function drop_created(keep)
|
|
17
|
+
for buf in pairs(session.created) do
|
|
18
|
+
if buf ~= keep and vim.api.nvim_buf_is_valid(buf) then pcall(vim.api.nvim_buf_delete, buf, {}) end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
function M.active()
|
|
23
|
+
return session ~= nil
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
function M.start(window)
|
|
27
|
+
vim.api.nvim_set_hl(0, "RuntimeAnalysisFrame", { link = "Visual", default = true })
|
|
28
|
+
session = { win = window, buf = vim.api.nvim_win_get_buf(window), created = {},
|
|
29
|
+
view = vim.api.nvim_win_call(window, vim.fn.winsaveview) }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
function M.show(path, line)
|
|
33
|
+
if not (session and vim.api.nvim_win_is_valid(session.win)) then return end
|
|
34
|
+
local existed = vim.fn.bufexists(path) == 1
|
|
35
|
+
local buf = vim.fn.bufadd(path)
|
|
36
|
+
if not existed then session.created[buf] = true end
|
|
37
|
+
vim.fn.bufload(buf)
|
|
38
|
+
clear_mark()
|
|
39
|
+
vim.api.nvim_win_set_buf(session.win, buf)
|
|
40
|
+
local at = math.min(math.max(line or 1, 1), vim.api.nvim_buf_line_count(buf))
|
|
41
|
+
vim.api.nvim_win_set_cursor(session.win, { at, 0 })
|
|
42
|
+
vim.api.nvim_win_call(session.win, function() vim.cmd("normal! zz") end)
|
|
43
|
+
vim.api.nvim_buf_set_extmark(buf, NAMESPACE, at - 1, 0, { line_hl_group = "RuntimeAnalysisFrame" })
|
|
44
|
+
session.marked, session.shown = buf, buf
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
-- Puts the window back on the buffer and view it had when the preview started.
|
|
48
|
+
function M.cancel()
|
|
49
|
+
if not session then return end
|
|
50
|
+
clear_mark()
|
|
51
|
+
if vim.api.nvim_win_is_valid(session.win) and vim.api.nvim_buf_is_valid(session.buf) then
|
|
52
|
+
vim.api.nvim_win_set_buf(session.win, session.buf)
|
|
53
|
+
vim.api.nvim_win_call(session.win, function() vim.fn.winrestview(session.view) end)
|
|
54
|
+
end
|
|
55
|
+
drop_created(nil)
|
|
56
|
+
session = nil
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
-- Leaves the window on what it shows and returns it, for the caller to move the cursor there.
|
|
60
|
+
function M.accept()
|
|
61
|
+
if not session then return nil end
|
|
62
|
+
clear_mark()
|
|
63
|
+
if session.shown and vim.api.nvim_buf_is_valid(session.shown) then vim.bo[session.shown].buflisted = true end
|
|
64
|
+
drop_created(session.shown)
|
|
65
|
+
local window = session.win
|
|
66
|
+
session = nil
|
|
67
|
+
return window
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
return M
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
-- Where a buffer's project is and how to run `ra` in it.
|
|
2
|
+
|
|
3
|
+
local M = {}
|
|
4
|
+
|
|
5
|
+
-- The nearest directory above the file that holds a recording, else the project's Gemfile or .git.
|
|
6
|
+
function M.root(bufnr)
|
|
7
|
+
for dir in vim.fs.parents(vim.api.nvim_buf_get_name(bufnr)) do
|
|
8
|
+
if vim.uv.fs_stat(dir .. "/tmp/runtime_analysis") then return dir end
|
|
9
|
+
end
|
|
10
|
+
return vim.fs.root(bufnr, { "Gemfile", ".git" }) or vim.fn.getcwd()
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
function M.has_recording(root)
|
|
14
|
+
return vim.uv.fs_stat(root .. "/tmp/runtime_analysis") ~= nil
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
-- The start of a command line that runs `ra` in the project. Neovim starts it as a process, so a
|
|
18
|
+
-- shell function or alias called `ra` is not there. The `ra` binary on PATH comes first: it answers
|
|
19
|
+
-- every tool and hands recording to the gem. Without one, the project's own binstub. The gem ships
|
|
20
|
+
-- no `ra`, so the project's bundle is never asked for one.
|
|
21
|
+
function M.ra(root)
|
|
22
|
+
if vim.fn.executable("ra") == 1 then return { "ra" } end
|
|
23
|
+
local binstub = root .. "/bin/ra"
|
|
24
|
+
if vim.fn.executable(binstub) == 1 then return { binstub } end
|
|
25
|
+
return { "ra" }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
return M
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
-- Records again the examples that reached the current file, or a code lens's spec files, with `ra rerun`. The language server
|
|
2
|
+
-- notices the new run and refreshes the diagnostics, so a fixed crash goes and one put back returns.
|
|
3
|
+
|
|
4
|
+
local project = require("runtime_analysis.project")
|
|
5
|
+
|
|
6
|
+
local M = {}
|
|
7
|
+
|
|
8
|
+
-- The test runner's own summary when it printed one, otherwise the last thing ra said.
|
|
9
|
+
local function summary(result)
|
|
10
|
+
local lines = vim.split(vim.trim((result.stdout or "") .. "\n" .. (result.stderr or "")), "\n")
|
|
11
|
+
for index = #lines, 1, -1 do
|
|
12
|
+
if lines[index]:match("%d+ examples?, ") or lines[index]:match("%d+ runs, ") then return lines[index] end
|
|
13
|
+
end
|
|
14
|
+
return lines[#lines]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
function M.run(bufnr)
|
|
18
|
+
bufnr = bufnr or vim.api.nvim_get_current_buf()
|
|
19
|
+
local root = project.root(bufnr)
|
|
20
|
+
local file = vim.api.nvim_buf_get_name(bufnr):sub(#root + 2)
|
|
21
|
+
local unsaved = vim.bo[bufnr].modified and " (unsaved changes are not in the run)" or ""
|
|
22
|
+
M.files(root, { file }, "the examples that reach " .. file .. unsaved)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
-- Records again the examples that reach each file, one `ra rerun` after another.
|
|
26
|
+
function M.files(root, files, what)
|
|
27
|
+
vim.notify("ra: recording " .. what)
|
|
28
|
+
local function next(index)
|
|
29
|
+
if index > #files then return end
|
|
30
|
+
local command = vim.list_extend(project.ra(root), { "rerun", files[index] })
|
|
31
|
+
vim.system(command, { cwd = root, text = true }, vim.schedule_wrap(function(result)
|
|
32
|
+
vim.notify("ra: " .. summary(result), result.code == 0 and vim.log.levels.INFO or vim.log.levels.WARN)
|
|
33
|
+
next(index + 1)
|
|
34
|
+
end))
|
|
35
|
+
end
|
|
36
|
+
next(1)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
return M
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
-- Text for a window that does not wrap its lines.
|
|
2
|
+
|
|
3
|
+
local M = {}
|
|
4
|
+
|
|
5
|
+
-- The text as lines no wider than `width`, broken between words. A word wider than that keeps a line
|
|
6
|
+
-- to itself, so a link stays in one piece.
|
|
7
|
+
function M.wrap(text, width)
|
|
8
|
+
local lines, line = {}, ""
|
|
9
|
+
for word in text:gmatch("%S+") do
|
|
10
|
+
if line == "" then
|
|
11
|
+
line = word
|
|
12
|
+
elseif vim.fn.strdisplaywidth(line .. " " .. word) <= width then
|
|
13
|
+
line = line .. " " .. word
|
|
14
|
+
else
|
|
15
|
+
table.insert(lines, line)
|
|
16
|
+
line = word
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
if line ~= "" then table.insert(lines, line) end
|
|
20
|
+
return lines
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
return M
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
-- Shows what is known about the value under the cursor once the cursor has rested on it: its
|
|
2
|
+
-- classes and the messages it was later sent. It asks the language server's hover and shows the
|
|
3
|
+
-- answer only when it is about the text under the cursor, so resting anywhere else shows nothing.
|
|
4
|
+
|
|
5
|
+
local M = {}
|
|
6
|
+
|
|
7
|
+
local GROUP = vim.api.nvim_create_augroup("runtime_analysis_value_popup", { clear = true })
|
|
8
|
+
local timer = nil
|
|
9
|
+
|
|
10
|
+
local function covers(range, line, character)
|
|
11
|
+
return range and range.start.line == line and range.start.character <= character
|
|
12
|
+
and character < range["end"].character
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
local function position_now(client)
|
|
16
|
+
return vim.lsp.util.make_position_params(0, client.offset_encoding)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
-- The answer is dropped when the cursor has moved on since it was asked for.
|
|
20
|
+
local function show(client, bufnr, asked, result)
|
|
21
|
+
if vim.api.nvim_get_current_buf() ~= bufnr or not vim.deep_equal(position_now(client).position, asked) then return end
|
|
22
|
+
if not (result and covers(result.range, asked.line, asked.character)) then return end
|
|
23
|
+
vim.lsp.util.open_floating_preview(vim.split(result.contents.value, "\n"), "markdown", {
|
|
24
|
+
border = "rounded", focusable = false, close_events = { "CursorMoved", "InsertEnter", "BufLeave" },
|
|
25
|
+
})
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
local function ask(client, bufnr)
|
|
29
|
+
if vim.api.nvim_get_mode().mode ~= "n" or vim.api.nvim_get_current_buf() ~= bufnr then return end
|
|
30
|
+
local params = position_now(client)
|
|
31
|
+
client:request("textDocument/hover", params, function(_, result)
|
|
32
|
+
show(client, bufnr, params.position, result)
|
|
33
|
+
end, bufnr)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
-- `delay` is how long the cursor must rest, in milliseconds.
|
|
37
|
+
function M.enable(client, bufnr, delay)
|
|
38
|
+
vim.api.nvim_clear_autocmds({ group = GROUP, buffer = bufnr })
|
|
39
|
+
vim.api.nvim_create_autocmd("CursorMoved", { group = GROUP, buffer = bufnr, callback = function()
|
|
40
|
+
if timer then timer:stop() end
|
|
41
|
+
timer = vim.defer_fn(function() ask(client, bufnr) end, delay)
|
|
42
|
+
end })
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
return M
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
-- Commands for Runtime Analysis. Each module is loaded on first use.
|
|
2
|
+
vim.api.nvim_create_user_command("Ra", function()
|
|
3
|
+
require("runtime_analysis.menu").open()
|
|
4
|
+
end, { desc = "Pick a tool to ask the recording, from all of them" })
|
|
5
|
+
|
|
6
|
+
vim.keymap.set("n", "<Plug>(Ra)", function()
|
|
7
|
+
require("runtime_analysis.menu").open()
|
|
8
|
+
end, { desc = "Pick a tool to ask the recording" })
|
|
9
|
+
|
|
10
|
+
vim.api.nvim_create_user_command("RaConnected", function()
|
|
11
|
+
require("runtime_analysis.connected").toggle()
|
|
12
|
+
end, { desc = "Toggle the list of files connected to this one by recorded calls" })
|
|
13
|
+
|
|
14
|
+
vim.api.nvim_create_user_command("RaConnectedDepth", function(opts)
|
|
15
|
+
require("runtime_analysis.connected").set_depth(opts.args)
|
|
16
|
+
end, { nargs = 1, desc = "How many hops the connected-files list follows: a number, or all" })
|
|
17
|
+
|
|
18
|
+
vim.api.nvim_create_user_command("RaNilTrail", function()
|
|
19
|
+
require("runtime_analysis.lsp").trail()
|
|
20
|
+
end, { desc = "List the trail a nil took to the crash on this line" })
|
|
21
|
+
|
|
22
|
+
vim.api.nvim_create_user_command("RaRerun", function()
|
|
23
|
+
require("runtime_analysis.rerun").run()
|
|
24
|
+
end, { desc = "Record again the examples that reach this file" })
|
|
25
|
+
|
|
26
|
+
vim.keymap.set("n", "<Plug>(RaRerun)", function()
|
|
27
|
+
require("runtime_analysis.rerun").run()
|
|
28
|
+
end, { desc = "Record again the examples that reach this file" })
|
|
29
|
+
|
|
30
|
+
vim.api.nvim_create_user_command("RaTypes", function()
|
|
31
|
+
require("runtime_analysis.lsp").toggle_types()
|
|
32
|
+
end, { desc = "Show or hide the inline types" })
|
|
33
|
+
|
|
34
|
+
vim.keymap.set("n", "<Plug>(RaTypes)", function()
|
|
35
|
+
require("runtime_analysis.lsp").toggle_types()
|
|
36
|
+
end, { desc = "Show or hide the inline types" })
|
|
37
|
+
|
|
38
|
+
-- <leader>ra opens the menu of every tool, <leader>rc toggles the sidebar, <leader>rr records again
|
|
39
|
+
-- and <leader>rt shows or hides the inline types, unless the key is taken or mappings are turned off
|
|
40
|
+
-- with vim.g.runtime_analysis_no_mappings. Map <Plug>(Ra), <Plug>(RaConnected), <Plug>(RaRerun) and
|
|
41
|
+
-- <Plug>(RaTypes) to use other keys.
|
|
42
|
+
if not vim.g.runtime_analysis_no_mappings and vim.fn.maparg("<leader>ra", "n") == "" then
|
|
43
|
+
vim.keymap.set("n", "<leader>ra", "<Plug>(Ra)", { desc = "Pick a tool to ask the recording" })
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
vim.keymap.set("n", "<Plug>(RaConnected)", function()
|
|
47
|
+
require("runtime_analysis.connected").toggle()
|
|
48
|
+
end, { desc = "Toggle files connected by recorded calls" })
|
|
49
|
+
|
|
50
|
+
if not vim.g.runtime_analysis_no_mappings and vim.fn.maparg("<leader>rc", "n") == "" then
|
|
51
|
+
vim.keymap.set("n", "<leader>rc", "<Plug>(RaConnected)", { desc = "Toggle files connected by recorded calls" })
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
if not vim.g.runtime_analysis_no_mappings and vim.fn.maparg("<leader>rr", "n") == "" then
|
|
55
|
+
vim.keymap.set("n", "<leader>rr", "<Plug>(RaRerun)", { desc = "Record again the examples that reach this file" })
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
if not vim.g.runtime_analysis_no_mappings and vim.fn.maparg("<leader>rt", "n") == "" then
|
|
59
|
+
vim.keymap.set("n", "<leader>rt", "<Plug>(RaTypes)", { desc = "Show or hide the inline types" })
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
-- Ruby buffers in a project with a recording are attached to `ra lsp`. Set
|
|
63
|
+
-- vim.g.runtime_analysis_no_lsp to keep the sidebar and leave the language server off.
|
|
64
|
+
if not vim.g.runtime_analysis_no_lsp then
|
|
65
|
+
vim.api.nvim_create_autocmd("FileType", {
|
|
66
|
+
group = vim.api.nvim_create_augroup("runtime_analysis_lsp", { clear = true }),
|
|
67
|
+
pattern = "ruby",
|
|
68
|
+
callback = function(event) require("runtime_analysis.lsp").attach(event.buf) end,
|
|
69
|
+
})
|
|
70
|
+
require("runtime_analysis.lsp").attach_open_buffers()
|
|
71
|
+
end
|