rbs-patch 0.1.4 → 0.1.6
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/lib/rbs/patch/version.rb +1 -1
- data/lib/rbs/patch.rb +66 -15
- data/sig/rbs/patch.rbs +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: be7a77838d494748f9f51925c7d26a78a70aee45fb143942b71630c79fa31518
|
|
4
|
+
data.tar.gz: 67ad4d7de09a5a558924e609894dc19c9e2266f7b3f311008e8300f7d41c43e8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 632f15418e48dca1b7a4f5202665a1b9248720ea267b6f49de41e3b8c3696ac3bc23f6010e22b3e9be8a551b593db3310be8ce6a93b27170590fd83c3b814637
|
|
7
|
+
data.tar.gz: 86fda57bc6b66c158b7c67c9b58dcc9f9bb4d13433204e0587e60338f8220aea9a52b386025ca48ab20eee27954b5779a2b54ab9382a05ad243918c5281610bf
|
data/lib/rbs/patch/version.rb
CHANGED
data/lib/rbs/patch.rb
CHANGED
|
@@ -74,6 +74,43 @@ module RBS
|
|
|
74
74
|
decl.members if decl.is_a?(::RBS::AST::Declarations::NestedDeclarationHelper)
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
+
def update(decl, location:)
|
|
78
|
+
if decl.respond_to?(:update)
|
|
79
|
+
# steep:ignore:start
|
|
80
|
+
decl.update(location:)
|
|
81
|
+
# steep:ignore:end
|
|
82
|
+
elsif decl.is_a?(AST::Declarations::Constant)
|
|
83
|
+
AST::Declarations::Constant.new(
|
|
84
|
+
name: decl.name, type: decl.type, location: location, comment: decl.comment, annotations: decl.annotations
|
|
85
|
+
)
|
|
86
|
+
elsif decl.is_a?(AST::Declarations::Global)
|
|
87
|
+
AST::Declarations::Global.new(
|
|
88
|
+
name: decl.name, type: decl.type, location: location, comment: decl.comment, annotations: decl.annotations
|
|
89
|
+
)
|
|
90
|
+
elsif decl.is_a?(AST::Declarations::TypeAlias)
|
|
91
|
+
AST::Declarations::TypeAlias.new(
|
|
92
|
+
name: decl.name, type_params: decl.type_params, type: decl.type, annotations: decl.annotations,
|
|
93
|
+
location: location, comment: decl.comment
|
|
94
|
+
)
|
|
95
|
+
elsif decl.is_a?(AST::Declarations::AliasDecl)
|
|
96
|
+
decl.class.new(
|
|
97
|
+
new_name: decl.new_name, old_name: decl.old_name, location: location, comment: decl.comment,
|
|
98
|
+
annotations: decl.annotations
|
|
99
|
+
)
|
|
100
|
+
elsif decl.is_a?(AST::Members::Mixin)
|
|
101
|
+
decl.class.new(
|
|
102
|
+
name: decl.name, args: decl.args, annotations: decl.annotations, location: location, comment: decl.comment
|
|
103
|
+
)
|
|
104
|
+
elsif decl.is_a?(AST::Members::Alias)
|
|
105
|
+
decl.class.new(
|
|
106
|
+
new_name: decl.new_name, old_name: decl.old_name, kind: decl.kind, annotations: decl.annotations,
|
|
107
|
+
location: location, comment: decl.comment
|
|
108
|
+
)
|
|
109
|
+
else
|
|
110
|
+
decl
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
77
114
|
def walk(decls, name_stack = [], &block)
|
|
78
115
|
decls.each do |decl|
|
|
79
116
|
name_stack << extract_name(decl)
|
|
@@ -104,29 +141,43 @@ module RBS
|
|
|
104
141
|
|
|
105
142
|
target = namespace.empty? ? @decls : extract_members(map[namespace])
|
|
106
143
|
|
|
107
|
-
|
|
144
|
+
unless target
|
|
145
|
+
@decls << decl # steep:ignore
|
|
146
|
+
return
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
if decl.is_a?(AST::Members::Var)
|
|
150
|
+
# AST::Members::Var does not support annotations.
|
|
151
|
+
index = target.rindex { |m| m.is_a?(decl.class) }
|
|
152
|
+
if index
|
|
153
|
+
decl = update(decl, location: target[index].location.dup)
|
|
154
|
+
target.insert(index + 1, decl)
|
|
155
|
+
else
|
|
156
|
+
index = target.find_index { |m| m.is_a?(AST::Members::MethodDefinition) }
|
|
157
|
+
if index
|
|
158
|
+
decl = update(decl, location: target[index].location.dup)
|
|
159
|
+
target.insert(index, decl)
|
|
160
|
+
else
|
|
161
|
+
target << decl
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
else
|
|
108
165
|
decl.annotations.delete_if { |a| process_annotations([a]) } # steep:ignore
|
|
109
166
|
if after
|
|
110
167
|
index = target.find_index { |m| extract_name(m) == after }
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
target.insert(index + 1, decl)
|
|
116
|
-
end
|
|
168
|
+
return unless index
|
|
169
|
+
|
|
170
|
+
decl = update(decl, location: target[index].location.dup)
|
|
171
|
+
target.insert(index + 1, decl)
|
|
117
172
|
elsif before
|
|
118
173
|
index = target.find_index { |m| extract_name(m) == before }
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
target.insert(index, decl)
|
|
124
|
-
end
|
|
174
|
+
return unless index
|
|
175
|
+
|
|
176
|
+
decl = update(decl, location: target[index].location.dup)
|
|
177
|
+
target.insert(index, decl)
|
|
125
178
|
else
|
|
126
179
|
target << decl
|
|
127
180
|
end
|
|
128
|
-
else
|
|
129
|
-
@decls << decl # steep:ignore
|
|
130
181
|
end
|
|
131
182
|
end
|
|
132
183
|
|
data/sig/rbs/patch.rbs
CHANGED
|
@@ -26,7 +26,9 @@ module RBS
|
|
|
26
26
|
|
|
27
27
|
def extract_members: (t decl) -> (Array[::RBS::AST::Declarations::Class::member] | Array[::RBS::AST::Declarations::Module::member] | nil)
|
|
28
28
|
|
|
29
|
-
def
|
|
29
|
+
def update: (t decl, location: untyped) -> t
|
|
30
|
+
|
|
31
|
+
def walk: (Array[t] decls, ?Array[String] name_stack) { (t, String) -> void } -> void
|
|
30
32
|
|
|
31
33
|
def decl_map: () -> Hash[String, t]
|
|
32
34
|
|