orthoses 1.9.0 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd4d2682b08812b2f8fa633aa299702d38fd509439e4e2ac0b8751a64358b32a
4
- data.tar.gz: 28118eed7d772c490670f83277ccdabc4d2938ca329f5051f8aebd40be1f08a6
3
+ metadata.gz: 7a6942bb06928e29ae619e8dfd3f92ac603bda3d0feda99dafd309c4eb493327
4
+ data.tar.gz: 6affe9ebc4d0b1a3ec31c9192e271ee6a2b35765ad6c753c58fc2310fb6155ae
5
5
  SHA512:
6
- metadata.gz: 1f4262320cb3d9ef5304cbdb53af7cb0e0895bac03e7d98697cf38fc73dabc25b579c6fd4a213ae5c0d97d1763f88dabde2f7f1e6455a084c424ef6b042a3acb
7
- data.tar.gz: 35e2b8378b602ad6b853ba7f543d807aab514d0f2a7d8b931230912084d40c7222e45d09cfe4b3eddd614f62bcce578cac2b6e14dac08f5578089ecbb7d7895c
6
+ metadata.gz: 7e5f33fe35dc796660ea45096401a2157ec32ac19ead7af5ead38d4ab96fb40e28a4c266726bf4c0d6769cd8cfa0d6064501c18e99bbcceb1bdb2b929f610eb1
7
+ data.tar.gz: 8adf74dc954206d5e517cf6d0151cf50500375c9363ede9305c90a0989724f61d956b07daf6a17ebe8f1018912245474e10fa944ba4ecbbda4c927a6253eb0ff
@@ -33,10 +33,14 @@ module Orthoses
33
33
  end
34
34
 
35
35
  def <<(decl)
36
- @load_env << decl
37
- @known_env << decl
38
- rescue RBS::DuplicatedDeclarationError => err
39
- Orthoses.logger.warn(err.inspect)
36
+ begin
37
+ @load_env << decl
38
+ @known_env << decl
39
+ rescue RBS::DuplicatedDeclarationError => err
40
+ Orthoses.logger.warn(err.inspect)
41
+ end
42
+
43
+ self
40
44
  end
41
45
 
42
46
  def write_to(store:)
@@ -58,9 +62,13 @@ module Orthoses
58
62
  content = Content.new(name: name)
59
63
  content.comment = m_entry.primary.decl.comment&.string&.gsub(/^/, "# ")
60
64
  content.header = header_builder.build(entry: m_entry, name_hint: name)
61
- decls_to_lines(m_entry.decls.map(&:decl)).each do |line|
65
+ decls = m_entry.decls.map(&:decl)
66
+ decls_to_lines(decls).each do |line|
62
67
  content << line
63
68
  end
69
+ detect_mixin_and_build_content(decls).each do |mixin_content|
70
+ yield mixin_content
71
+ end
64
72
  yield content
65
73
  end
66
74
 
@@ -92,6 +100,14 @@ module Orthoses
92
100
  end
93
101
  end
94
102
 
103
+ def detect_mixin_and_build_content(decls)
104
+ decls.flat_map do |decl|
105
+ decl.members.grep(RBS::AST::Members::Mixin).map do |decl|
106
+ Content.new(name: decl.name.relative!.to_s)
107
+ end
108
+ end
109
+ end
110
+
95
111
  def decls_to_lines(decls)
96
112
  out = StringIO.new
97
113
  writer = RBS::Writer.new(out: out)
@@ -115,16 +115,16 @@ module Orthoses
115
115
  def build_super_class(val)
116
116
  return nil unless val.superclass && val.superclass != Object
117
117
 
118
+ super_module_name = Utils.module_name(val.superclass)
119
+ return nil unless super_module_name
120
+
118
121
  begin
119
122
  # check private const
120
- eval(val.superclass.to_s)
123
+ eval("::#{val.superclass.to_s}")
121
124
  rescue NameError
122
125
  return nil
123
126
  end
124
127
 
125
- super_module_name = Utils.module_name(val.superclass)
126
- return nil unless super_module_name
127
-
128
128
  # https://github.com/ruby/rbs/pull/977
129
129
  return nil unless super_module_name != "Random::Base"
130
130
 
@@ -144,6 +144,7 @@ module Orthoses
144
144
  @outs
145
145
  end
146
146
  end
147
+ private_constant :ArrayIO
147
148
 
148
149
  def decl_to_lines(decl)
149
150
  out = ArrayIO.new
@@ -162,11 +163,23 @@ module Orthoses
162
163
  end
163
164
 
164
165
  def uniqed_body_decl
165
- buffer = RBS::Buffer.new(
166
- name: "orthoses/content.rb",
167
- content: original_rbs
168
- )
169
- _, _, parsed_decls = RBS::Parser.parse_signature(buffer)
166
+ parsed_decls = begin
167
+ parse(original_rbs)
168
+ rescue RBS::ParsingError => e
169
+ begin
170
+ # retry with escape
171
+ Orthoses.logger.debug "Try to parse original rbs but ParsingError"
172
+ Orthoses.logger.debug e.message
173
+ Orthoses.logger.debug "```rbs\n#{original_rbs}```"
174
+ parse(escaped_rbs)
175
+ rescue RBS::ParsingError
176
+ # giveup
177
+ Orthoses.logger.error "Try to parse escaped rbs"
178
+ Orthoses.logger.error "```rbs\n#{escaped_rbs}```"
179
+ raise
180
+ end
181
+ end
182
+
170
183
  unless parsed_decls.length == 1
171
184
  raise "expect decls.length == 1, but got #{parsed_decls.length}"
172
185
  end
@@ -174,9 +187,20 @@ module Orthoses
174
187
  parsed_decl.tap do |decl|
175
188
  DuplicationChecker.new(decl).update_decl
176
189
  end
177
- rescue RBS::ParsingError
178
- Orthoses.logger.error "```rbs\n#{original_rbs}```"
179
- raise
190
+ end
191
+
192
+ def escaped_rbs
193
+ rbs = original_rbs
194
+ rbs.gsub!(/def\s*(self\??\.)?(.+?):/) { "def #{$1}`#{$2}`:" }
195
+ rbs.gsub!(/alias\s*(self\.)?(.+?)\s+(self\.)?(.+)$/) { "alias #{$1}`#{$2}` #{$3}`#{$4}`" }
196
+ rbs.gsub!(/attr_(reader|writer|accessor)\s*(self\.)?(.+)\s*:\s*(.+)$/) { "attr_#{$1} #{$2}`#{$3}`: #{$4}" }
197
+ rbs
198
+ end
199
+
200
+ def parse(rbs)
201
+ rbs.then { |wraped| RBS::Buffer.new(name: "orthoses/content.rb", content: rbs) }
202
+ .then { |buffer| RBS::Parser.parse_signature(buffer) }
203
+ .then { |_, _, decls| decls }
180
204
  end
181
205
 
182
206
  def temporary_type_params(name)
@@ -32,7 +32,8 @@ module Orthoses
32
32
  end
33
33
  ::Module.prepend MethodAddedHook
34
34
 
35
- module SignletonMethodAddedHook
35
+ class ::BasicObject
36
+ undef singleton_method_added
36
37
  def singleton_method_added(id)
37
38
  begin
38
39
  if h = SINGLETON_METHOD_ADDED_HOOKS[id]
@@ -42,10 +43,8 @@ module Orthoses
42
43
  end
43
44
  rescue TypeError => e
44
45
  end
45
- super
46
46
  end
47
47
  end
48
- ::BasicObject.prepend SignletonMethodAddedHook
49
48
 
50
49
  def enable(target: nil, &block)
51
50
  return super unless target.kind_of?(String)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Orthoses
4
- VERSION = "1.9.0"
4
+ VERSION = "1.11.0"
5
5
  end
@@ -10,13 +10,14 @@ class Orthoses::Content::Environment
10
10
  @attribute_filter: attribute_filter?
11
11
  def self.load_from_paths: (untyped paths) -> untyped
12
12
  def initialize: (?method_definition_filter: method_definition_filter?, ?alias_filter: alias_filter?, ?constant_filter: constant_filter?, ?mixin_filter: mixin_filter?, ?attribute_filter: attribute_filter?) -> void
13
- def <<: (RBS::AST::Declarations::t decl) -> RBS::Environment
13
+ def <<: (RBS::AST::Declarations::t decl) -> self
14
14
  def write_to: (store: Orthoses::store) -> void
15
15
  def each: () { (Orthoses::Content) -> void } -> void
16
16
  # Avoid `RBS::GenericParameterMismatchError` from like rbs_prototype_rb
17
17
  # class Array # <= RBS::GenericParameterMismatchError
18
18
  # end
19
19
  private def avoid_generic_parameter_mismatch_error: () -> untyped
20
+ private def detect_mixin_and_build_content: (untyped decls) -> untyped
20
21
  private def decls_to_lines: (untyped decls) -> untyped
21
22
  type method_definition_filter = ^(RBS::AST::Members::MethodDefinition) -> boolish
22
23
  type alias_filter = ^(RBS::AST::Members::Alias) -> boolish
@@ -21,6 +21,8 @@ class Orthoses::Content
21
21
  private def decl_to_lines: (untyped decl) -> untyped
22
22
  private def uniqed_body_string: () -> String
23
23
  private def uniqed_body_decl: () -> RBS::AST::Declarations::t
24
+ private def escaped_rbs: () -> untyped
25
+ private def parse: (untyped rbs) -> untyped
24
26
  private def temporary_type_params: (untyped name) -> untyped
25
27
  private def type_params: (untyped name) -> untyped
26
28
  attr_reader name: String
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orthoses
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-24 00:00:00.000000000 Z
11
+ date: 2023-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbs
@@ -101,7 +101,6 @@ files:
101
101
  - sig/orthoses/filter.rbs
102
102
  - sig/orthoses/lazy_trace_point.rbs
103
103
  - sig/orthoses/lazy_trace_point/method_added_hook.rbs
104
- - sig/orthoses/lazy_trace_point/signleton_method_added_hook.rbs
105
104
  - sig/orthoses/load_rbs.rbs
106
105
  - sig/orthoses/missing_name.rbs
107
106
  - sig/orthoses/missing_name/missing_class.rbs
@@ -1,5 +0,0 @@
1
- # THIS IS GENERATED CODE from `$ rake sig`
2
-
3
- module Orthoses::LazyTracePoint::SignletonMethodAddedHook
4
- def singleton_method_added: (untyped id) -> untyped
5
- end