rbs-patch 0.1.6 → 0.1.7
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/README.md +39 -0
- data/Steepfile +1 -0
- data/lib/rbs/patch/version.rb +1 -1
- data/lib/rbs/patch.rb +40 -14
- data/sig/generated/rbs/patch.rbs +59 -0
- data/sig/rbs/patch.rbs +0 -38
- data/typeprof.conf.jsonc +6 -0
- metadata +8 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 84022bf98bc54075dedb17f137e45f0a1f7571146987d4efc899fe65a4c71d46
|
|
4
|
+
data.tar.gz: 6743bda0891b9fee83b1dcd39b795d69cda6d75f6a47a342e4c4c6819affd900
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f1280e5b1e1cce06a9af9ca899d95c8896d5c14f21c0e0e46e5ac59b09795da27f78b425efe5cff1900f566612883851f48e78696eaf9d3fb3dc93ea2fde7866
|
|
7
|
+
data.tar.gz: 35be3d68b8dcdc4ab10ac4999adf87e1b17662d68f583c9084cbf1ead2325da84ca0ebc7825430d5939722dcf72c29e12da8ba8076ddf4af1b7de81920800e62
|
data/README.md
CHANGED
|
@@ -143,6 +143,45 @@ class Guest
|
|
|
143
143
|
end # Inserts Guest class before User class
|
|
144
144
|
```
|
|
145
145
|
|
|
146
|
+
### Comment Handling in `override`
|
|
147
|
+
|
|
148
|
+
When `override` replaces a method, class, or module, the comment on the two sides is merged rather than always taken from one side:
|
|
149
|
+
|
|
150
|
+
- If the overriding declaration has a comment, it replaces the original comment.
|
|
151
|
+
- If the overriding declaration has no comment, the original comment (if any) is kept.
|
|
152
|
+
|
|
153
|
+
```ruby
|
|
154
|
+
p.apply(<<~RBS)
|
|
155
|
+
class User
|
|
156
|
+
# The user's display name.
|
|
157
|
+
def name: () -> String
|
|
158
|
+
end
|
|
159
|
+
RBS
|
|
160
|
+
|
|
161
|
+
p.apply(<<~RBS)
|
|
162
|
+
class User
|
|
163
|
+
%a{patch:override}
|
|
164
|
+
def name: () -> String? # No comment here, so the original one is kept
|
|
165
|
+
end
|
|
166
|
+
RBS
|
|
167
|
+
|
|
168
|
+
# Result:
|
|
169
|
+
# class User
|
|
170
|
+
# # The user's display name.
|
|
171
|
+
# def name: () -> String?
|
|
172
|
+
# end
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
There is currently no way to explicitly clear an existing comment through `override` — omitting the comment always keeps the original one.
|
|
176
|
+
|
|
177
|
+
> **Note:** In RBS syntax, a comment must be written *before* the annotation, not after it:
|
|
178
|
+
>
|
|
179
|
+
> ```ruby
|
|
180
|
+
> # This comment is attached to the method
|
|
181
|
+
> %a{patch:override}
|
|
182
|
+
> def name: () -> String?
|
|
183
|
+
> ```
|
|
184
|
+
|
|
146
185
|
### Working with Nested Modules
|
|
147
186
|
|
|
148
187
|
Operations work correctly within nested module structures:
|
data/Steepfile
CHANGED
data/lib/rbs/patch/version.rb
CHANGED
data/lib/rbs/patch.rb
CHANGED
|
@@ -6,15 +6,21 @@ require_relative "patch/version"
|
|
|
6
6
|
|
|
7
7
|
module RBS
|
|
8
8
|
class Patch # rubocop:disable Style/Documentation
|
|
9
|
+
# @rbs! type t = ::RBS::AST::Declarations::t | ::RBS::AST::Members::t
|
|
10
|
+
|
|
9
11
|
ANNOTATION_OVERRIDE = "patch:override"
|
|
10
12
|
ANNOTATION_DELETE = "patch:delete"
|
|
11
13
|
ANNOTATION_APPEND_AFTER = /\Apatch:append_after\((.*)\)\Z/
|
|
12
14
|
ANNOTATION_PREPEND_BEFORE = /\Apatch:prepend_before\((.*)\)\Z/
|
|
13
15
|
|
|
16
|
+
# @rbs @decls: Array[::RBS::AST::Declarations::t]
|
|
17
|
+
|
|
18
|
+
#: -> void
|
|
14
19
|
def initialize
|
|
15
20
|
@decls = []
|
|
16
21
|
end
|
|
17
22
|
|
|
23
|
+
#: -> String
|
|
18
24
|
def to_s
|
|
19
25
|
io = ::StringIO.new
|
|
20
26
|
::RBS::Writer.new(out: io).write(@decls)
|
|
@@ -22,6 +28,7 @@ module RBS
|
|
|
22
28
|
io.read || ""
|
|
23
29
|
end
|
|
24
30
|
|
|
31
|
+
#: (?untyped? String, ?path: Pathname?) -> void
|
|
25
32
|
def apply(source = nil, path: nil)
|
|
26
33
|
unless path.nil?
|
|
27
34
|
files = Set[]
|
|
@@ -55,6 +62,7 @@ module RBS
|
|
|
55
62
|
|
|
56
63
|
private
|
|
57
64
|
|
|
65
|
+
#: (t decl) -> String
|
|
58
66
|
def extract_name(decl)
|
|
59
67
|
if decl.is_a?(::RBS::AST::Declarations::AliasDecl) # rubocop:disable Style/CaseLikeIf
|
|
60
68
|
decl.new_name.to_s
|
|
@@ -70,47 +78,51 @@ module RBS
|
|
|
70
78
|
end
|
|
71
79
|
end
|
|
72
80
|
|
|
81
|
+
#: (t decl) -> (Array[AST::Declarations::Class::member] | Array[AST::Declarations::Module::member] | nil)
|
|
73
82
|
def extract_members(decl)
|
|
74
83
|
decl.members if decl.is_a?(::RBS::AST::Declarations::NestedDeclarationHelper)
|
|
75
84
|
end
|
|
76
85
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
decl.update(location:)
|
|
81
|
-
# steep:ignore:end
|
|
82
|
-
elsif decl.is_a?(AST::Declarations::Constant)
|
|
86
|
+
#: (t decl, ?location: untyped, ?comment: untyped) -> t
|
|
87
|
+
def update(decl, location: decl.location, comment: nil)
|
|
88
|
+
if decl.is_a?(AST::Declarations::Constant) # rubocop:disable Style/CaseLikeIf
|
|
83
89
|
AST::Declarations::Constant.new(
|
|
84
|
-
name: decl.name, type: decl.type, location: location, comment:
|
|
90
|
+
name: decl.name, type: decl.type, location: location, comment: comment || decl.comment,
|
|
91
|
+
annotations: decl.annotations
|
|
85
92
|
)
|
|
86
93
|
elsif decl.is_a?(AST::Declarations::Global)
|
|
87
94
|
AST::Declarations::Global.new(
|
|
88
|
-
name: decl.name, type: decl.type, location: location, comment:
|
|
95
|
+
name: decl.name, type: decl.type, location: location, comment: comment || decl.comment,
|
|
96
|
+
annotations: decl.annotations
|
|
89
97
|
)
|
|
90
98
|
elsif decl.is_a?(AST::Declarations::TypeAlias)
|
|
91
99
|
AST::Declarations::TypeAlias.new(
|
|
92
100
|
name: decl.name, type_params: decl.type_params, type: decl.type, annotations: decl.annotations,
|
|
93
|
-
location: location, comment: decl.comment
|
|
101
|
+
location: location, comment: comment || decl.comment
|
|
94
102
|
)
|
|
95
103
|
elsif decl.is_a?(AST::Declarations::AliasDecl)
|
|
96
104
|
decl.class.new(
|
|
97
|
-
new_name: decl.new_name, old_name: decl.old_name, location: location, comment: decl.comment,
|
|
105
|
+
new_name: decl.new_name, old_name: decl.old_name, location: location, comment: comment || decl.comment,
|
|
98
106
|
annotations: decl.annotations
|
|
99
107
|
)
|
|
100
108
|
elsif decl.is_a?(AST::Members::Mixin)
|
|
101
109
|
decl.class.new(
|
|
102
|
-
name: decl.name, args: decl.args, annotations: decl.annotations, location: location,
|
|
110
|
+
name: decl.name, args: decl.args, annotations: decl.annotations, location: location,
|
|
111
|
+
comment: comment || decl.comment
|
|
103
112
|
)
|
|
104
113
|
elsif decl.is_a?(AST::Members::Alias)
|
|
105
114
|
decl.class.new(
|
|
106
115
|
new_name: decl.new_name, old_name: decl.old_name, kind: decl.kind, annotations: decl.annotations,
|
|
107
|
-
location: location, comment: decl.comment
|
|
116
|
+
location: location, comment: comment || decl.comment
|
|
108
117
|
)
|
|
109
|
-
|
|
118
|
+
elsif decl.is_a?(AST::Members::Var) || decl.is_a?(AST::Members::LocationOnly)
|
|
110
119
|
decl
|
|
120
|
+
else
|
|
121
|
+
decl.update(location: location, comment: comment || decl.comment)
|
|
111
122
|
end
|
|
112
123
|
end
|
|
113
124
|
|
|
125
|
+
#: (Array[t] decls, ?Array[String] name_stack) { (t, String) -> void } -> void
|
|
114
126
|
def walk(decls, name_stack = [], &block)
|
|
115
127
|
decls.each do |decl|
|
|
116
128
|
name_stack << extract_name(decl)
|
|
@@ -125,6 +137,7 @@ module RBS
|
|
|
125
137
|
end
|
|
126
138
|
end
|
|
127
139
|
|
|
140
|
+
#: () -> Hash[String, t]
|
|
128
141
|
def decl_map
|
|
129
142
|
# @type var map: Hash[String, ::RBS::Patch::t]
|
|
130
143
|
map = {}
|
|
@@ -132,6 +145,7 @@ module RBS
|
|
|
132
145
|
map
|
|
133
146
|
end
|
|
134
147
|
|
|
148
|
+
#: (t decl, to: String, ?after: String?, ?before: String?) -> void
|
|
135
149
|
def add(decl, to:, after: nil, before: nil)
|
|
136
150
|
map = decl_map
|
|
137
151
|
return if map.key?(to)
|
|
@@ -142,7 +156,7 @@ module RBS
|
|
|
142
156
|
target = namespace.empty? ? @decls : extract_members(map[namespace])
|
|
143
157
|
|
|
144
158
|
unless target
|
|
145
|
-
@decls << decl
|
|
159
|
+
@decls << decl if decl.is_a?(AST::Declarations::Base)
|
|
146
160
|
return
|
|
147
161
|
end
|
|
148
162
|
|
|
@@ -181,10 +195,16 @@ module RBS
|
|
|
181
195
|
end
|
|
182
196
|
end
|
|
183
197
|
|
|
198
|
+
#: (String name, with: t) -> void
|
|
184
199
|
def override(name, with:)
|
|
185
200
|
map = decl_map
|
|
186
201
|
return unless map.key?(name)
|
|
187
202
|
|
|
203
|
+
old = map[name]
|
|
204
|
+
# No way to explicitly clear a comment via override: an override without a
|
|
205
|
+
# comment always keeps the overridden one. Revisit if that's ever needed.
|
|
206
|
+
with = update(with, comment: old.comment) if with.comment.nil? && old.comment # steep:ignore
|
|
207
|
+
|
|
188
208
|
sep = with.is_a?(::RBS::AST::Members::Base) ? "#" : "::"
|
|
189
209
|
namespace, _, name = name.rpartition(sep)
|
|
190
210
|
|
|
@@ -202,6 +222,7 @@ module RBS
|
|
|
202
222
|
with.annotations.delete_if { |a| process_annotations([a]) } # steep:ignore
|
|
203
223
|
end
|
|
204
224
|
|
|
225
|
+
#: (String name) -> void
|
|
205
226
|
def delete(name)
|
|
206
227
|
map = decl_map
|
|
207
228
|
return unless map.key?(name)
|
|
@@ -217,6 +238,11 @@ module RBS
|
|
|
217
238
|
end
|
|
218
239
|
end
|
|
219
240
|
|
|
241
|
+
# @rbs (Array[AST::Annotation] annotations) -> ([:override, nil]
|
|
242
|
+
# | [:delte, nil]
|
|
243
|
+
# | [:append_after, String]
|
|
244
|
+
# | [:prepend_before, String]
|
|
245
|
+
# | nil)
|
|
220
246
|
def process_annotations(annotations) # steep:ignore
|
|
221
247
|
if annotations.any? { |a| a.string == ANNOTATION_OVERRIDE }
|
|
222
248
|
[:override, nil]
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Generated from lib/rbs/patch.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module RBS
|
|
4
|
+
class Patch
|
|
5
|
+
type t = ::RBS::AST::Declarations::t | ::RBS::AST::Members::t
|
|
6
|
+
|
|
7
|
+
ANNOTATION_OVERRIDE: ::String
|
|
8
|
+
|
|
9
|
+
ANNOTATION_DELETE: ::String
|
|
10
|
+
|
|
11
|
+
ANNOTATION_APPEND_AFTER: ::Regexp
|
|
12
|
+
|
|
13
|
+
ANNOTATION_PREPEND_BEFORE: ::Regexp
|
|
14
|
+
|
|
15
|
+
@decls: Array[::RBS::AST::Declarations::t]
|
|
16
|
+
|
|
17
|
+
# : -> void
|
|
18
|
+
def initialize: () -> void
|
|
19
|
+
|
|
20
|
+
# : -> String
|
|
21
|
+
def to_s: () -> String
|
|
22
|
+
|
|
23
|
+
# : (?untyped? String, ?path: Pathname?) -> void
|
|
24
|
+
def apply: (?untyped? String, ?path: Pathname?) -> void
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
# : (t decl) -> String
|
|
29
|
+
def extract_name: (t decl) -> String
|
|
30
|
+
|
|
31
|
+
# : (t decl) -> (Array[AST::Declarations::Class::member] | Array[AST::Declarations::Module::member] | nil)
|
|
32
|
+
def extract_members: (t decl) -> (Array[AST::Declarations::Class::member] | Array[AST::Declarations::Module::member] | nil)
|
|
33
|
+
|
|
34
|
+
# : (t decl, ?location: untyped, ?comment: untyped) -> t
|
|
35
|
+
def update: (t decl, ?location: untyped, ?comment: untyped) -> t
|
|
36
|
+
|
|
37
|
+
# : (Array[t] decls, ?Array[String] name_stack) { (t, String) -> void } -> void
|
|
38
|
+
def walk: (Array[t] decls, ?Array[String] name_stack) { (t, String) -> void } -> void
|
|
39
|
+
|
|
40
|
+
# : () -> Hash[String, t]
|
|
41
|
+
def decl_map: () -> Hash[String, t]
|
|
42
|
+
|
|
43
|
+
# : (t decl, to: String, ?after: String?, ?before: String?) -> void
|
|
44
|
+
def add: (t decl, to: String, ?after: String?, ?before: String?) -> void
|
|
45
|
+
|
|
46
|
+
# : (String name, with: t) -> void
|
|
47
|
+
def override: (String name, with: t) -> void
|
|
48
|
+
|
|
49
|
+
# : (String name) -> void
|
|
50
|
+
def delete: (String name) -> void
|
|
51
|
+
|
|
52
|
+
# @rbs (Array[AST::Annotation] annotations) -> ([:override, nil]
|
|
53
|
+
# | [:delte, nil]
|
|
54
|
+
# | [:append_after, String]
|
|
55
|
+
# | [:prepend_before, String]
|
|
56
|
+
# | nil)
|
|
57
|
+
def process_annotations: (Array[AST::Annotation] annotations) -> ([ :override, nil ] | [ :delte, nil ] | [ :append_after, String ] | [ :prepend_before, String ] | nil)
|
|
58
|
+
end
|
|
59
|
+
end
|
data/sig/rbs/patch.rbs
CHANGED
|
@@ -1,43 +1,5 @@
|
|
|
1
1
|
module RBS
|
|
2
2
|
class Patch
|
|
3
3
|
VERSION: String
|
|
4
|
-
|
|
5
|
-
@decls: ::Array[::RBS::AST::Declarations::t]
|
|
6
|
-
|
|
7
|
-
ANNOTATION_OVERRIDE: "patch:override"
|
|
8
|
-
|
|
9
|
-
ANNOTATION_DELETE: "patch:delete"
|
|
10
|
-
|
|
11
|
-
ANNOTATION_APPEND_AFTER: ::Regexp
|
|
12
|
-
|
|
13
|
-
ANNOTATION_PREPEND_BEFORE: ::Regexp
|
|
14
|
-
|
|
15
|
-
def initialize: () -> void
|
|
16
|
-
|
|
17
|
-
def to_s: () -> String
|
|
18
|
-
|
|
19
|
-
def apply: (?untyped? String, ?path: Pathname?) -> void
|
|
20
|
-
|
|
21
|
-
type t = ::RBS::AST::Declarations::t | ::RBS::AST::Members::t
|
|
22
|
-
|
|
23
|
-
private
|
|
24
|
-
|
|
25
|
-
def extract_name: (t decl) -> String
|
|
26
|
-
|
|
27
|
-
def extract_members: (t decl) -> (Array[::RBS::AST::Declarations::Class::member] | Array[::RBS::AST::Declarations::Module::member] | nil)
|
|
28
|
-
|
|
29
|
-
def update: (t decl, location: untyped) -> t
|
|
30
|
-
|
|
31
|
-
def walk: (Array[t] decls, ?Array[String] name_stack) { (t, String) -> void } -> void
|
|
32
|
-
|
|
33
|
-
def decl_map: () -> Hash[String, t]
|
|
34
|
-
|
|
35
|
-
def add: (t decl, to: String, ?after: String?, ?before: String?) -> void
|
|
36
|
-
|
|
37
|
-
def override: (String name, with: t) -> void
|
|
38
|
-
|
|
39
|
-
def delete: (String name) -> void
|
|
40
|
-
|
|
41
|
-
def process_annotations: (Array[::RBS::AST::Annotation] annotations) -> ([:override, nil] | [:delte, nil] | [:append_after, String] | [:prepend_before, String] | nil)
|
|
42
4
|
end
|
|
43
5
|
end
|
data/typeprof.conf.jsonc
ADDED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rbs-patch
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Koji NAKAMURA
|
|
@@ -13,16 +13,16 @@ dependencies:
|
|
|
13
13
|
name: rbs
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
|
15
15
|
requirements:
|
|
16
|
-
- - "
|
|
16
|
+
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '
|
|
18
|
+
version: '0'
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
|
-
- - "
|
|
23
|
+
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '
|
|
25
|
+
version: '0'
|
|
26
26
|
description: RBS::Patch manages RBS (Ruby Signature) type definitions through patches.
|
|
27
27
|
It applies incremental changes to existing RBS signatures.
|
|
28
28
|
email:
|
|
@@ -39,7 +39,9 @@ files:
|
|
|
39
39
|
- exe/rbs-patch
|
|
40
40
|
- lib/rbs/patch.rb
|
|
41
41
|
- lib/rbs/patch/version.rb
|
|
42
|
+
- sig/generated/rbs/patch.rbs
|
|
42
43
|
- sig/rbs/patch.rbs
|
|
44
|
+
- typeprof.conf.jsonc
|
|
43
45
|
homepage: https://github.com/kozy4324/rbs-patch
|
|
44
46
|
licenses:
|
|
45
47
|
- MIT
|
|
@@ -63,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
63
65
|
- !ruby/object:Gem::Version
|
|
64
66
|
version: '0'
|
|
65
67
|
requirements: []
|
|
66
|
-
rubygems_version: 4.0.
|
|
68
|
+
rubygems_version: 4.0.14
|
|
67
69
|
specification_version: 4
|
|
68
70
|
summary: RBS::Patch manages RBS type definitions through patches.
|
|
69
71
|
test_files: []
|