rbs-trace 0.3.2 → 0.4.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 +4 -4
- data/.rubocop.yml +11 -1
- data/CHANGELOG.md +26 -0
- data/README.md +44 -24
- data/Rakefile +7 -0
- data/exe/rbs-trace +8 -0
- data/lib/rbs/trace/builder.rb +124 -0
- data/lib/rbs/trace/cli/inline.rb +62 -0
- data/lib/rbs/trace/cli/merge.rb +102 -0
- data/lib/rbs/trace/cli.rb +40 -0
- data/lib/rbs/trace/file.rb +66 -21
- data/lib/rbs/trace/helpers.rb +75 -0
- data/lib/rbs/trace/inline_comment_visitor.rb +63 -0
- data/lib/rbs/trace/overload_compact.rb +85 -0
- data/lib/rbs/trace/return_value_visitor.rb +63 -0
- data/lib/rbs/trace/version.rb +2 -2
- data/lib/rbs/trace.rb +153 -4
- data/rbs_collection.lock.yaml +0 -4
- data/sig/generated/rbs/trace/builder.rbs +33 -0
- data/sig/generated/rbs/trace/cli/inline.rbs +19 -0
- data/sig/generated/rbs/trace/cli/merge.rbs +24 -0
- data/sig/generated/rbs/trace/cli.rbs +17 -0
- data/sig/generated/rbs/trace/file.rbs +20 -9
- data/sig/generated/rbs/trace/helpers.rbs +33 -0
- data/sig/generated/rbs/trace/inline_comment_visitor.rbs +27 -0
- data/sig/generated/rbs/trace/overload_compact.rbs +21 -0
- data/sig/generated/rbs/trace/return_value_visitor.rbs +27 -0
- data/sig/generated/rbs/trace/version.rbs +1 -1
- data/sig/generated/rbs/trace.rbs +63 -1
- data/tmp/.keep +0 -0
- metadata +38 -11
- data/lib/rbs/trace/declaration.rb +0 -107
- data/lib/rbs/trace/definition.rb +0 -33
- data/lib/rbs/trace/method_tracing.rb +0 -182
- data/sig/generated/rbs/trace/declaration.rbs +0 -36
- data/sig/generated/rbs/trace/definition.rbs +0 -25
- data/sig/generated/rbs/trace/method_tracing.rbs +0 -63
@@ -0,0 +1,21 @@
|
|
1
|
+
# Generated from lib/rbs/trace/overload_compact.rb with RBS::Inline
|
2
|
+
|
3
|
+
module RBS
|
4
|
+
class Trace
|
5
|
+
class OverloadCompact
|
6
|
+
# @rbs (Array[AST::Members::MethodDefinition::Overload]) -> void
|
7
|
+
def initialize: (Array[AST::Members::MethodDefinition::Overload]) -> void
|
8
|
+
|
9
|
+
# @rbs () -> Array[AST::Members::MethodDefinition::Overload]
|
10
|
+
def call: () -> Array[AST::Members::MethodDefinition::Overload]
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
# @rbs (Array[MethodType]) -> MethodType
|
15
|
+
def merge_method_types: (Array[MethodType]) -> MethodType
|
16
|
+
|
17
|
+
# @rbs (Array[Types::t]) -> Types::t
|
18
|
+
def merge_types: (Array[Types::t]) -> Types::t
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Generated from lib/rbs/trace/return_value_visitor.rb with RBS::Inline
|
2
|
+
|
3
|
+
module RBS
|
4
|
+
class Trace
|
5
|
+
class ReturnValueVisitor < Prism::BasicVisitor
|
6
|
+
# @rbs (String) -> ReturnValueVisitor
|
7
|
+
def self.parse_file: (String) -> ReturnValueVisitor
|
8
|
+
|
9
|
+
# @rbs () -> void
|
10
|
+
def initialize: () -> void
|
11
|
+
|
12
|
+
# @rbs (Integer, Symbol) -> bool
|
13
|
+
def void_type?: (Integer, Symbol) -> bool
|
14
|
+
|
15
|
+
# @rbs (Prism::Node) -> void
|
16
|
+
def visit_child_nodes: (Prism::Node) -> void
|
17
|
+
|
18
|
+
# @rbs (Prism::CallNode) -> void
|
19
|
+
def visit_call_node: (Prism::CallNode) -> void
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
# @rbs (Prism::CallNode) -> bool
|
24
|
+
def use_return_value?: (Prism::CallNode) -> bool
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/sig/generated/rbs/trace.rbs
CHANGED
@@ -1,8 +1,70 @@
|
|
1
1
|
# Generated from lib/rbs/trace.rb with RBS::Inline
|
2
2
|
|
3
3
|
module RBS
|
4
|
-
|
4
|
+
class Trace
|
5
5
|
class Error < StandardError
|
6
6
|
end
|
7
|
+
|
8
|
+
# steep:ignore:start
|
9
|
+
BUNDLE_PATH: String
|
10
|
+
|
11
|
+
# steep:ignore:end
|
12
|
+
RUBY_LIB_PATH: String
|
13
|
+
|
14
|
+
PATH_INTERNAL: String
|
15
|
+
|
16
|
+
PATH_EVAL: String
|
17
|
+
|
18
|
+
PATH_INLINE_TEMPLATE: String
|
19
|
+
|
20
|
+
# @rbs (?log_level: Symbol, ?raises: bool) -> void
|
21
|
+
def initialize: (?log_level: Symbol, ?raises: bool) -> void
|
22
|
+
|
23
|
+
# @rbs [T] () { () -> T } -> T
|
24
|
+
def enable: [T] () { () -> T } -> T
|
25
|
+
|
26
|
+
# @rbs () -> void
|
27
|
+
def disable: () -> void
|
28
|
+
|
29
|
+
# @rbs () -> Hash[String, File]
|
30
|
+
def files: () -> Hash[String, File]
|
31
|
+
|
32
|
+
# @rbs () -> void
|
33
|
+
def save_comments: () -> void
|
34
|
+
|
35
|
+
# @rbs (out_dir: String) -> void
|
36
|
+
def save_files: (out_dir: String) -> void
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
# @rbs () -> TracePoint
|
41
|
+
def trace: () -> TracePoint
|
42
|
+
|
43
|
+
# @rbs () -> Logger
|
44
|
+
def logger: () -> Logger
|
45
|
+
|
46
|
+
# @rbs () -> Builder
|
47
|
+
def builder: () -> Builder
|
48
|
+
|
49
|
+
# @rbs (String) -> File
|
50
|
+
def find_or_new_file: (String) -> File
|
51
|
+
|
52
|
+
# @rbs (TracePoint) -> void
|
53
|
+
def record: (TracePoint) -> void
|
54
|
+
|
55
|
+
# @rbs (TracePoint, AST::Members::MethodDefinition) -> void
|
56
|
+
def call_event: (TracePoint, AST::Members::MethodDefinition) -> void
|
57
|
+
|
58
|
+
# @rbs (TracePoint, AST::Members::MethodDefinition) -> void
|
59
|
+
def return_event: (TracePoint, AST::Members::MethodDefinition) -> void
|
60
|
+
|
61
|
+
# @rbs (String) -> bool
|
62
|
+
def ignore_path?: (String) -> bool
|
63
|
+
|
64
|
+
# @rbs (String, Symbol) -> bool
|
65
|
+
def void_return_type?: (String, Symbol) -> bool
|
66
|
+
|
67
|
+
# @rbs (String, String) -> Thread::Backtrace::Location?
|
68
|
+
def find_caller_location: (String, String) -> Thread::Backtrace::Location?
|
7
69
|
end
|
8
70
|
end
|
data/tmp/.keep
ADDED
File without changes
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbs-trace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takumi Shotoku
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 2025-02-23 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: prism
|
@@ -23,12 +23,27 @@ dependencies:
|
|
23
23
|
- - ">="
|
24
24
|
- !ruby/object:Gem::Version
|
25
25
|
version: 0.3.0
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rbs
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.5.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 3.5.0
|
26
40
|
description: |
|
27
41
|
RBS::Trace collects argument types and return value types using TracePoint, and inserts
|
28
42
|
inline RBS type declarations into files.
|
29
43
|
email:
|
30
44
|
- sinsoku.listy@gmail.com
|
31
|
-
executables:
|
45
|
+
executables:
|
46
|
+
- rbs-trace
|
32
47
|
extensions: []
|
33
48
|
extra_rdoc_files: []
|
34
49
|
files:
|
@@ -40,29 +55,41 @@ files:
|
|
40
55
|
- README.md
|
41
56
|
- Rakefile
|
42
57
|
- Steepfile
|
58
|
+
- exe/rbs-trace
|
43
59
|
- lib/rbs-trace.rb
|
44
60
|
- lib/rbs/trace.rb
|
45
|
-
- lib/rbs/trace/
|
46
|
-
- lib/rbs/trace/
|
61
|
+
- lib/rbs/trace/builder.rb
|
62
|
+
- lib/rbs/trace/cli.rb
|
63
|
+
- lib/rbs/trace/cli/inline.rb
|
64
|
+
- lib/rbs/trace/cli/merge.rb
|
47
65
|
- lib/rbs/trace/file.rb
|
48
|
-
- lib/rbs/trace/
|
66
|
+
- lib/rbs/trace/helpers.rb
|
67
|
+
- lib/rbs/trace/inline_comment_visitor.rb
|
68
|
+
- lib/rbs/trace/overload_compact.rb
|
69
|
+
- lib/rbs/trace/return_value_visitor.rb
|
49
70
|
- lib/rbs/trace/version.rb
|
50
71
|
- rbs_collection.lock.yaml
|
51
72
|
- rbs_collection.yaml
|
52
73
|
- sig/generated/rbs-trace.rbs
|
53
74
|
- sig/generated/rbs/trace.rbs
|
54
|
-
- sig/generated/rbs/trace/
|
55
|
-
- sig/generated/rbs/trace/
|
75
|
+
- sig/generated/rbs/trace/builder.rbs
|
76
|
+
- sig/generated/rbs/trace/cli.rbs
|
77
|
+
- sig/generated/rbs/trace/cli/inline.rbs
|
78
|
+
- sig/generated/rbs/trace/cli/merge.rbs
|
56
79
|
- sig/generated/rbs/trace/file.rbs
|
57
|
-
- sig/generated/rbs/trace/
|
80
|
+
- sig/generated/rbs/trace/helpers.rbs
|
81
|
+
- sig/generated/rbs/trace/inline_comment_visitor.rbs
|
82
|
+
- sig/generated/rbs/trace/overload_compact.rbs
|
83
|
+
- sig/generated/rbs/trace/return_value_visitor.rbs
|
58
84
|
- sig/generated/rbs/trace/version.rbs
|
85
|
+
- tmp/.keep
|
59
86
|
homepage: https://github.com/sinsoku/rbs-trace
|
60
87
|
licenses:
|
61
88
|
- MIT
|
62
89
|
metadata:
|
63
90
|
homepage_uri: https://github.com/sinsoku/rbs-trace
|
64
|
-
source_code_uri: https://github.com/sinsoku/rbs-trace/tree/v0.
|
65
|
-
changelog_uri: https://github.com/sinsoku/rbs-trace/blob/v0.
|
91
|
+
source_code_uri: https://github.com/sinsoku/rbs-trace/tree/v0.4.0
|
92
|
+
changelog_uri: https://github.com/sinsoku/rbs-trace/blob/v0.4.0/CHANGELOG.md
|
66
93
|
rubygems_mfa_required: 'true'
|
67
94
|
rdoc_options: []
|
68
95
|
require_paths:
|
@@ -1,107 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RBS
|
4
|
-
module Trace
|
5
|
-
class Declaration
|
6
|
-
METHOD_KINDS = %i[req opt rest keyreq key keyrest].freeze #: Array[Symbol]
|
7
|
-
private_constant :METHOD_KINDS
|
8
|
-
|
9
|
-
attr_reader :parameters #: Array[untyped]
|
10
|
-
attr_reader :void #: bool
|
11
|
-
attr_accessor :return_type #: Array[Object]
|
12
|
-
|
13
|
-
# @rbs (Array[untyped], ?void: bool) -> void
|
14
|
-
def initialize(parameters, void: false)
|
15
|
-
@parameters = parameters
|
16
|
-
@void = void
|
17
|
-
end
|
18
|
-
|
19
|
-
# @rbs () -> String
|
20
|
-
def to_rbs
|
21
|
-
return_rbs = void ? "void" : convert_type(return_type)
|
22
|
-
|
23
|
-
"(#{parameters_rbs}) -> #{return_rbs}"
|
24
|
-
end
|
25
|
-
|
26
|
-
# @rbs (Declaration) -> Declaration
|
27
|
-
def merge(other) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
28
|
-
new_parameters = @parameters.map.with_index do |parameter, index|
|
29
|
-
kind = parameter[0]
|
30
|
-
name = parameter[1]
|
31
|
-
klass = parameter[2]
|
32
|
-
other_klass = other.parameters[index][2]
|
33
|
-
|
34
|
-
merged_klass = (klass + other_klass).uniq
|
35
|
-
[kind, name, merged_klass]
|
36
|
-
end
|
37
|
-
Declaration.new(new_parameters, void: void && other.void).tap do |decl|
|
38
|
-
decl.return_type = (return_type + other.return_type).uniq
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
# TODO: support block argument
|
45
|
-
# @rbs () -> String
|
46
|
-
def parameters_rbs
|
47
|
-
converted = {} #: Hash[Symbol, Array[String?]]
|
48
|
-
@parameters.each do |kind, name, klass|
|
49
|
-
converted[kind] ||= [] #: Array[String?]
|
50
|
-
converted[kind] << convert(kind, name, klass)
|
51
|
-
end
|
52
|
-
|
53
|
-
METHOD_KINDS.flat_map { |kind| converted[kind] }.compact.join(", ")
|
54
|
-
end
|
55
|
-
|
56
|
-
# @rbs (Symbol, Symbol, Array[Object]) -> String?
|
57
|
-
def convert(kind, name, klass) # rubocop:disable Metrics/MethodLength
|
58
|
-
type = convert_type(klass)
|
59
|
-
case kind
|
60
|
-
when :req
|
61
|
-
type
|
62
|
-
when :opt
|
63
|
-
"?#{type}"
|
64
|
-
when :rest
|
65
|
-
"*#{type}"
|
66
|
-
when :keyreq
|
67
|
-
"#{name}: #{type}"
|
68
|
-
when :key
|
69
|
-
"?#{name}: #{type}"
|
70
|
-
when :keyrest
|
71
|
-
"**#{type}"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
# @rbs (Array[Object]) -> String
|
76
|
-
def convert_type(klass) # rubocop:disable Metrics
|
77
|
-
optional = klass.any? { |k| k == NilClass }
|
78
|
-
types = klass.filter_map do |k|
|
79
|
-
if k == NilClass
|
80
|
-
nil
|
81
|
-
elsif [TrueClass, FalseClass].include?(k) # steep:ignore ArgumentTypeMismatch
|
82
|
-
"bool"
|
83
|
-
elsif [Array, Range].include?(k) # steep:ignore ArgumentTypeMismatch
|
84
|
-
"#{k}[untyped]"
|
85
|
-
elsif k == Hash
|
86
|
-
"#{k}[untyped, untyped]"
|
87
|
-
elsif k == Object
|
88
|
-
"untyped"
|
89
|
-
else
|
90
|
-
k.name # steep:ignore NoMethod
|
91
|
-
end
|
92
|
-
end.uniq
|
93
|
-
type = types.join("|")
|
94
|
-
|
95
|
-
if types.size > 1 && optional
|
96
|
-
"(#{type})?"
|
97
|
-
elsif types.empty?
|
98
|
-
"nil"
|
99
|
-
elsif optional
|
100
|
-
"#{type}?"
|
101
|
-
else
|
102
|
-
type
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
data/lib/rbs/trace/definition.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RBS
|
4
|
-
module Trace
|
5
|
-
class Definition
|
6
|
-
attr_reader :klass #: Class
|
7
|
-
attr_reader :name #: Symbol
|
8
|
-
attr_reader :lineno #: Integer
|
9
|
-
|
10
|
-
# @rbs (klass: Object, name: Symbol, lineno: Integer) -> void
|
11
|
-
def initialize(klass:, name:, lineno:)
|
12
|
-
@klass = klass
|
13
|
-
@name = name
|
14
|
-
@lineno = lineno
|
15
|
-
end
|
16
|
-
|
17
|
-
# @rbs () -> Array[Declaration]
|
18
|
-
def decls
|
19
|
-
@decls ||= []
|
20
|
-
end
|
21
|
-
|
22
|
-
# @rbs (?Integer) -> String
|
23
|
-
def rbs_comment(indent = 0)
|
24
|
-
"#{" " * indent}# @rbs #{rbs}\n"
|
25
|
-
end
|
26
|
-
|
27
|
-
# @rbs () -> String
|
28
|
-
def rbs
|
29
|
-
@decls.inject { |result, decl| result.merge(decl) }.to_rbs
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,182 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RBS
|
4
|
-
module Trace
|
5
|
-
class MethodTracing # rubocop:disable Metrics/ClassLength
|
6
|
-
ASSIGNED_NODE_TYPES = %i[statements_node local_variable_write_node instance_variable_write_node
|
7
|
-
class_variable_write_node constant_write_node call_node
|
8
|
-
embedded_statements_node].freeze #: Array[Symbol]
|
9
|
-
private_constant :ASSIGNED_NODE_TYPES
|
10
|
-
|
11
|
-
# @rbs [T] () { () -> T } -> T
|
12
|
-
def enable(&)
|
13
|
-
trace.enable(&)
|
14
|
-
end
|
15
|
-
|
16
|
-
# @rbs () -> void
|
17
|
-
def disable
|
18
|
-
trace.disable
|
19
|
-
end
|
20
|
-
|
21
|
-
# @rbs () -> Hash[String, File]
|
22
|
-
def files
|
23
|
-
@files ||= {}
|
24
|
-
end
|
25
|
-
|
26
|
-
# @rbs () -> void
|
27
|
-
def insert_rbs
|
28
|
-
files.each_value(&:rewrite)
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
# @rbs () -> TracePoint
|
34
|
-
def trace
|
35
|
-
@trace ||= TracePoint.new(:call, :return) { |tp| record(tp) }
|
36
|
-
end
|
37
|
-
|
38
|
-
# @rbs () -> Logger
|
39
|
-
def logger
|
40
|
-
return @logger if defined?(@logger)
|
41
|
-
|
42
|
-
level = ENV["RBS_TRACE_DEBUG"] ? :debug : :info
|
43
|
-
@logger = Logger.new($stdout, level:)
|
44
|
-
end
|
45
|
-
|
46
|
-
# @rbs () -> Array[Declaration]
|
47
|
-
def stack_traces
|
48
|
-
@stack_traces ||= []
|
49
|
-
end
|
50
|
-
|
51
|
-
# @rbs (String) -> File
|
52
|
-
def find_or_new_file(path)
|
53
|
-
files[path] ||= File.new(path)
|
54
|
-
files[path]
|
55
|
-
end
|
56
|
-
|
57
|
-
# @rbs (File, TracePoint) -> Definition
|
58
|
-
def find_or_new_definition(file, tp)
|
59
|
-
name = tp.method_id
|
60
|
-
is_singleton = tp.defined_class.singleton_class? # steep:ignore NoMethod
|
61
|
-
klass = is_singleton ? tp.self : tp.defined_class
|
62
|
-
mark = is_singleton ? "." : "#"
|
63
|
-
signature = "#{klass}#{mark}#{name}"
|
64
|
-
|
65
|
-
# steep:ignore:start
|
66
|
-
file.definitions[signature] ||= Definition.new(klass:, name:, lineno: tp.lineno)
|
67
|
-
# steep:ignore:end
|
68
|
-
end
|
69
|
-
|
70
|
-
# @rbs (TracePoint) -> void
|
71
|
-
def record(tp) # rubocop:disable Metrics/MethodLength
|
72
|
-
return if ignore_path?(tp.path)
|
73
|
-
|
74
|
-
file = find_or_new_file(tp.path)
|
75
|
-
definition = find_or_new_definition(file, tp)
|
76
|
-
|
77
|
-
case tp.event
|
78
|
-
when :call
|
79
|
-
call_event(tp)
|
80
|
-
when :return
|
81
|
-
return_event(tp, definition)
|
82
|
-
end
|
83
|
-
rescue StandardError => e
|
84
|
-
logger.debug(e)
|
85
|
-
end
|
86
|
-
|
87
|
-
# @rbs (TracePoint) -> void
|
88
|
-
def call_event(tp) # rubocop:disable Metrics
|
89
|
-
parameters = tp.parameters.filter_map do |kind, name| # steep:ignore NoMethod
|
90
|
-
# steep:ignore:start
|
91
|
-
value = tp.binding.local_variable_get(name) if name && !%i[* ** &].include?(name)
|
92
|
-
# steep:ignore:end
|
93
|
-
klass = case kind
|
94
|
-
when :rest
|
95
|
-
value ? value.map { |v| obj_to_class(v) }.uniq : [Object]
|
96
|
-
when :keyrest
|
97
|
-
value ? value.map { |_, v| obj_to_class(v) }.uniq : [Object]
|
98
|
-
when :block
|
99
|
-
# TODO: support block argument
|
100
|
-
next
|
101
|
-
else
|
102
|
-
[obj_to_class(value)]
|
103
|
-
end
|
104
|
-
[kind, name, klass]
|
105
|
-
end
|
106
|
-
# steep:ignore:start
|
107
|
-
stack_traces << Declaration.new(parameters, void: !assign_return_value?(tp.path, tp.method_id))
|
108
|
-
# steep:ignore:end
|
109
|
-
end
|
110
|
-
|
111
|
-
# @rbs (TracePoint, Definition) -> void
|
112
|
-
def return_event(tp, definition)
|
113
|
-
decl = stack_traces.pop
|
114
|
-
# TODO: check usecase where decl is nil
|
115
|
-
return unless decl
|
116
|
-
|
117
|
-
decl.return_type = [obj_to_class(tp.return_value)]
|
118
|
-
definition.decls << decl
|
119
|
-
end
|
120
|
-
|
121
|
-
# @rbs (BasicObject) -> Class
|
122
|
-
def obj_to_class(obj)
|
123
|
-
Object.instance_method(:class).bind_call(obj)
|
124
|
-
end
|
125
|
-
|
126
|
-
# @rbs (String) -> bool
|
127
|
-
def ignore_path?(path)
|
128
|
-
bundle_path = Bundler.bundle_path.to_s # steep:ignore NoMethod
|
129
|
-
ruby_lib_path = RbConfig::CONFIG["rubylibdir"]
|
130
|
-
|
131
|
-
path.start_with?("<internal") ||
|
132
|
-
path.start_with?("(eval") ||
|
133
|
-
path.start_with?(bundle_path) ||
|
134
|
-
path.start_with?(ruby_lib_path) ||
|
135
|
-
path.start_with?(__FILE__)
|
136
|
-
end
|
137
|
-
|
138
|
-
# @rbs (String, Symbol) -> bool
|
139
|
-
def assign_return_value?(path, method_id) # rubocop:disable Metrics
|
140
|
-
is_initialize = method_id == :initialize
|
141
|
-
return false if is_initialize
|
142
|
-
|
143
|
-
locations = caller_locations || []
|
144
|
-
i = locations.index { |loc| loc.path == path && loc.label == method_id.to_s }
|
145
|
-
loc = locations[i + 1] if i
|
146
|
-
# If the caller is not found, assume the return value is used.
|
147
|
-
return true unless loc
|
148
|
-
|
149
|
-
node = parsed_nodes(loc.path) # steep:ignore ArgumentTypeMismatch
|
150
|
-
return false unless node
|
151
|
-
|
152
|
-
method_name = is_initialize ? :new : method_id
|
153
|
-
parents = find_parents(node, method_name:, lineno: loc.lineno)
|
154
|
-
return false unless parents
|
155
|
-
|
156
|
-
parent = parents[1]
|
157
|
-
ASSIGNED_NODE_TYPES.include?(parent.type) # steep:ignore NoMethod
|
158
|
-
end
|
159
|
-
|
160
|
-
# @rbs (Prism::Node, method_name: Symbol, lineno: Integer, ?parents: Array[Prism::Node]) -> Array[Prism::Node]?
|
161
|
-
def find_parents(node, method_name:, lineno:, parents: [])
|
162
|
-
result = nil
|
163
|
-
node.compact_child_nodes.each do |child| # steep:ignore NoMethod
|
164
|
-
break if result
|
165
|
-
|
166
|
-
found = child.type == :call_node && child.name == method_name && child.location.start_line == lineno
|
167
|
-
result = found ? [child, *parents] : find_parents(child, method_name:, lineno:, parents: [node, *parents])
|
168
|
-
end
|
169
|
-
result
|
170
|
-
end
|
171
|
-
|
172
|
-
# @rbs (String) -> Prism::ProgramNode?
|
173
|
-
def parsed_nodes(path)
|
174
|
-
return unless ::File.exist?(path)
|
175
|
-
|
176
|
-
@parsed_nodes ||= {} #: Hash[String, Prism::ParseResult]
|
177
|
-
@parsed_nodes[path] ||= Prism.parse_file(path)
|
178
|
-
@parsed_nodes[path].value
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# Generated from lib/rbs/trace/declaration.rb with RBS::Inline
|
2
|
-
|
3
|
-
module RBS
|
4
|
-
module Trace
|
5
|
-
class Declaration
|
6
|
-
METHOD_KINDS: Array[Symbol]
|
7
|
-
|
8
|
-
attr_reader parameters: Array[untyped]
|
9
|
-
|
10
|
-
attr_reader void: bool
|
11
|
-
|
12
|
-
attr_accessor return_type: Array[Object]
|
13
|
-
|
14
|
-
# @rbs (Array[untyped], ?void: bool) -> void
|
15
|
-
def initialize: (Array[untyped], ?void: bool) -> void
|
16
|
-
|
17
|
-
# @rbs () -> String
|
18
|
-
def to_rbs: () -> String
|
19
|
-
|
20
|
-
# @rbs (Declaration) -> Declaration
|
21
|
-
def merge: (Declaration) -> Declaration
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
# TODO: support block argument
|
26
|
-
# @rbs () -> String
|
27
|
-
def parameters_rbs: () -> String
|
28
|
-
|
29
|
-
# @rbs (Symbol, Symbol, Array[Object]) -> String?
|
30
|
-
def convert: (Symbol, Symbol, Array[Object]) -> String?
|
31
|
-
|
32
|
-
# @rbs (Array[Object]) -> String
|
33
|
-
def convert_type: (Array[Object]) -> String
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# Generated from lib/rbs/trace/definition.rb with RBS::Inline
|
2
|
-
|
3
|
-
module RBS
|
4
|
-
module Trace
|
5
|
-
class Definition
|
6
|
-
attr_reader klass: Class
|
7
|
-
|
8
|
-
attr_reader name: Symbol
|
9
|
-
|
10
|
-
attr_reader lineno: Integer
|
11
|
-
|
12
|
-
# @rbs (klass: Object, name: Symbol, lineno: Integer) -> void
|
13
|
-
def initialize: (klass: Object, name: Symbol, lineno: Integer) -> void
|
14
|
-
|
15
|
-
# @rbs () -> Array[Declaration]
|
16
|
-
def decls: () -> Array[Declaration]
|
17
|
-
|
18
|
-
# @rbs (?Integer) -> String
|
19
|
-
def rbs_comment: (?Integer) -> String
|
20
|
-
|
21
|
-
# @rbs () -> String
|
22
|
-
def rbs: () -> String
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
# Generated from lib/rbs/trace/method_tracing.rb with RBS::Inline
|
2
|
-
|
3
|
-
module RBS
|
4
|
-
module Trace
|
5
|
-
class MethodTracing
|
6
|
-
# rubocop:disable Metrics/ClassLength
|
7
|
-
ASSIGNED_NODE_TYPES: Array[Symbol]
|
8
|
-
|
9
|
-
# @rbs [T] () { () -> T } -> T
|
10
|
-
def enable: [T] () { () -> T } -> T
|
11
|
-
|
12
|
-
# @rbs () -> void
|
13
|
-
def disable: () -> void
|
14
|
-
|
15
|
-
# @rbs () -> Hash[String, File]
|
16
|
-
def files: () -> Hash[String, File]
|
17
|
-
|
18
|
-
# @rbs () -> void
|
19
|
-
def insert_rbs: () -> void
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
# @rbs () -> TracePoint
|
24
|
-
def trace: () -> TracePoint
|
25
|
-
|
26
|
-
# @rbs () -> Logger
|
27
|
-
def logger: () -> Logger
|
28
|
-
|
29
|
-
# @rbs () -> Array[Declaration]
|
30
|
-
def stack_traces: () -> Array[Declaration]
|
31
|
-
|
32
|
-
# @rbs (String) -> File
|
33
|
-
def find_or_new_file: (String) -> File
|
34
|
-
|
35
|
-
# @rbs (File, TracePoint) -> Definition
|
36
|
-
def find_or_new_definition: (File, TracePoint) -> Definition
|
37
|
-
|
38
|
-
# @rbs (TracePoint) -> void
|
39
|
-
def record: (TracePoint) -> void
|
40
|
-
|
41
|
-
# @rbs (TracePoint) -> void
|
42
|
-
def call_event: (TracePoint) -> void
|
43
|
-
|
44
|
-
# @rbs (TracePoint, Definition) -> void
|
45
|
-
def return_event: (TracePoint, Definition) -> void
|
46
|
-
|
47
|
-
# @rbs (BasicObject) -> Class
|
48
|
-
def obj_to_class: (BasicObject) -> Class
|
49
|
-
|
50
|
-
# @rbs (String) -> bool
|
51
|
-
def ignore_path?: (String) -> bool
|
52
|
-
|
53
|
-
# @rbs (String, Symbol) -> bool
|
54
|
-
def assign_return_value?: (String, Symbol) -> bool
|
55
|
-
|
56
|
-
# @rbs (Prism::Node, method_name: Symbol, lineno: Integer, ?parents: Array[Prism::Node]) -> Array[Prism::Node]?
|
57
|
-
def find_parents: (Prism::Node, method_name: Symbol, lineno: Integer, ?parents: Array[Prism::Node]) -> Array[Prism::Node]?
|
58
|
-
|
59
|
-
# @rbs (String) -> Prism::ProgramNode?
|
60
|
-
def parsed_nodes: (String) -> Prism::ProgramNode?
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|