rbs-trace 0.4.1 → 0.5.1
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/CHANGELOG.md +9 -0
- data/README.md +1 -3
- data/lib/rbs/trace/cli/inline.rb +0 -6
- data/lib/rbs/trace/inline_comment_visitor.rb +19 -6
- data/lib/rbs/trace/version.rb +1 -1
- data/lib/rbs/trace.rb +13 -20
- data/sig/generated/rbs/trace/inline_comment_visitor.rbs +3 -0
- data/sig/generated/rbs/trace.rbs +5 -11
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffa35a17dce6177b82270290080a095b19ee61015245ce8d64621990b7634635
|
4
|
+
data.tar.gz: c6ec9bb2c2387b4c421e03bab6d3aec654eff71e1d814c680027952ccd4d6805
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfabe32a33ba27850b286c2a6ab5bbf33d382dea09cfb6e6bc828d9c3aac949b644ad9cd8afbbc2bbc3f3c873c6200ccb9743f7ee04143ec3eb38ff2eb35f382
|
7
|
+
data.tar.gz: 4dbdea59fdf5711777c5a3b9ed5e07e8420c901fe6a156d9e710e31227c437220001974e848c678adef096aef279a277b2679c11329ae7f32c43841b65649edb
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.5.1] - 2025-04-20
|
4
|
+
|
5
|
+
- fix: Support nested modules defined with `::`
|
6
|
+
|
7
|
+
## [0.5.0] - 2025-03-30
|
8
|
+
|
9
|
+
- feat: Add paths to control trace targets
|
10
|
+
- chore: Remove wrong examples
|
11
|
+
|
3
12
|
## [0.4.1] - 2025-02-24
|
4
13
|
|
5
14
|
- fix: Ensure class names are referenced
|
data/README.md
CHANGED
@@ -111,9 +111,7 @@ end
|
|
111
111
|
### Insert RBS declarations for specific files only
|
112
112
|
|
113
113
|
```ruby
|
114
|
-
|
115
|
-
file.rewrite if path.include?("app/models/")
|
116
|
-
end
|
114
|
+
RBS::Trace.new(paths: Dir.glob("#{Dir.pwd}/app/models/**/*.rb"))
|
117
115
|
```
|
118
116
|
|
119
117
|
### Save RBS declarations as files
|
data/lib/rbs/trace/cli/inline.rb
CHANGED
@@ -13,12 +13,6 @@ module RBS
|
|
13
13
|
# Insert inline comments to `app/**/*.rb`.
|
14
14
|
$ rbs-trace inline --sig-dir=sig --rb-dir=app
|
15
15
|
|
16
|
-
# Generate RBS files with rbs-inline.
|
17
|
-
$ rbs-inline --output --opt-out app
|
18
|
-
|
19
|
-
# Remove method definitions that have been migrated to inline comments.
|
20
|
-
$ rbs subtract --write sig sig/generated/
|
21
|
-
|
22
16
|
Options:
|
23
17
|
USAGE
|
24
18
|
|
@@ -15,17 +15,17 @@ module RBS
|
|
15
15
|
# @rbs override
|
16
16
|
# @rbs (Prism::Node) -> void
|
17
17
|
def visit_class_node(node)
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
with_context node do
|
19
|
+
super
|
20
|
+
end
|
21
21
|
end
|
22
22
|
|
23
23
|
# @rbs override
|
24
24
|
# @rbs (Prism::Node) -> void
|
25
25
|
def visit_module_node(node)
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
with_context node do
|
27
|
+
super
|
28
|
+
end
|
29
29
|
end
|
30
30
|
|
31
31
|
# @rbs override
|
@@ -58,6 +58,19 @@ module RBS
|
|
58
58
|
member.is_a?(AST::Members::MethodDefinition) && member.name == name
|
59
59
|
end
|
60
60
|
end
|
61
|
+
|
62
|
+
# @rbs (Prism::ModuleNode | Prism::ClassNode) { () -> void } -> void
|
63
|
+
def with_context(node)
|
64
|
+
constant_path = node.constant_path
|
65
|
+
raise if constant_path.is_a?(Prism::MissingNode) || constant_path.is_a?(Prism::CallNode)
|
66
|
+
|
67
|
+
names = constant_path.full_name_parts
|
68
|
+
@context.push(*names)
|
69
|
+
|
70
|
+
yield
|
71
|
+
|
72
|
+
@context.pop(names.size)
|
73
|
+
end
|
61
74
|
end
|
62
75
|
end
|
63
76
|
end
|
data/lib/rbs/trace/version.rb
CHANGED
data/lib/rbs/trace.rb
CHANGED
@@ -24,17 +24,15 @@ module RBS
|
|
24
24
|
BUNDLE_PATH = Bundler.bundle_path.to_s #: String
|
25
25
|
# steep:ignore:end
|
26
26
|
RUBY_LIB_PATH = RbConfig::CONFIG["rubylibdir"] #: String
|
27
|
-
PATH_INTERNAL = "<internal" #: String
|
28
|
-
PATH_EVAL = "(eval" #: String
|
29
|
-
PATH_INLINE_TEMPLATE = "inline template" #: String
|
30
27
|
|
31
|
-
private_constant :BUNDLE_PATH, :RUBY_LIB_PATH
|
28
|
+
private_constant :BUNDLE_PATH, :RUBY_LIB_PATH
|
32
29
|
|
33
|
-
# @rbs (?log_level: Symbol, ?raises: bool) -> void
|
34
|
-
def initialize(log_level: nil, raises: false)
|
30
|
+
# @rbs (?log_level: Symbol, ?raises: bool, ?paths: Array[String]) -> void
|
31
|
+
def initialize(log_level: nil, raises: false, paths: default_paths)
|
35
32
|
@log_level = log_level
|
36
33
|
@log_level ||= ENV["RBS_TRACE_DEBUG"] ? :debug : :info
|
37
34
|
@raises = raises
|
35
|
+
@paths = Set.new(paths)
|
38
36
|
end
|
39
37
|
|
40
38
|
# @rbs [T] () { () -> T } -> T
|
@@ -54,7 +52,9 @@ module RBS
|
|
54
52
|
|
55
53
|
# @rbs () -> void
|
56
54
|
def save_comments
|
57
|
-
files.
|
55
|
+
files.each do |path, file|
|
56
|
+
file.rewrite if @paths.include?(path)
|
57
|
+
end
|
58
58
|
end
|
59
59
|
|
60
60
|
# @rbs (out_dir: String) -> void
|
@@ -64,6 +64,11 @@ module RBS
|
|
64
64
|
|
65
65
|
private
|
66
66
|
|
67
|
+
# @rbs () -> Array[String]
|
68
|
+
def default_paths
|
69
|
+
Dir.glob("#{Dir.pwd}/**/*.rb").reject { |path| path.start_with?(BUNDLE_PATH, RUBY_LIB_PATH) }
|
70
|
+
end
|
71
|
+
|
67
72
|
# @rbs () -> TracePoint
|
68
73
|
def trace
|
69
74
|
@trace ||= TracePoint.new(:call, :return) { |tp| record(tp) }
|
@@ -86,7 +91,7 @@ module RBS
|
|
86
91
|
|
87
92
|
# @rbs (TracePoint) -> void
|
88
93
|
def record(tp) # rubocop:disable Metrics/MethodLength
|
89
|
-
return
|
94
|
+
return unless @paths.include?(tp.path)
|
90
95
|
|
91
96
|
file = find_or_new_file(tp.path)
|
92
97
|
# steep:ignore:start
|
@@ -127,18 +132,6 @@ module RBS
|
|
127
132
|
member.overloads << overload
|
128
133
|
end
|
129
134
|
|
130
|
-
# @rbs (String) -> bool
|
131
|
-
def ignore_path?(path)
|
132
|
-
path.start_with?(
|
133
|
-
PATH_INTERNAL,
|
134
|
-
PATH_EVAL,
|
135
|
-
PATH_INLINE_TEMPLATE,
|
136
|
-
BUNDLE_PATH,
|
137
|
-
RUBY_LIB_PATH,
|
138
|
-
__FILE__
|
139
|
-
)
|
140
|
-
end
|
141
|
-
|
142
135
|
# @rbs (String, Symbol) -> bool
|
143
136
|
def void_return_type?(path, method_id)
|
144
137
|
return true if method_id == :initialize
|
@@ -22,6 +22,9 @@ module RBS
|
|
22
22
|
|
23
23
|
# @rbs (Symbol) -> AST::Members::MethodDefinition?
|
24
24
|
def find_method_definition: (Symbol) -> AST::Members::MethodDefinition?
|
25
|
+
|
26
|
+
# @rbs (Prism::ModuleNode | Prism::ClassNode) { () -> void } -> void
|
27
|
+
def with_context: (Prism::ModuleNode | Prism::ClassNode) { () -> void } -> void
|
25
28
|
end
|
26
29
|
end
|
27
30
|
end
|
data/sig/generated/rbs/trace.rbs
CHANGED
@@ -11,14 +11,8 @@ module RBS
|
|
11
11
|
# steep:ignore:end
|
12
12
|
RUBY_LIB_PATH: String
|
13
13
|
|
14
|
-
|
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
|
14
|
+
# @rbs (?log_level: Symbol, ?raises: bool, ?paths: Array[String]) -> void
|
15
|
+
def initialize: (?log_level: Symbol, ?raises: bool, ?paths: Array[String]) -> void
|
22
16
|
|
23
17
|
# @rbs [T] () { () -> T } -> T
|
24
18
|
def enable: [T] () { () -> T } -> T
|
@@ -37,6 +31,9 @@ module RBS
|
|
37
31
|
|
38
32
|
private
|
39
33
|
|
34
|
+
# @rbs () -> Array[String]
|
35
|
+
def default_paths: () -> Array[String]
|
36
|
+
|
40
37
|
# @rbs () -> TracePoint
|
41
38
|
def trace: () -> TracePoint
|
42
39
|
|
@@ -58,9 +55,6 @@ module RBS
|
|
58
55
|
# @rbs (TracePoint, AST::Members::MethodDefinition) -> void
|
59
56
|
def return_event: (TracePoint, AST::Members::MethodDefinition) -> void
|
60
57
|
|
61
|
-
# @rbs (String) -> bool
|
62
|
-
def ignore_path?: (String) -> bool
|
63
|
-
|
64
58
|
# @rbs (String, Symbol) -> bool
|
65
59
|
def void_return_type?: (String, Symbol) -> bool
|
66
60
|
|
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.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takumi Shotoku
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: prism
|
@@ -88,8 +88,8 @@ licenses:
|
|
88
88
|
- MIT
|
89
89
|
metadata:
|
90
90
|
homepage_uri: https://github.com/sinsoku/rbs-trace
|
91
|
-
source_code_uri: https://github.com/sinsoku/rbs-trace/tree/v0.
|
92
|
-
changelog_uri: https://github.com/sinsoku/rbs-trace/blob/v0.
|
91
|
+
source_code_uri: https://github.com/sinsoku/rbs-trace/tree/v0.5.1
|
92
|
+
changelog_uri: https://github.com/sinsoku/rbs-trace/blob/v0.5.1/CHANGELOG.md
|
93
93
|
rubygems_mfa_required: 'true'
|
94
94
|
rdoc_options: []
|
95
95
|
require_paths:
|
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
- !ruby/object:Gem::Version
|
106
106
|
version: '0'
|
107
107
|
requirements: []
|
108
|
-
rubygems_version: 3.6.
|
108
|
+
rubygems_version: 3.6.7
|
109
109
|
specification_version: 4
|
110
110
|
summary: Automatically Insert inline RBS type declarations using runtime information.
|
111
111
|
test_files: []
|