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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef229a0a3efd1a66cdc57652ef80b173d19311652f376422a06bad6d61d3c7b5
4
- data.tar.gz: 364bff243f157949a91b88c936a953e88cf275589312c664df1a9f6cc2d89c40
3
+ metadata.gz: be7a77838d494748f9f51925c7d26a78a70aee45fb143942b71630c79fa31518
4
+ data.tar.gz: 67ad4d7de09a5a558924e609894dc19c9e2266f7b3f311008e8300f7d41c43e8
5
5
  SHA512:
6
- metadata.gz: ad22a7fbeff8115b185977f5d21bfdbd51b53485f1e1896dc0e692fccbf6e8de82b90f499e3702343dbb579798cbe86b4ad871926aa8089763d4e1599d9c29e2
7
- data.tar.gz: 2850321317aa8b97317f315b4dce55af70330c724cd279dadbd5f8b0c8f9edc3e4305dbfaeca0aa85365123caa1772b4bb7137487df4b7fbf6c9b6d9ab66c7aa
6
+ metadata.gz: 632f15418e48dca1b7a4f5202665a1b9248720ea267b6f49de41e3b8c3696ac3bc23f6010e22b3e9be8a551b593db3310be8ce6a93b27170590fd83c3b814637
7
+ data.tar.gz: 86fda57bc6b66c158b7c67c9b58dcc9f9bb4d13433204e0587e60338f8220aea9a52b386025ca48ab20eee27954b5779a2b54ab9382a05ad243918c5281610bf
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RBS
4
4
  class Patch
5
- VERSION = "0.1.4"
5
+ VERSION = "0.1.6"
6
6
  end
7
7
  end
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
- if target
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
- if index
112
- # steep:ignore:start
113
- decl = decl.update(location: target[index].location.dup) if decl.respond_to?(:update) # rubocop:disable Style/RedundantSelfAssignment
114
- # steep:ignore:end
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
- if index
120
- # steep:ignore:start
121
- decl = decl.update(location: target[index].location.dup) if decl.respond_to?(:update) # rubocop:disable Style/RedundantSelfAssignment
122
- # steep:ignore:end
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 walk: (Array[t] decls, ?Array[String] name_stack) { (::RBS::AST::Declarations::t | ::RBS::AST::Members::t, String) -> void } -> void
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
 
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
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koji NAKAMURA