rbs-trace 0.5.0 → 0.6.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 +1 -1
- data/CHANGELOG.md +9 -0
- data/README.md +19 -0
- 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 +23 -9
- data/lib/rbs/trace/version.rb +1 -1
- data/lib/rbs/trace.rb +3 -3
- data/rbs_collection.lock.yaml +11 -3
- data/sig/generated/rbs/trace/file.rbs +4 -4
- data/sig/generated/rbs/trace/inline_comment_visitor.rbs +5 -2
- data/sig/generated/rbs/trace.rbs +2 -2
- 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: 8a25eb287a611f0c087e0419da03b0d45b53735e3e1bfa9bbcf9018940f640a1
|
4
|
+
data.tar.gz: 70591151052c0e0695b3584b31551e0251987f8cc9b5c5c635db741d4b44c0d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3fd0ae96dc471248170fd72d639fc338026e7ecba577db2d3be8096652c9e28e9df4a1cf9c012a976da6951dcb0bbbcb12444d029206f9ac3384b9374538165
|
7
|
+
data.tar.gz: 204295de73d9fee188d8c5568546b09bd295173937b9037f1e957f7a4b2952af502b2a58ce2fc01927e29bdeeb866e8950d3b9549cf3f4960759e94d745f5a2f
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.6.0] - 2025-05-12
|
4
|
+
|
5
|
+
- feat: Support inline comments using colon-prefixed RBS syntax
|
6
|
+
- chore: Update gem dependencies
|
7
|
+
|
8
|
+
## [0.5.1] - 2025-04-20
|
9
|
+
|
10
|
+
- fix: Support nested modules defined with `::`
|
11
|
+
|
3
12
|
## [0.5.0] - 2025-03-30
|
4
13
|
|
5
14
|
- feat: Add paths to control trace targets
|
data/README.md
CHANGED
@@ -114,6 +114,25 @@ 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
|
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()
|
@@ -15,17 +16,17 @@ module RBS
|
|
15
16
|
# @rbs override
|
16
17
|
# @rbs (Prism::Node) -> void
|
17
18
|
def visit_class_node(node)
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
with_context node do
|
20
|
+
super
|
21
|
+
end
|
21
22
|
end
|
22
23
|
|
23
24
|
# @rbs override
|
24
25
|
# @rbs (Prism::Node) -> void
|
25
26
|
def visit_module_node(node)
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
with_context node do
|
28
|
+
super
|
29
|
+
end
|
29
30
|
end
|
30
31
|
|
31
32
|
# @rbs override
|
@@ -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
|
@@ -58,6 +59,19 @@ module RBS
|
|
58
59
|
member.is_a?(AST::Members::MethodDefinition) && member.name == name
|
59
60
|
end
|
60
61
|
end
|
62
|
+
|
63
|
+
# @rbs (Prism::ModuleNode | Prism::ClassNode) { () -> void } -> void
|
64
|
+
def with_context(node)
|
65
|
+
constant_path = node.constant_path
|
66
|
+
raise if constant_path.is_a?(Prism::MissingNode) || constant_path.is_a?(Prism::CallNode)
|
67
|
+
|
68
|
+
names = constant_path.full_name_parts
|
69
|
+
@context.push(*names)
|
70
|
+
|
71
|
+
yield
|
72
|
+
|
73
|
+
@context.pop(names.size)
|
74
|
+
end
|
61
75
|
end
|
62
76
|
end
|
63
77
|
end
|
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
|
|
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:
|
@@ -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
|
@@ -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
@@ -23,8 +23,8 @@ 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
|
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.6.0
|
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.6.0
|
92
|
+
changelog_uri: https://github.com/sinsoku/rbs-trace/blob/v0.6.0/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: []
|