rbs-trace 0.5.1 → 0.7.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/.devcontainer/devcontainer.json +17 -0
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +9 -0
- data/README.md +33 -0
- data/lib/rbs/trace/builder.rb +12 -7
- data/lib/rbs/trace/cli/inline.rb +5 -2
- data/lib/rbs/trace/file.rb +6 -6
- data/lib/rbs/trace/inline_comment_visitor.rb +4 -3
- data/lib/rbs/trace/version.rb +1 -1
- data/lib/rbs/trace.rb +8 -3
- data/rbs_collection.lock.yaml +11 -3
- data/sig/generated/rbs/trace/builder.rbs +4 -1
- data/sig/generated/rbs/trace/file.rbs +4 -4
- data/sig/generated/rbs/trace/inline_comment_visitor.rbs +2 -2
- data/sig/generated/rbs/trace.rbs +5 -2
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66c8c25570faea268f27c79d9a91cd4b0768e326e6c013fac3ea5bffb2c94bb5
|
4
|
+
data.tar.gz: 1fdefe3317b2a9c59600e1182fbfcd4b267020bc63c9bf9537f128b00d3543d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ead299e9457dcd8c8b00b363110a57448cc935a6d634009d584966d9c913588708e48618b56a88ff69550f6fe7c2c911a5db33a51711b480f221ee36fe18b72c
|
7
|
+
data.tar.gz: 668d6007a51b4836fbd6c8ff0eadb9e59a30f60d1a53cf0498572778e6d27612e77bfb4426ffb44760433e2d3b9c9065cb01d36ede3f5a77c5115d168fa3fbd0
|
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
"image": "mcr.microsoft.com/devcontainers/base:1-bookworm",
|
3
|
+
"features": {
|
4
|
+
"ghcr.io/devcontainers/features/ruby:1": {
|
5
|
+
"version": "3.4.4"
|
6
|
+
}
|
7
|
+
},
|
8
|
+
"customizations": {
|
9
|
+
"vscode": {
|
10
|
+
"extensions": [
|
11
|
+
"GitHub.copilot",
|
12
|
+
"Shopify.ruby-lsp",
|
13
|
+
"soutaro.steep-vscode"
|
14
|
+
]
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.7.0] - 2025-09-01
|
4
|
+
|
5
|
+
- feat: Add support for generics other than Array, Range, and Hash
|
6
|
+
|
7
|
+
## [0.6.0] - 2025-05-12
|
8
|
+
|
9
|
+
- feat: Support inline comments using colon-prefixed RBS syntax
|
10
|
+
- chore: Update gem dependencies
|
11
|
+
|
3
12
|
## [0.5.1] - 2025-04-20
|
4
13
|
|
5
14
|
- fix: Support nested modules defined with `::`
|
data/README.md
CHANGED
@@ -114,12 +114,45 @@ end
|
|
114
114
|
RBS::Trace.new(paths: Dir.glob("#{Dir.pwd}/app/models/**/*.rb"))
|
115
115
|
```
|
116
116
|
|
117
|
+
### Change the format of embedded comments
|
118
|
+
|
119
|
+
You can change the comment format.
|
120
|
+
|
121
|
+
| `comment_format` | embedded comment |
|
122
|
+
|---|---|
|
123
|
+
| `:rbs_keyword` (default) | `# @rbs () -> void` |
|
124
|
+
| `:rbs_colon` | `#: () -> void` |
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
trace.save_comments(:rbs_colon)
|
128
|
+
```
|
129
|
+
|
130
|
+
or
|
131
|
+
|
132
|
+
```bash
|
133
|
+
$ rbs-trace inline --rb-dir=app --rb-dir=lib --comment-format=rbs_colon
|
134
|
+
```
|
135
|
+
|
117
136
|
### Save RBS declarations as files
|
118
137
|
|
119
138
|
```ruby
|
120
139
|
trace.save_files(out_dir: "sig/trace/")
|
121
140
|
```
|
122
141
|
|
142
|
+
### Specify generics size
|
143
|
+
|
144
|
+
By default, generics are applied to the generated results only in the following classes.
|
145
|
+
|
146
|
+
- Array
|
147
|
+
- Hash
|
148
|
+
- Range
|
149
|
+
|
150
|
+
If any other classes require generics, configure them as follows.
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
trace.add_generics_size!("CSV::Table" => 1, "ActiveSupport::HashWithIndifferentAccess" => 2)
|
154
|
+
```
|
155
|
+
|
123
156
|
### Parallel testing
|
124
157
|
|
125
158
|
If you are using a parallel testing gem such as [parallel_tests](https://github.com/grosser/parallel_tests) or [flatware](https://github.com/briandunn/flatware), first save the type definitions in RBS files.
|
data/lib/rbs/trace/builder.rb
CHANGED
@@ -9,12 +9,12 @@ module RBS
|
|
9
9
|
UNBOUND_NAME_METHOD = Class.instance_method(:name)
|
10
10
|
private_constant :UNBOUND_CLASS_METHOD, :UNBOUND_NAME_METHOD
|
11
11
|
|
12
|
-
|
13
|
-
Array => 1,
|
14
|
-
Range => 1,
|
15
|
-
Hash => 2
|
16
|
-
}.freeze
|
17
|
-
private_constant :
|
12
|
+
DEFAULT_GENERICS_SIZE = {
|
13
|
+
"Array" => 1,
|
14
|
+
"Range" => 1,
|
15
|
+
"Hash" => 2
|
16
|
+
}.freeze #: Hash[String, Integer]
|
17
|
+
private_constant :DEFAULT_GENERICS_SIZE
|
18
18
|
|
19
19
|
# @rbs (bind: Binding, parameters: Array[__todo__], void: bool) -> Array[__todo__]
|
20
20
|
def method_call(bind:, parameters:, void:)
|
@@ -37,6 +37,11 @@ module RBS
|
|
37
37
|
AST::Members::MethodDefinition::Overload.new(method_type:, annotations: [])
|
38
38
|
end
|
39
39
|
|
40
|
+
# @rbs () -> Hash[String, Integer]
|
41
|
+
def generics_size
|
42
|
+
@generics_size ||= DEFAULT_GENERICS_SIZE.dup
|
43
|
+
end
|
44
|
+
|
40
45
|
private
|
41
46
|
|
42
47
|
def stack_traces
|
@@ -115,7 +120,7 @@ module RBS
|
|
115
120
|
elsif klass == Object || class_name.nil?
|
116
121
|
type_untyped
|
117
122
|
else
|
118
|
-
size =
|
123
|
+
size = generics_size[klass.name].to_i
|
119
124
|
args = Array.new(size) { type_untyped }
|
120
125
|
Types::ClassInstance.new(name: TypeName.parse(class_name), args:, location: nil)
|
121
126
|
end
|
data/lib/rbs/trace/cli/inline.rb
CHANGED
@@ -5,7 +5,7 @@ module RBS
|
|
5
5
|
class CLI
|
6
6
|
class Inline
|
7
7
|
BANNER = <<~USAGE
|
8
|
-
Usage: rbs-trace inline --sig-dir=DIR --rb-dir=DIR
|
8
|
+
Usage: rbs-trace inline --sig-dir=DIR --rb-dir=DIR --comment-format=FORMAT
|
9
9
|
|
10
10
|
Insert RBS inline comments from RBS files.
|
11
11
|
|
@@ -14,16 +14,19 @@ module RBS
|
|
14
14
|
$ rbs-trace inline --sig-dir=sig --rb-dir=app
|
15
15
|
|
16
16
|
Options:
|
17
|
+
--comment-format FORMAT: Format for comments (`rbs_keyword` or `rbs_colon`, default: `rbs_keyword`)
|
17
18
|
USAGE
|
18
19
|
|
19
20
|
# @rbs (Array[String]) -> void
|
20
21
|
def run(args) # rubocop:disable Metrics
|
21
22
|
sig_dir = Pathname.pwd.join("sig").to_s
|
22
23
|
rb_dirs = [] #: Array[String]
|
24
|
+
comment_format = :rbs_keyword
|
23
25
|
|
24
26
|
opts = OptionParser.new(BANNER)
|
25
27
|
opts.on("--sig-dir DIR") { |dir| sig_dir = dir }
|
26
28
|
opts.on("--rb-dir DIR") { |dir| rb_dirs << dir }
|
29
|
+
opts.on("--comment-format FORMAT") { |format| comment_format = format.to_sym }
|
27
30
|
opts.parse!(args)
|
28
31
|
|
29
32
|
if rb_dirs.empty?
|
@@ -35,7 +38,7 @@ module RBS
|
|
35
38
|
rb_files = rb_dirs.flat_map { |rb_dir| Dir.glob("#{rb_dir}/**/*.rb") }
|
36
39
|
rb_files.each do |path|
|
37
40
|
file = File.new(path, decls)
|
38
|
-
file.rewrite
|
41
|
+
file.rewrite(comment_format)
|
39
42
|
end
|
40
43
|
end
|
41
44
|
end
|
data/lib/rbs/trace/file.rb
CHANGED
@@ -27,11 +27,11 @@ module RBS
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
# @rbs () -> String
|
31
|
-
def with_rbs
|
30
|
+
# @rbs (?Symbol?) -> String
|
31
|
+
def with_rbs(comment_format = nil)
|
32
32
|
result = Prism.parse_file(@path)
|
33
33
|
comments = {} #: Hash[Integer, String]
|
34
|
-
result.value.accept(InlineCommentVisitor.new(@decls, comments))
|
34
|
+
result.value.accept(InlineCommentVisitor.new(@decls, comments, comment_format))
|
35
35
|
|
36
36
|
lines = result.source.source.lines
|
37
37
|
comments.keys.sort.reverse_each do |i|
|
@@ -42,9 +42,9 @@ module RBS
|
|
42
42
|
lines.join
|
43
43
|
end
|
44
44
|
|
45
|
-
# @rbs () -> void
|
46
|
-
def rewrite
|
47
|
-
::File.write(@path, with_rbs)
|
45
|
+
# @rbs (?Symbol?) -> void
|
46
|
+
def rewrite(comment_format = nil)
|
47
|
+
::File.write(@path, with_rbs(comment_format))
|
48
48
|
end
|
49
49
|
|
50
50
|
# @rbs () -> String
|
@@ -3,10 +3,11 @@
|
|
3
3
|
module RBS
|
4
4
|
class Trace
|
5
5
|
class InlineCommentVisitor < Prism::Visitor
|
6
|
-
# @rbs (Hash[TypeName, AST::Declarations::t], Hash[Integer, String]) -> void
|
7
|
-
def initialize(decls, comments)
|
6
|
+
# @rbs (Hash[TypeName, AST::Declarations::t], Hash[Integer, String], Symbol?) -> void
|
7
|
+
def initialize(decls, comments, comment_format)
|
8
8
|
@decls = decls
|
9
9
|
@comments = comments
|
10
|
+
@comment_prefix = comment_format == :rbs_colon ? "#:" : "# @rbs"
|
10
11
|
@context = [] #: Array[Symbol]
|
11
12
|
|
12
13
|
super()
|
@@ -38,7 +39,7 @@ module RBS
|
|
38
39
|
overloads = OverloadCompact.new(member.overloads).call
|
39
40
|
comment = overloads.map(&:method_type).join(" | ")
|
40
41
|
|
41
|
-
@comments[lineno] = "#{indent}#
|
42
|
+
@comments[lineno] = "#{indent}#{@comment_prefix} #{comment}\n"
|
42
43
|
end
|
43
44
|
|
44
45
|
super
|
data/lib/rbs/trace/version.rb
CHANGED
data/lib/rbs/trace.rb
CHANGED
@@ -50,10 +50,10 @@ module RBS
|
|
50
50
|
@files ||= {}
|
51
51
|
end
|
52
52
|
|
53
|
-
# @rbs () -> void
|
54
|
-
def save_comments
|
53
|
+
# @rbs (?Symbol) -> void
|
54
|
+
def save_comments(comment_format = nil)
|
55
55
|
files.each do |path, file|
|
56
|
-
file.rewrite if @paths.include?(path)
|
56
|
+
file.rewrite(comment_format) if @paths.include?(path)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -62,6 +62,11 @@ module RBS
|
|
62
62
|
files.each_value { |file| file.save_rbs(out_dir) }
|
63
63
|
end
|
64
64
|
|
65
|
+
# @rbs (Hash[String, Integer]) -> Hash[String, Integer]
|
66
|
+
def add_generics_size!(additional_generics_size)
|
67
|
+
builder.generics_size.merge!(additional_generics_size)
|
68
|
+
end
|
69
|
+
|
65
70
|
private
|
66
71
|
|
67
72
|
# @rbs () -> Array[String]
|
data/rbs_collection.lock.yaml
CHANGED
@@ -6,7 +6,7 @@ gems:
|
|
6
6
|
source:
|
7
7
|
type: git
|
8
8
|
name: ruby/gem_rbs_collection
|
9
|
-
revision:
|
9
|
+
revision: 1e026936df951c269b64b7cba278132b0af42828
|
10
10
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
11
11
|
repo_dir: gems
|
12
12
|
- name: fileutils
|
@@ -42,17 +42,25 @@ gems:
|
|
42
42
|
source:
|
43
43
|
type: git
|
44
44
|
name: ruby/gem_rbs_collection
|
45
|
-
revision:
|
45
|
+
revision: 1e026936df951c269b64b7cba278132b0af42828
|
46
46
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
47
47
|
repo_dir: gems
|
48
48
|
- name: rbs
|
49
|
-
version: 3.
|
49
|
+
version: 3.9.3
|
50
50
|
source:
|
51
51
|
type: rubygems
|
52
52
|
- name: rdoc
|
53
53
|
version: '0'
|
54
54
|
source:
|
55
55
|
type: stdlib
|
56
|
+
- name: simplecov
|
57
|
+
version: '0.22'
|
58
|
+
source:
|
59
|
+
type: git
|
60
|
+
name: ruby/gem_rbs_collection
|
61
|
+
revision: 1e026936df951c269b64b7cba278132b0af42828
|
62
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
63
|
+
repo_dir: gems
|
56
64
|
- name: tsort
|
57
65
|
version: '0'
|
58
66
|
source:
|
@@ -9,7 +9,7 @@ module RBS
|
|
9
9
|
|
10
10
|
UNBOUND_NAME_METHOD: untyped
|
11
11
|
|
12
|
-
|
12
|
+
DEFAULT_GENERICS_SIZE: Hash[String, Integer]
|
13
13
|
|
14
14
|
# @rbs (bind: Binding, parameters: Array[__todo__], void: bool) -> Array[__todo__]
|
15
15
|
def method_call: (bind: Binding, parameters: Array[__todo__], void: bool) -> Array[__todo__]
|
@@ -17,6 +17,9 @@ module RBS
|
|
17
17
|
# @rbs (__todo__) -> AST::Members::MethodDefinition::Overload
|
18
18
|
def method_return: (__todo__) -> AST::Members::MethodDefinition::Overload
|
19
19
|
|
20
|
+
# @rbs () -> Hash[String, Integer]
|
21
|
+
def generics_size: () -> Hash[String, Integer]
|
22
|
+
|
20
23
|
private
|
21
24
|
|
22
25
|
def stack_traces: () -> untyped
|
@@ -11,11 +11,11 @@ module RBS
|
|
11
11
|
# @rbs (untyped, Class, Symbol) -> AST::Members::MethodDefinition?
|
12
12
|
def find_or_new_method_definition: (untyped, Class, Symbol) -> AST::Members::MethodDefinition?
|
13
13
|
|
14
|
-
# @rbs () -> String
|
15
|
-
def with_rbs: () -> String
|
14
|
+
# @rbs (?Symbol?) -> String
|
15
|
+
def with_rbs: (?Symbol?) -> String
|
16
16
|
|
17
|
-
# @rbs () -> void
|
18
|
-
def rewrite: () -> void
|
17
|
+
# @rbs (?Symbol?) -> void
|
18
|
+
def rewrite: (?Symbol?) -> void
|
19
19
|
|
20
20
|
# @rbs () -> String
|
21
21
|
def to_rbs: () -> String
|
@@ -3,8 +3,8 @@
|
|
3
3
|
module RBS
|
4
4
|
class Trace
|
5
5
|
class InlineCommentVisitor < Prism::Visitor
|
6
|
-
# @rbs (Hash[TypeName, AST::Declarations::t], Hash[Integer, String]) -> void
|
7
|
-
def initialize: (Hash[TypeName, AST::Declarations::t], Hash[Integer, String]) -> void
|
6
|
+
# @rbs (Hash[TypeName, AST::Declarations::t], Hash[Integer, String], Symbol?) -> void
|
7
|
+
def initialize: (Hash[TypeName, AST::Declarations::t], Hash[Integer, String], Symbol?) -> void
|
8
8
|
|
9
9
|
# @rbs override
|
10
10
|
# @rbs (Prism::Node) -> void
|
data/sig/generated/rbs/trace.rbs
CHANGED
@@ -23,12 +23,15 @@ module RBS
|
|
23
23
|
# @rbs () -> Hash[String, File]
|
24
24
|
def files: () -> Hash[String, File]
|
25
25
|
|
26
|
-
# @rbs () -> void
|
27
|
-
def save_comments: () -> void
|
26
|
+
# @rbs (?Symbol) -> void
|
27
|
+
def save_comments: (?Symbol) -> void
|
28
28
|
|
29
29
|
# @rbs (out_dir: String) -> void
|
30
30
|
def save_files: (out_dir: String) -> void
|
31
31
|
|
32
|
+
# @rbs (Hash[String, Integer]) -> Hash[String, Integer]
|
33
|
+
def add_generics_size!: (Hash[String, Integer]) -> Hash[String, Integer]
|
34
|
+
|
32
35
|
private
|
33
36
|
|
34
37
|
# @rbs () -> Array[String]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbs-trace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takumi Shotoku
|
@@ -47,6 +47,7 @@ executables:
|
|
47
47
|
extensions: []
|
48
48
|
extra_rdoc_files: []
|
49
49
|
files:
|
50
|
+
- ".devcontainer/devcontainer.json"
|
50
51
|
- ".rspec"
|
51
52
|
- ".rubocop.yml"
|
52
53
|
- CHANGELOG.md
|
@@ -88,8 +89,8 @@ licenses:
|
|
88
89
|
- MIT
|
89
90
|
metadata:
|
90
91
|
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.
|
92
|
+
source_code_uri: https://github.com/sinsoku/rbs-trace/tree/v0.7.0
|
93
|
+
changelog_uri: https://github.com/sinsoku/rbs-trace/blob/v0.7.0/CHANGELOG.md
|
93
94
|
rubygems_mfa_required: 'true'
|
94
95
|
rdoc_options: []
|
95
96
|
require_paths:
|
@@ -105,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
106
|
- !ruby/object:Gem::Version
|
106
107
|
version: '0'
|
107
108
|
requirements: []
|
108
|
-
rubygems_version: 3.6.
|
109
|
+
rubygems_version: 3.6.9
|
109
110
|
specification_version: 4
|
110
111
|
summary: Automatically Insert inline RBS type declarations using runtime information.
|
111
112
|
test_files: []
|