orthoses 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/examples/minitest/Rakefile +9 -1
- data/lib/orthoses/attribute.rb +98 -0
- data/lib/orthoses/builder.rb +1 -0
- data/lib/orthoses/content/duplication_checker.rb +15 -11
- data/lib/orthoses/content/environment.rb +41 -7
- data/lib/orthoses/content/header_builder.rb +2 -1
- data/lib/orthoses/load_rbs.rb +1 -8
- data/lib/orthoses/rbs_prototype_rb.rb +3 -1
- data/lib/orthoses/utils.rb +8 -4
- data/lib/orthoses/version.rb +1 -1
- data/lib/orthoses.rb +1 -0
- data/sig/orthoses/attribute/hook.rbs +4 -0
- data/sig/orthoses/attribute.rbs +4 -0
- data/sig/orthoses/const_load_error.rbs +1 -1
- data/sig/orthoses/content/header_builder.rbs +4 -0
- data/sig/orthoses/name_space_error.rbs +1 -1
- data/sig/orthoses/utils.rbs +2 -2
- data/sig/orthoses.rbs +2 -2
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db149183688863139dfc513f92a150464497d1df409c495377817b4d3671db00
|
4
|
+
data.tar.gz: a02eb903127a7f6daf17750b9263ffee63a880b381ccfc47e76aa82e52252af3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ada92bd790f9ff1fd4b4e1293c1d4dad77c08c3c2e39f4513655ce910db7239e2a9e34373395e5abb4025d341c3596ef48b5dd46c05312cf6e2e8ec92152558
|
7
|
+
data.tar.gz: cb126e961ab83cc8ce683aa852279bac3a8cd166d73cd9f28f9e13cb482f8949d4b2f48928d617c2e4804b558160aea2feb6b91e66d91bfc0de86822869ba030
|
data/Gemfile.lock
CHANGED
data/examples/minitest/Rakefile
CHANGED
@@ -22,10 +22,12 @@ task :minitest => :src do
|
|
22
22
|
!Orthoses::Utils.rbs_defined_const?("#{current}::#{const}")
|
23
23
|
}
|
24
24
|
use Orthoses::Mixin
|
25
|
+
use Orthoses::Attribute
|
25
26
|
use Orthoses::RBSPrototypeRB,
|
26
27
|
paths: Dir.glob('src/lib/minitest{.rb,/*.rb}'),
|
27
28
|
constant_filter: ->(_) { false },
|
28
|
-
mixin_filter: ->(_) { false }
|
29
|
+
mixin_filter: ->(_) { false },
|
30
|
+
attribute_filter: ->(_) { false }
|
29
31
|
run ->(){
|
30
32
|
require_relative 'src/lib/minitest'
|
31
33
|
require_relative 'src/lib/minitest/test'
|
@@ -43,6 +45,12 @@ task :minitest => :src do
|
|
43
45
|
dependencies:
|
44
46
|
- name: mutex_m
|
45
47
|
YAML
|
48
|
+
tmp = out.join("kernel.rbs").read
|
49
|
+
out.join("kernel.rbs").open("w") do |f|
|
50
|
+
f.puts "%a{annotate:rdoc:skip}"
|
51
|
+
f.write tmp
|
52
|
+
end
|
53
|
+
sh "rbs annotate --gems out"
|
46
54
|
end
|
47
55
|
|
48
56
|
task default: :minitest
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Orthoses
|
2
|
+
class Attribute
|
3
|
+
module Hook
|
4
|
+
def attr(*names)
|
5
|
+
super
|
6
|
+
end
|
7
|
+
|
8
|
+
def attr_accessor(*names)
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def attr_reader(*names)
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def attr_writer(*names)
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(loader)
|
22
|
+
@loader = loader
|
23
|
+
end
|
24
|
+
|
25
|
+
def call
|
26
|
+
Module.prepend(Hook)
|
27
|
+
|
28
|
+
attr = CallTracer.new
|
29
|
+
attr_accessor = CallTracer.new
|
30
|
+
attr_reader = CallTracer.new
|
31
|
+
attr_writer = CallTracer.new
|
32
|
+
|
33
|
+
store = attr.trace(Hook.method(:attr)) do
|
34
|
+
attr_accessor.trace(Hook.method(:attr_accessor)) do
|
35
|
+
attr_reader.trace(Hook.method(:attr_reader)) do
|
36
|
+
attr_writer.trace(Hook.method(:attr_writer)) do
|
37
|
+
@loader.call
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
store["Module"].body.delete("prepend Orthoses::Attribute::Hook")
|
44
|
+
|
45
|
+
attr.result.each do |method, argument|
|
46
|
+
m = method.receiver.to_s.match(/#<Class:([\w:]+)>/)
|
47
|
+
if m && m[1]
|
48
|
+
receiver_name = m[1]
|
49
|
+
prefix = "self."
|
50
|
+
else
|
51
|
+
receiver_name = Utils.module_name(method.receiver) or next
|
52
|
+
prefix = nil
|
53
|
+
end
|
54
|
+
content = store[receiver_name]
|
55
|
+
if argument[:names][1].equal?(true)
|
56
|
+
content << "attr_accessor #{prefix}#{argument[:names][0]}: untyped"
|
57
|
+
elsif argument[:names][1].equal?(false)
|
58
|
+
content << "attr_reader #{prefix}#{argument[:names][0]}: untyped"
|
59
|
+
else
|
60
|
+
argument[:names].each do |name|
|
61
|
+
content << "attr_reader #{prefix}#{name}: untyped"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
each_definition(attr_accessor) do |receiver_name, name|
|
67
|
+
store[receiver_name] << "attr_accessor #{name}: untyped"
|
68
|
+
end
|
69
|
+
each_definition(attr_reader) do |receiver_name, name|
|
70
|
+
store[receiver_name] << "attr_reader #{name}: untyped"
|
71
|
+
end
|
72
|
+
each_definition(attr_writer) do |receiver_name, name|
|
73
|
+
store[receiver_name] << "attr_writer #{name}: untyped"
|
74
|
+
end
|
75
|
+
|
76
|
+
store
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def each_definition(call_tracer)
|
82
|
+
call_tracer.result.each do |method, argument|
|
83
|
+
m = method.receiver.to_s.match(/#<Class:([\w:]+)>/)
|
84
|
+
if m && m[1]
|
85
|
+
receiver_name = m[1]
|
86
|
+
argument[:names].each do |name|
|
87
|
+
yield [receiver_name, "self.#{name}"]
|
88
|
+
end
|
89
|
+
else
|
90
|
+
receiver_name = Utils.module_name(method.receiver) or next
|
91
|
+
argument[:names].each do |name|
|
92
|
+
yield [receiver_name, name]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/orthoses/builder.rb
CHANGED
@@ -8,16 +8,16 @@ module Orthoses
|
|
8
8
|
|
9
9
|
def update_decl
|
10
10
|
uniq_map = {}
|
11
|
-
@decl.members.
|
11
|
+
@decl.members.each do |member|
|
12
12
|
key = member_key(member)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
drop_member = uniq_map[key]
|
14
|
+
uniq_map[key] = member
|
15
|
+
if drop_member
|
16
|
+
Orthoses.logger.warn("#{@decl.name}::#{drop_member} was droped since duplication")
|
17
17
|
end
|
18
18
|
end
|
19
19
|
drop_known_method_definition(uniq_map)
|
20
|
-
@decl.members.replace(uniq_map.values
|
20
|
+
@decl.members.replace(uniq_map.values)
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
@@ -26,11 +26,8 @@ module Orthoses
|
|
26
26
|
env = Utils.rbs_environment(collection: true)
|
27
27
|
if m_entry = env.class_decls[@decl.name.absolute!]
|
28
28
|
m_entry.decls.each do |d|
|
29
|
-
d.decl.members.each do |member|
|
30
|
-
|
31
|
-
when RBS::AST::Members::MethodDefinition, RBS::AST::Members::Alias
|
32
|
-
uniq_map.delete(member_key(member))
|
33
|
-
end
|
29
|
+
d.decl.members.grep_v(RBS::AST::Members::LocationOnly).each do |member|
|
30
|
+
uniq_map.delete(member_key(member))
|
34
31
|
end
|
35
32
|
end
|
36
33
|
end
|
@@ -51,6 +48,13 @@ module Orthoses
|
|
51
48
|
[member.class]
|
52
49
|
when RBS::AST::Members::Alias
|
53
50
|
[RBS::AST::Members::MethodDefinition, member.new_name, member.kind]
|
51
|
+
when RBS::AST::Members::AttrAccessor
|
52
|
+
# FIXME: how to check "#{member.name}=" ?
|
53
|
+
[RBS::AST::Members::MethodDefinition, member.name, member.kind]
|
54
|
+
when RBS::AST::Members::AttrReader
|
55
|
+
[RBS::AST::Members::MethodDefinition, member.name, member.kind]
|
56
|
+
when RBS::AST::Members::AttrWriter
|
57
|
+
[RBS::AST::Members::MethodDefinition, "#{member.name}=", member.kind]
|
54
58
|
else
|
55
59
|
[member.class, member.name]
|
56
60
|
end
|
@@ -1,18 +1,31 @@
|
|
1
1
|
module Orthoses
|
2
2
|
class Content
|
3
3
|
class Environment
|
4
|
-
|
4
|
+
class << self
|
5
|
+
def load_from_paths(paths)
|
6
|
+
new.tap do |env|
|
7
|
+
paths.each do |path|
|
8
|
+
Orthoses.logger.debug("Load #{path}")
|
9
|
+
buffer = RBS::Buffer.new(name: path.to_s, content: File.read(path.to_s, encoding: "UTF-8"))
|
10
|
+
RBS::Parser.parse_signature(buffer).each do |decl|
|
11
|
+
env << decl
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(constant_filter: nil, mixin_filter: nil, attribute_filter: nil)
|
5
19
|
@load_env = RBS::Environment.new
|
6
|
-
@known_env = Utils.rbs_environment(collection: true)
|
20
|
+
@known_env = Utils.rbs_environment(collection: true, cache: false)
|
7
21
|
@constant_filter = constant_filter
|
8
22
|
@mixin_filter = mixin_filter
|
23
|
+
@attribute_filter = attribute_filter
|
9
24
|
end
|
10
25
|
|
11
26
|
def <<(decl)
|
12
|
-
if known_class_entry = @known_env.class_decls[decl.name.absolute!]
|
13
|
-
decl.type_params.replace(known_class_entry.primary.decl.type_params)
|
14
|
-
end
|
15
27
|
@load_env << decl
|
28
|
+
@known_env << decl
|
16
29
|
rescue RBS::DuplicatedDeclarationError => err
|
17
30
|
Orthoses.logger.warn(err.inspect)
|
18
31
|
end
|
@@ -20,13 +33,15 @@ module Orthoses
|
|
20
33
|
def write_to(store:)
|
21
34
|
each do |add_content|
|
22
35
|
content = store[add_content.name]
|
23
|
-
content.header
|
36
|
+
content.header = add_content.header
|
24
37
|
content.concat(add_content.body)
|
25
38
|
end
|
26
39
|
end
|
27
40
|
|
28
41
|
def each
|
29
|
-
|
42
|
+
avoid_generic_parameter_mismatch_error
|
43
|
+
|
44
|
+
header_builder = HeaderBuilder.new(env: @known_env)
|
30
45
|
|
31
46
|
@load_env.class_decls.each do |type_name, m_entry|
|
32
47
|
name = type_name.relative!.to_s
|
@@ -49,6 +64,23 @@ module Orthoses
|
|
49
64
|
end
|
50
65
|
end
|
51
66
|
|
67
|
+
private
|
68
|
+
|
69
|
+
# Avoid `RBS::GenericParameterMismatchError` from like rbs_prototype_rb
|
70
|
+
# class Array # <= RBS::GenericParameterMismatchError
|
71
|
+
# end
|
72
|
+
def avoid_generic_parameter_mismatch_error
|
73
|
+
@known_env.class_decls.each do |type_name, m_entry|
|
74
|
+
tmp_primary_d = m_entry.decls.find { |d| !d.decl.type_params.empty? }
|
75
|
+
next unless tmp_primary_d
|
76
|
+
m_entry.decls.each do |d|
|
77
|
+
if d.decl.type_params.empty?
|
78
|
+
d.decl.type_params.replace(tmp_primary_d.decl.type_params)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
52
84
|
def decls_to_lines(decls)
|
53
85
|
out = StringIO.new
|
54
86
|
writer = RBS::Writer.new(out: out)
|
@@ -61,6 +93,8 @@ module Orthoses
|
|
61
93
|
next unless @constant_filter.nil? || @constant_filter.call(member)
|
62
94
|
when RBS::AST::Members::Mixin
|
63
95
|
next unless @mixin_filter.nil? || @mixin_filter.call(member)
|
96
|
+
when RBS::AST::Members::Attribute
|
97
|
+
next unless @attribute_filter.nil? || @attribute_filter.call(member)
|
64
98
|
end
|
65
99
|
writer.write_member(member)
|
66
100
|
end
|
@@ -48,10 +48,11 @@ module Orthoses
|
|
48
48
|
context = primary.outer.length.times.map do |i|
|
49
49
|
primary.outer[0, i + 1].map(&:name).inject(:+).to_namespace.absolute!
|
50
50
|
end
|
51
|
+
context.push(RBS::Namespace.root)
|
51
52
|
|
52
53
|
super_class_name = @resolver.resolve(primary.decl.super_class.name, context: context) || primary.decl.super_class.name
|
53
54
|
if primary.decl.super_class.args.empty?
|
54
|
-
if super_class_entry = @env.class_decls[super_class_name
|
55
|
+
if super_class_entry = @env.class_decls[super_class_name]
|
55
56
|
super_primary = super_class_entry.primary
|
56
57
|
" < #{name_and_args(super_class_name, super_primary.decl.type_params.map { :untyped })}"
|
57
58
|
else
|
data/lib/orthoses/load_rbs.rb
CHANGED
@@ -11,14 +11,7 @@ module Orthoses
|
|
11
11
|
|
12
12
|
def call
|
13
13
|
@loader.call.tap do |store|
|
14
|
-
env = Content::Environment.
|
15
|
-
@paths.each do |path|
|
16
|
-
Orthoses.logger.debug("Load #{path}")
|
17
|
-
buffer = RBS::Buffer.new(name: path.to_s, content: File.read(path.to_s, encoding: "UTF-8"))
|
18
|
-
RBS::Parser.parse_signature(buffer).each do |decl|
|
19
|
-
env << decl
|
20
|
-
end
|
21
|
-
end
|
14
|
+
env = Content::Environment.load_from_paths(@paths)
|
22
15
|
env.write_to(store: store)
|
23
16
|
end
|
24
17
|
end
|
@@ -3,11 +3,12 @@ module Orthoses
|
|
3
3
|
# use Orthoses::RBSPrototypeRB,
|
4
4
|
# paths: Dir.glob("lib/**/*.rb")
|
5
5
|
class RBSPrototypeRB
|
6
|
-
def initialize(loader, paths:, constant_filter: nil, mixin_filter: nil)
|
6
|
+
def initialize(loader, paths:, constant_filter: nil, mixin_filter: nil, attribute_filter: nil)
|
7
7
|
@loader = loader
|
8
8
|
@paths = paths
|
9
9
|
@constant_filter = constant_filter
|
10
10
|
@mixin_filter = mixin_filter
|
11
|
+
@attribute_filter = attribute_filter
|
11
12
|
end
|
12
13
|
|
13
14
|
def call
|
@@ -24,6 +25,7 @@ module Orthoses
|
|
24
25
|
env = Orthoses::Content::Environment.new(
|
25
26
|
constant_filter: @constant_filter,
|
26
27
|
mixin_filter: @mixin_filter,
|
28
|
+
attribute_filter: @attribute_filter,
|
27
29
|
)
|
28
30
|
parser.decls.each do |decl|
|
29
31
|
env << decl
|
data/lib/orthoses/utils.rb
CHANGED
@@ -46,9 +46,9 @@ module Orthoses
|
|
46
46
|
RBS::Namespace.parse(name).to_type_name
|
47
47
|
end
|
48
48
|
|
49
|
-
def self.rbs_environment(library: nil, collection: false)
|
49
|
+
def self.rbs_environment(library: nil, collection: false, cache: true)
|
50
50
|
@env_cache ||= {}
|
51
|
-
if hit = @env_cache[[library, collection]]
|
51
|
+
if cache && hit = @env_cache[[library, collection]]
|
52
52
|
return hit
|
53
53
|
end
|
54
54
|
|
@@ -71,8 +71,9 @@ module Orthoses
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
|
75
|
-
|
74
|
+
RBS::Environment.from_loader(loader).resolve_type_names.tap do |env|
|
75
|
+
@env_cache[[library, collection]] = env if cache
|
76
|
+
end
|
76
77
|
end
|
77
78
|
|
78
79
|
def self.object_to_rbs(object, strict:)
|
@@ -121,6 +122,9 @@ module Orthoses
|
|
121
122
|
"Hash[#{keys.join(' | ')}, #{values.join(' | ')}]"
|
122
123
|
end
|
123
124
|
end
|
125
|
+
when Range
|
126
|
+
type = object_to_rbs(object.begin || object.end, strict: false)
|
127
|
+
"Range[#{type}]"
|
124
128
|
when ARGF
|
125
129
|
# see also https://github.com/ruby/rbs/pull/975
|
126
130
|
'untyped'
|
data/lib/orthoses/version.rb
CHANGED
data/lib/orthoses.rb
CHANGED
data/sig/orthoses/utils.rbs
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# THIS IS GENERATED CODE from `$ rake generate_self_sig`
|
2
2
|
|
3
3
|
module Orthoses::Utils
|
4
|
-
UNBOUND_NAME_METHOD: UnboundMethod
|
5
|
-
|
6
4
|
def self.unautoload!: () -> void
|
7
5
|
|
8
6
|
def self.each_const_recursive: (Module root, ?cache: Hash[untyped, true], ?on_error: ^(Orthoses::ConstLoadError) -> void?) ?{ (Module, Symbol, untyped) -> void } -> void
|
@@ -24,4 +22,6 @@ module Orthoses::Utils
|
|
24
22
|
def self.known_type_params: (Module | String) -> Array[RBS::AST::TypeParam]
|
25
23
|
|
26
24
|
def self.new_store: () -> Orthoses::store
|
25
|
+
|
26
|
+
UNBOUND_NAME_METHOD: UnboundMethod
|
27
27
|
end
|
data/sig/orthoses.rbs
CHANGED
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: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rbs
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- examples/simple_middleware.rb
|
41
41
|
- examples/simple_middleware.rbs
|
42
42
|
- lib/orthoses.rb
|
43
|
+
- lib/orthoses/attribute.rb
|
43
44
|
- lib/orthoses/avoid_recursive_ancestor_error.rb
|
44
45
|
- lib/orthoses/builder.rb
|
45
46
|
- lib/orthoses/call_tracer.rb
|
@@ -66,6 +67,8 @@ files:
|
|
66
67
|
- sig/orthoses.rbs
|
67
68
|
- sig/orthoses/_call.rbs
|
68
69
|
- sig/orthoses/_middle_ware.rbs
|
70
|
+
- sig/orthoses/attribute.rbs
|
71
|
+
- sig/orthoses/attribute/hook.rbs
|
69
72
|
- sig/orthoses/avoid_recursive_ancestor_error.rbs
|
70
73
|
- sig/orthoses/builder.rbs
|
71
74
|
- sig/orthoses/builder/call_logable.rbs
|
@@ -75,6 +78,7 @@ files:
|
|
75
78
|
- sig/orthoses/content.rbs
|
76
79
|
- sig/orthoses/content/duplication_checker.rbs
|
77
80
|
- sig/orthoses/content/environment.rbs
|
81
|
+
- sig/orthoses/content/header_builder.rbs
|
78
82
|
- sig/orthoses/create_file_by_name.rbs
|
79
83
|
- sig/orthoses/delegate_class.rbs
|
80
84
|
- sig/orthoses/filter.rbs
|