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,96 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# no-unit-test: asserted through ../sorbet_spec.rb, which reads each kind of Sorbet type as a class name.
|
|
4
|
+
|
|
5
|
+
require "runtime_analysis/ruby_parsing"
|
|
6
|
+
require "runtime_analysis/query/nodes"
|
|
7
|
+
require "runtime_analysis/query/index/signatures/written"
|
|
8
|
+
|
|
9
|
+
module RuntimeAnalysis
|
|
10
|
+
module Query
|
|
11
|
+
module Index
|
|
12
|
+
class Signatures
|
|
13
|
+
module Sorbet
|
|
14
|
+
class Types
|
|
15
|
+
HOLDERS = { "T::Array" => "Array", "T::Hash" => "Hash", "T::Set" => "Set", "T::Range" => "Range",
|
|
16
|
+
"T::Enumerable" => "Enumerable", "T::Enumerator" => "Enumerator" }.freeze
|
|
17
|
+
NAMED = { "T::Boolean" => "bool", "T::Class" => "Class" }.freeze
|
|
18
|
+
LITERALS = RubyParsing.by_kind(array_node: ["Array"], hash_node: ["Hash"])
|
|
19
|
+
WRAPPERS = { nilable: :nilable, class_of: :a_class }.freeze
|
|
20
|
+
FIXED = { self_type: ["self"], attached_class: ["self"], proc: ["Proc"] }.freeze
|
|
21
|
+
|
|
22
|
+
def initialize(nesting)
|
|
23
|
+
@nesting = nesting
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def read(node)
|
|
27
|
+
return constant(node) if RubyParsing.constant?(node)
|
|
28
|
+
|
|
29
|
+
RubyParsing.call?(node) ? call(node) : LITERALS[RubyParsing.kind(node)]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def constant(node)
|
|
33
|
+
name = name_of(node)
|
|
34
|
+
name && [NAMED[name.delete_prefix("::")] || Written.within(name, @nesting)]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def name_of(node)
|
|
40
|
+
RubyParsing.full_name(node)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def call(node)
|
|
44
|
+
return on_t(node) if t?(node.receiver)
|
|
45
|
+
return holder(node) if node.name == :[]
|
|
46
|
+
|
|
47
|
+
["Proc"] if a_proc?(node)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def t?(node)
|
|
51
|
+
RubyParsing.constant?(node) && node.name == :T
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def on_t(node)
|
|
55
|
+
return union(arguments(node)) if node.name == :any
|
|
56
|
+
|
|
57
|
+
reader = WRAPPERS[node.name]
|
|
58
|
+
reader ? __send__(reader, arguments(node).first) : FIXED[node.name]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def arguments(node)
|
|
62
|
+
Array(node.arguments&.arguments)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def a_class(argument)
|
|
66
|
+
itself = read(argument)
|
|
67
|
+
[itself ? ["Class", itself] : "Class"]
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def nilable(argument)
|
|
71
|
+
read(argument)&.+(["nil"])
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def union(arguments)
|
|
75
|
+
types = arguments.map { |argument| read(argument) }
|
|
76
|
+
types.flatten(1).uniq unless types.any?(&:nil?)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def holder(node)
|
|
80
|
+
held = HOLDERS[name_of(node.receiver).to_s.delete_prefix("::")]
|
|
81
|
+
return constant(node.receiver) unless held
|
|
82
|
+
|
|
83
|
+
[[held, *arguments(node).map { |argument| read(argument) }]]
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def a_proc?(node)
|
|
87
|
+
return node.name == :proc if t?(node.receiver)
|
|
88
|
+
|
|
89
|
+
RubyParsing.call?(node.receiver) && a_proc?(node.receiver)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "runtime_analysis/ruby_parsing"
|
|
4
|
+
require "runtime_analysis/query/nodes"
|
|
5
|
+
require_relative "written"
|
|
6
|
+
require_relative "sorbet/sig"
|
|
7
|
+
require_relative "sorbet/signed"
|
|
8
|
+
require_relative "sorbet/table"
|
|
9
|
+
require_relative "sorbet/types"
|
|
10
|
+
|
|
11
|
+
module RuntimeAnalysis
|
|
12
|
+
module Query
|
|
13
|
+
module Index
|
|
14
|
+
class Signatures
|
|
15
|
+
module Sorbet
|
|
16
|
+
def self.read(text)
|
|
17
|
+
Visitor.new.tap { |visitor| RubyParsing.tree_of(text).accept(visitor) }.classes
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.sig?(node) = Sig.written?(node)
|
|
21
|
+
|
|
22
|
+
class Visitor < RubyParsing.visitor
|
|
23
|
+
MIXINS = { include: "ancestors", prepend: "ancestors", extend: "extends" }.freeze
|
|
24
|
+
HANDLERS = { include: :mix, prepend: :mix, extend: :mix, attr_reader: :attributes,
|
|
25
|
+
attr_accessor: :attributes, const: :field, prop: :field }.freeze
|
|
26
|
+
TOP = { klass: nil, singleton: false }.freeze
|
|
27
|
+
READER = [0, 0, 0, nil].freeze
|
|
28
|
+
|
|
29
|
+
def initialize
|
|
30
|
+
super()
|
|
31
|
+
@table = Table.new
|
|
32
|
+
@scopes = []
|
|
33
|
+
@types = {}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def classes
|
|
37
|
+
@table.classes
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def visit_class_node(node)
|
|
41
|
+
parent = types.read(node.superclass)&.first
|
|
42
|
+
within(node) do |entry|
|
|
43
|
+
entry["superclass"] = parent if parent.instance_of?(String)
|
|
44
|
+
super
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def visit_module_node(node)
|
|
49
|
+
within(node) { super }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def visit_singleton_class_node(node)
|
|
53
|
+
push(klass, singleton: true) { super } if RubyParsing.self?(node.expression)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def visit_call_node(node)
|
|
57
|
+
handler = handler_of(node)
|
|
58
|
+
handler ? __send__(handler, node) : super
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def visit_def_node(node)
|
|
62
|
+
sig = taken
|
|
63
|
+
Signed.new(node, sig, types).into(@table, klass, class_method?(node)) if sig && own?(node)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
def handler_of(node)
|
|
69
|
+
return :sign if Sig.written?(node)
|
|
70
|
+
|
|
71
|
+
HANDLERS[node.name] if node.receiver.nil?
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def own?(node)
|
|
75
|
+
node.receiver.nil? || RubyParsing.self?(node.receiver)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def class_method?(node)
|
|
79
|
+
node.receiver ? true : scope.fetch(:singleton)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def sign(node)
|
|
83
|
+
@pending = Sig.new(node)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def within(node)
|
|
87
|
+
name = qualified(node)
|
|
88
|
+
push(name, singleton: false) { yield @table.entry(name) } if name
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def push(klass, singleton:)
|
|
92
|
+
@scopes << { klass: klass, singleton: singleton }
|
|
93
|
+
@pending = nil
|
|
94
|
+
yield
|
|
95
|
+
@scopes.pop
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def qualified(node)
|
|
99
|
+
path = RubyParsing.full_name(node.constant_path) or return nil
|
|
100
|
+
klass && !path.start_with?("::") ? "#{klass}::#{path}" : path.delete_prefix("::")
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def scope
|
|
104
|
+
@scopes.last || TOP
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def klass
|
|
108
|
+
scope.fetch(:klass)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def types
|
|
112
|
+
@types[klass] ||= Types.new(klass)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def taken
|
|
116
|
+
@pending.tap { @pending = nil }
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def mix(node)
|
|
120
|
+
@table.mixed(klass, scope.fetch(:singleton) ? "extends" : MIXINS.fetch(node.name), constants(node))
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def constants(node)
|
|
124
|
+
arguments(node).map { |each| types.read(each)&.first }.grep(String)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def attributes(node)
|
|
128
|
+
type = types.read(taken&.result)
|
|
129
|
+
arguments(node).each { |name| reader(name, type) if RubyParsing.symbol?(name) } if type
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def field(node)
|
|
133
|
+
name, written = arguments(node)
|
|
134
|
+
type = types.read(written)
|
|
135
|
+
reader(name, type) if type && RubyParsing.symbol?(name)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def reader(name, type)
|
|
139
|
+
@table.returns(klass, name.unescaped, [*READER, type], scope.fetch(:singleton))
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def arguments(node)
|
|
143
|
+
Array(node.arguments&.arguments)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "rbs"
|
|
4
|
+
require_relative "sorbet"
|
|
5
|
+
require_relative "written"
|
|
6
|
+
|
|
7
|
+
module RuntimeAnalysis
|
|
8
|
+
module Query
|
|
9
|
+
module Index
|
|
10
|
+
class Signatures
|
|
11
|
+
class Sources
|
|
12
|
+
CODE = %w[app lib].freeze
|
|
13
|
+
RBI = %w[sorbet/rbi rbi].freeze
|
|
14
|
+
SPEC = /_(spec|test)\.rb\z/
|
|
15
|
+
|
|
16
|
+
def initialize(root, code: CODE, core: Signatures.core)
|
|
17
|
+
@root = root
|
|
18
|
+
@code = code
|
|
19
|
+
@core = core
|
|
20
|
+
@read = {}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def signatures
|
|
24
|
+
@signatures ||= @core.with(table)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def declarations
|
|
28
|
+
@declarations ||= Signatures.new(table, {})
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def reread
|
|
32
|
+
@signatures = @declarations = @table = nil
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def table
|
|
38
|
+
@table ||= settled(Layers.merged(rbs, gathered))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def rbs
|
|
42
|
+
stamp = Rbs.stamp(@root)
|
|
43
|
+
@rbs = [stamp, Rbs.read(@root)] unless @rbs&.first == stamp
|
|
44
|
+
@rbs.last
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def gathered
|
|
48
|
+
@read = files.to_h { |file| [file, current(file)] }
|
|
49
|
+
@read.each_value.with_object({}) { |(_, classes), all| add(all, classes) }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def settled(table)
|
|
53
|
+
Written.resolved(table, @core.names | table.keys)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def files
|
|
57
|
+
ruby = @code.flat_map { |dir| Dir.glob(File.join(@root, dir, "**", "*.rb")) }.grep_v(SPEC)
|
|
58
|
+
ruby + RBI.flat_map { |dir| Dir.glob(File.join(@root, dir, "**", "*.rbi")) }
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def current(file)
|
|
62
|
+
stamp = [File.size(file), File.mtime(file)]
|
|
63
|
+
kept = @read[file]
|
|
64
|
+
kept&.first == stamp ? kept : [stamp, read(file)]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def read(file)
|
|
68
|
+
Sorbet.read(File.read(file))
|
|
69
|
+
rescue StandardError
|
|
70
|
+
{}
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def add(all, classes)
|
|
74
|
+
all.merge!(classes) { |_, declared, entry| Layers.entry(declared, entry) }
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuntimeAnalysis
|
|
4
|
+
module Query
|
|
5
|
+
module Index
|
|
6
|
+
class Signatures
|
|
7
|
+
module Written
|
|
8
|
+
SEPARATOR = "|"
|
|
9
|
+
|
|
10
|
+
module_function
|
|
11
|
+
|
|
12
|
+
def within(name, nesting)
|
|
13
|
+
return name.delete_prefix("::") if nesting.nil? || name.start_with?("::")
|
|
14
|
+
|
|
15
|
+
"#{nesting}#{SEPARATOR}#{name}"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def resolved(value, known)
|
|
19
|
+
case value
|
|
20
|
+
when Hash then value.transform_values { |each| resolved(each, known) }
|
|
21
|
+
when Array then value.map { |each| resolved(each, known) }
|
|
22
|
+
else settled(value, known)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def settled(value, known)
|
|
27
|
+
value.instance_of?(String) && value.include?(SEPARATOR) ? found(value, known) : value
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def found(written, known)
|
|
31
|
+
nesting, name = written.split(SEPARATOR)
|
|
32
|
+
looked_up(nesting.split("::"), name, known)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def looked_up(parts, name, known)
|
|
36
|
+
return name if parts.empty?
|
|
37
|
+
|
|
38
|
+
candidate = "#{parts.join("::")}::#{name}"
|
|
39
|
+
known.include?(candidate) ? candidate : looked_up(parts[...-1], name, known)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require_relative "signatures/active_support"
|
|
5
|
+
require_relative "signatures/layers"
|
|
6
|
+
require_relative "signatures/lineage"
|
|
7
|
+
require_relative "signatures/overloads"
|
|
8
|
+
require_relative "signatures/sorbet"
|
|
9
|
+
|
|
10
|
+
module RuntimeAnalysis
|
|
11
|
+
module Query
|
|
12
|
+
module Index
|
|
13
|
+
class Signatures
|
|
14
|
+
FILE = File.expand_path("signatures/core.json", __dir__)
|
|
15
|
+
RECORDED_AS = { "nil" => "NilClass" }.freeze
|
|
16
|
+
|
|
17
|
+
def self.declared_in(root, **) = Sources.new(root, **)
|
|
18
|
+
|
|
19
|
+
def self.sig?(node) = Sorbet.sig?(node)
|
|
20
|
+
|
|
21
|
+
def self.core
|
|
22
|
+
@core ||= new(JSON.parse(File.read(FILE)).fetch("classes"))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def initialize(classes, additions = ActiveSupport.returns)
|
|
26
|
+
@classes = classes
|
|
27
|
+
@additions = additions
|
|
28
|
+
@lineage = Lineage.new(classes)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def names
|
|
32
|
+
@classes.keys
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def settled(constant, within:) = Written.settled(Written.within(constant, within), self)
|
|
36
|
+
|
|
37
|
+
def include?(name)
|
|
38
|
+
@classes.key?(name)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def with(classes)
|
|
42
|
+
self.class.new(Layers.merged(@classes, classes), @additions)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def returns(klass, name, **call)
|
|
46
|
+
found = @lineage.of(klass).filter_map { |owner| declared(owner, name, call) }.first
|
|
47
|
+
found && named(found, klass)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def class_returns(klass, name, **call)
|
|
51
|
+
overloads = @lineage.of_class(klass).filter_map { |owner, part| @classes.dig(owner, part, name) }.first
|
|
52
|
+
overloads && named(Overloads.chosen(overloads, **call), klass)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def parameters(klass, name, class_method: false)
|
|
56
|
+
places = @lineage.of_parameters(klass, class_method)
|
|
57
|
+
found = places.filter_map { |owner, part| @classes.dig(owner, part, name) }.first
|
|
58
|
+
found && taking(found, klass)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
def declared(owner, name, call)
|
|
64
|
+
overloads = @classes.dig(owner, "methods", name)
|
|
65
|
+
overloads ? Overloads.chosen(overloads, **call) : @additions.dig(owner, name)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def taking(parameters, klass)
|
|
69
|
+
{ "positional" => parameters.fetch("positional").map { |type| known(type, klass) },
|
|
70
|
+
"keywords" => parameters.fetch("keywords").transform_values { |type| known(type, klass) } }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def named(type, klass)
|
|
74
|
+
type.map { |each| each.instance_of?(Array) ? holding(each, klass) : plain(each, klass) }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def holding((name, *held), klass)
|
|
78
|
+
[name, *held.map { |type| known(type, klass) }]
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def known(type, klass)
|
|
82
|
+
type && named(type, klass)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def plain(name, klass)
|
|
86
|
+
name == "self" ? klass : RECORDED_AS.fetch(name, name)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
require_relative "signatures/sources"
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "forwardable"
|
|
4
|
+
require_relative "graph"
|
|
5
|
+
require_relative "static"
|
|
6
|
+
require_relative "signatures"
|
|
7
|
+
|
|
8
|
+
module RuntimeAnalysis
|
|
9
|
+
module Query
|
|
10
|
+
module Index
|
|
11
|
+
class SourceNamedGraph
|
|
12
|
+
extend Forwardable
|
|
13
|
+
include Graph.neighbours
|
|
14
|
+
|
|
15
|
+
DECLARABLE = /\A[A-Z]/
|
|
16
|
+
|
|
17
|
+
def_delegators :@graph, :recording, :trees, :methods, :edges, :spec_trees, :run_trees
|
|
18
|
+
|
|
19
|
+
def self.over(graph, project)
|
|
20
|
+
graph.instance_of?(self) ? graph : new(graph, project)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def initialize(graph, project, static: nil, declared: nil)
|
|
24
|
+
@graph = graph
|
|
25
|
+
@project = project
|
|
26
|
+
@static = static
|
|
27
|
+
@declared = declared
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def signatures
|
|
31
|
+
declared.signatures
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def declarations
|
|
35
|
+
declared.declarations
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def static
|
|
39
|
+
@static ||= Static.new(@project)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def method(identity)
|
|
43
|
+
@graph.method(identity) || declared_method(identity)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def nodes_of(identity)
|
|
47
|
+
recorded(identity).flat_map { |name| @graph.nodes_of(name) }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def declared
|
|
53
|
+
@declared ||= Signatures.declared_in(@project.root, code: static.code_dirs)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def recorded(identity)
|
|
57
|
+
declared = declaration(identity)
|
|
58
|
+
[identity, *(recorded_as(declared).map(&:identity) if declared)].uniq
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def declaration(identity)
|
|
62
|
+
static.method(identity) if DECLARABLE.match?(identity)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def declared_method(identity)
|
|
66
|
+
declared = declaration(identity)
|
|
67
|
+
found = declared && recorded_as(declared).first
|
|
68
|
+
return nil unless found
|
|
69
|
+
|
|
70
|
+
Graph.method_entry(identity: identity, klass: declared.klass, name: declared.name,
|
|
71
|
+
class_method: declared.class_method, file: found.file, line: found.line)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def recorded_as(declared)
|
|
75
|
+
recorded_at.fetch([declared.file, declared.line], []).select { |method| method.name == declared.name }
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def recorded_at
|
|
79
|
+
@recorded_at ||= methods.group_by { |method| [@project.relative(method.file), method.line] }
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# no-unit-test: asserted through ../static_spec.rb, through #changed_methods.
|
|
4
|
+
|
|
5
|
+
module RuntimeAnalysis
|
|
6
|
+
module Query
|
|
7
|
+
module Index
|
|
8
|
+
class Static
|
|
9
|
+
class ChangeSet
|
|
10
|
+
attr_reader :methods, :spec_files
|
|
11
|
+
|
|
12
|
+
def initialize(methods:, spec_files:)
|
|
13
|
+
@methods = methods
|
|
14
|
+
@spec_files = spec_files
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# no-unit-test: asserted through ../static_spec.rb, whose Changes and #changed_methods examples drive it.
|
|
4
|
+
|
|
5
|
+
require "open3"
|
|
6
|
+
require_relative "change_set"
|
|
7
|
+
require "runtime_analysis/platform"
|
|
8
|
+
|
|
9
|
+
module RuntimeAnalysis
|
|
10
|
+
module Query
|
|
11
|
+
module Index
|
|
12
|
+
class Static
|
|
13
|
+
module Changes
|
|
14
|
+
HUNK = /\A@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/
|
|
15
|
+
FILE = /\A\+\+\+ (.+)\z/
|
|
16
|
+
GIT_DIFF = %w[git diff -U0 --no-prefix --relative].freeze
|
|
17
|
+
ADVICE = "--since needs git, and a repository that has the ref. A shallow clone may not have it: " \
|
|
18
|
+
"fetch the full history (on GitHub Actions, fetch-depth: 0 for actions/checkout)."
|
|
19
|
+
|
|
20
|
+
class Unreadable < ArgumentError
|
|
21
|
+
def initialize(ref, reason)
|
|
22
|
+
super("git could not diff against #{ref}: #{reason}\n#{ADVICE}")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
module_function
|
|
27
|
+
|
|
28
|
+
def since(ref, root:, methods:, spec_dirs:)
|
|
29
|
+
hunks = parse(diff(ref, root))
|
|
30
|
+
ChangeSet.new(methods: touched(hunks, methods), spec_files: spec_files(hunks, spec_dirs))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def diff(ref, root)
|
|
34
|
+
out, said, status = Open3.capture3(*GIT_DIFF, ref, "--", chdir: root)
|
|
35
|
+
return out.lines(chomp: true) if status.success?
|
|
36
|
+
|
|
37
|
+
raise Unreadable.new(ref, "#{first_line_before_gits_usage(said)} (exit status #{status.exitstatus})")
|
|
38
|
+
rescue SystemCallError => e
|
|
39
|
+
raise Unreadable.new(ref, e)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def first_line_before_gits_usage(said)
|
|
43
|
+
said[/.+/]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def parse(lines)
|
|
47
|
+
file = nil
|
|
48
|
+
lines.filter_map do |line|
|
|
49
|
+
file = Regexp.last_match(1) if line.match(FILE)
|
|
50
|
+
hunk(file, line)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def hunk(file, line)
|
|
55
|
+
match = HUNK.match(line) or return
|
|
56
|
+
start = Integer(match[1])
|
|
57
|
+
[file, start, start + at_least_one_line(match[2]) - 1]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def at_least_one_line(count)
|
|
61
|
+
[count.to_i, 1].max
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def touched(hunks, methods)
|
|
65
|
+
methods.select { |method| hunks.any? { |file, from, to| method.file == file && method.covers?(from, to) } }
|
|
66
|
+
.map(&:identity).uniq
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def spec_files(hunks, spec_dirs)
|
|
70
|
+
hunks.map(&:first).uniq.select { |file| spec?(file, spec_dirs) }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def spec?(file, spec_dirs)
|
|
74
|
+
SPEC_FILE.match?(file) || spec_dirs.any? { |dir| file.start_with?("#{dir}/") }
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|