orthoses 1.17.0 → 1.18.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: e7d32af3f7ca57a532b811d511f214250dab712748f88602089d23349375c46d
4
- data.tar.gz: 197966b36e96be58eb2aeea816090e2c24ebeec954175ee2d24a8cec07771b15
3
+ metadata.gz: 544e3607082ea7cf7133437a87c355e16422240c07cf63da846ee5880630789e
4
+ data.tar.gz: b210030d343c4a8b41bc2aa314fe4bc916196ef76161e0298ff76ee06abd4a0f
5
5
  SHA512:
6
- metadata.gz: d70aeed9a896b32671d41f23c3bdba9efbb5679bd7c2c6bb0a3ead0976a26ee1a903a8b9ce1b748509efc94b6f8f1f66aea0e04a92d6efef8958b85785e81686
7
- data.tar.gz: 8f186cc6a6ceeff80267d9dd6150e9d1d8cd96e5a37446314195a0b0f6adf7132356dbca50c61a275b0e16a33aac184b5969c8b39c2b49089d6998e98b491fea
6
+ metadata.gz: 066bf0492515c4df6fd7320e5d564b345063083b1692a889f8fbfeb32e74f45a0fffb2defedfd0a3ebba5eeaf9a35eb15f2c1e678999f64add3c876fadb8310b
7
+ data.tar.gz: a2dbf32980d77df48dbcc7606a013c2b8b921d5dfae8a30bcfa1f189d26b38c352261345e8eb1f5976df695ad6f5e651457be3236b5f43be76514137ca62a03c
data/README.md CHANGED
@@ -189,6 +189,11 @@ If it is unknown whether it is a class or a module, it is defined as an empty mo
189
189
  You can specify that the specified RBS should not be intentionally generated.
190
190
  This is useful when you want to exclude handwritten RBS.
191
191
 
192
+ ### Orthoses::ResolveTypeNames
193
+
194
+ Call `RBS::Environment#resolve_type_names` and output.
195
+ Using this middleware improves the efficiency of loading files after they are generated.
196
+
192
197
  ## Development
193
198
 
194
199
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -21,9 +21,15 @@ module Orthoses
21
21
 
22
22
  private
23
23
 
24
+ def resolve_full_name(entry:)
25
+ full_name = entry.decl.name.relative!
26
+ context = build_context(entry: entry)
27
+ @resolver.resolve(full_name, context: context) || full_name
28
+ end
29
+
24
30
  def build_module(entry:, name_hint: nil)
25
31
  primary = entry.primary
26
- full_name = name_hint || primary.decl.name.relative!
32
+ full_name = name_hint || resolve_full_name(entry: primary).relative!
27
33
 
28
34
  self_types =
29
35
  if primary.decl.self_types.empty?
@@ -37,7 +43,7 @@ module Orthoses
37
43
 
38
44
  def build_class(entry:, name_hint: nil)
39
45
  primary = entry.primary
40
- full_name = name_hint || primary.decl.name.relative!
46
+ full_name = name_hint || resolve_full_name(entry: primary).relative!
41
47
 
42
48
  "class #{name_and_params(full_name, primary.decl.type_params)}#{build_super_class(primary)}"
43
49
  end
@@ -60,10 +66,8 @@ module Orthoses
60
66
  end
61
67
 
62
68
  def build_interface(entry:, name_hint: nil)
63
- full_name = name_hint || entry.decl.name.relative!
64
- context = build_context(entry: entry)
65
- resolved_name = @resolver.resolve(full_name, context: context) || full_name
66
- "interface #{name_and_params(resolved_name.relative!, entry.decl.type_params)}"
69
+ full_name = name_hint || resolve_full_name(entry: entry).relative!
70
+ "interface #{name_and_params(full_name, entry.decl.type_params)}"
67
71
  end
68
72
 
69
73
  include RBS::Environment::ContextUtil
@@ -86,7 +86,7 @@ module Orthoses
86
86
 
87
87
  def auto_header
88
88
  env = Utils.rbs_environment
89
- if entry = env.class_decls[TypeName(name).absolute!]
89
+ if entry = env.class_decls[RBS::TypeName.parse(name).absolute!]
90
90
  @header = Content::HeaderBuilder.new(env: env).build(entry: entry)
91
91
  return
92
92
  end
@@ -77,7 +77,7 @@ module Orthoses
77
77
  name.split('::')[0, @depth].join('::')
78
78
  when Hash
79
79
  found_key, found_index = @depth.find do |n, _|
80
- name.start_with?(n)
80
+ n == '*' || name.start_with?(n)
81
81
  end
82
82
  case found_index
83
83
  when nil
@@ -33,7 +33,7 @@ module Orthoses
33
33
  if content.header && content.header.include?("<")
34
34
  _, superclass = content.header.split(/\s*<\s*/, 2)
35
35
  superclass.sub!(/\[.*/, "")
36
- new_name = TypeName(superclass).relative!.to_s
36
+ new_name = RBS::TypeName.parse(superclass).relative!.to_s
37
37
  recur(@store[new_name])
38
38
  end
39
39
  end
@@ -60,7 +60,7 @@ module Orthoses
60
60
  def split_name(key_name)
61
61
  ret = []
62
62
 
63
- type_name = TypeName(key_name).relative!
63
+ type_name = RBS::TypeName.parse(key_name).relative!
64
64
  if !Utils.rbs_defined_class?(type_name.to_s) && !@store.has_key?(type_name.to_s)
65
65
  ret << type_name.to_s
66
66
  end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Orthoses
4
+ # use Orthoses::ResolveTypeNames
5
+ class ResolveTypeNames
6
+ def initialize(loader)
7
+ @loader = loader
8
+ end
9
+
10
+ def call
11
+ @loader.call.tap do |store|
12
+ env = Utils.rbs_environment(cache: false)
13
+
14
+ signatures = store.map do |name, content|
15
+ buffer = RBS::Buffer.new(content: content.to_rbs, name: "orthoses-resolve_type_names-#{name.downcase}.rbs")
16
+ decls = [content.to_decl]
17
+
18
+ # Add as known types
19
+ env.add_signature(buffer: buffer, directives: [], decls: decls)
20
+
21
+ # Will resolve names
22
+ [buffer, [[], decls]]
23
+ end.to_h
24
+
25
+ # Reduce resolving names
26
+ env.signatures.replace(signatures)
27
+ env = env.resolve_type_names
28
+
29
+ store.each do |name, content|
30
+ out = StringIO.new
31
+ writer = RBS::Writer.new(out: out)
32
+ type_name = RBS::TypeName.parse(content.name).absolute!
33
+ entry = env.class_decls[type_name] || raise
34
+ content.header = content_header(entry)
35
+ entry.decls.each do |decl|
36
+ decl.decl.members.each do |member|
37
+ writer.write_member(member)
38
+ end
39
+ end
40
+ content.body.replace(out.string.lines)
41
+ end
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def content_header(entry)
48
+ case primary_decl = entry.primary.decl
49
+ when RBS::AST::Declarations::Class
50
+ class_header(primary_decl)
51
+ when RBS::AST::Declarations::Module
52
+ module_header(primary_decl)
53
+ else
54
+ raise "unexpected decl: #{primary_decl.class}"
55
+ end
56
+ end
57
+
58
+ def class_header(decl)
59
+ super_class = if super_class = decl.super_class
60
+ " < #{name_and_args(super_class.name, super_class.args)}"
61
+ end
62
+ "class #{name_and_params(decl.name, decl.type_params)}#{super_class}"
63
+ end
64
+
65
+ def module_header(decl)
66
+ self_type = unless decl.self_types.empty?
67
+ " : #{decl.self_types.join(", ")}"
68
+ end
69
+ "module #{name_and_params(decl.name, decl.type_params)}#{self_type}"
70
+ end
71
+
72
+ module WriterCopy
73
+ def name_and_args(name, args)
74
+ if name && args
75
+ if args.empty?
76
+ "#{name}"
77
+ else
78
+ "#{name}[#{args.join(", ")}]"
79
+ end
80
+ end
81
+ end
82
+
83
+ def name_and_params(name, params)
84
+ if params.empty?
85
+ "#{name}"
86
+ else
87
+ ps = params.each.map do |param|
88
+ param.to_s
89
+ end
90
+
91
+ "#{name}[#{ps.join(", ")}]"
92
+ end
93
+ end
94
+ end
95
+ include WriterCopy
96
+ end
97
+ end
@@ -0,0 +1,18 @@
1
+ # RBS 3.8
2
+ unless RBS::TypeName.singleton_class.method_defined?(:parse)
3
+ module RBS
4
+ class TypeName
5
+ def self.parse(string)
6
+ absolute = string.start_with?("::")
7
+
8
+ *path, name = string.delete_prefix("::").split("::").map(&:to_sym)
9
+ raise unless name
10
+
11
+ TypeName.new(
12
+ name: name,
13
+ namespace: RBS::Namespace.new(path: path, absolute: absolute)
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
@@ -165,7 +165,7 @@ module Orthoses
165
165
  def self.module_to_type_name(mod)
166
166
  name = Utils.module_name(mod)
167
167
  if name && !name.empty?
168
- TypeName(name)
168
+ RBS::TypeName.parse(name)
169
169
  else
170
170
  nil
171
171
  end
@@ -186,7 +186,7 @@ module Orthoses
186
186
  type_name =
187
187
  case name
188
188
  when String
189
- TypeName(name).absolute!
189
+ RBS::TypeName.parse(name).absolute!
190
190
  when Module
191
191
  module_to_type_name(name).absolute!
192
192
  when RBS::TypeName
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Orthoses
4
- VERSION = "1.17.0"
4
+ VERSION = "1.18.0"
5
5
  end
data/lib/orthoses.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'rbs'
4
4
  require 'pathname'
5
5
  require 'stringio'
6
+ require_relative 'orthoses/shims'
6
7
 
7
8
  require 'orthoses/utils'
8
9
 
@@ -27,6 +28,7 @@ module Orthoses
27
28
  autoload :PP, 'orthoses/pp'
28
29
  autoload :RBSPrototypeRB, 'orthoses/rbs_prototype_rb'
29
30
  autoload :RBSPrototypeRuntime, 'orthoses/rbs_prototype_runtime'
31
+ autoload :ResolveTypeNames, 'orthoses/resolve_type_names'
30
32
  autoload :Sort, 'orthoses/sort'
31
33
  autoload :Store, 'orthoses/store'
32
34
  autoload :Tap, 'orthoses/tap'
@@ -86,6 +86,7 @@ class Orthoses::Content::HeaderBuilder
86
86
  @resolver: untyped
87
87
  def initialize: (env: untyped) -> void
88
88
  def build: (entry: untyped, ?name_hint: untyped?) -> untyped
89
+ private def resolve_full_name: (entry: untyped) -> untyped
89
90
  private def build_module: (entry: untyped, ?name_hint: untyped?) -> ::String
90
91
  private def build_class: (entry: untyped, ?name_hint: untyped?) -> ::String
91
92
  private def build_super_class: (untyped primary) -> (nil | untyped)
@@ -0,0 +1,17 @@
1
+ # THIS IS GENERATED CODE from `$ rake sig`
2
+
3
+ # use Orthoses::ResolveTypeNames
4
+ class Orthoses::ResolveTypeNames
5
+ @loader: untyped
6
+ def initialize: (untyped loader) -> void
7
+ def call: () -> untyped
8
+ private def content_header: (untyped entry) -> untyped
9
+ private def class_header: (untyped decl) -> ::String
10
+ private def module_header: (untyped decl) -> ::String
11
+ end
12
+
13
+ module Orthoses::ResolveTypeNames::WriterCopy
14
+ def name_and_args: (untyped name, untyped args) -> (::String | nil)
15
+
16
+ def name_and_params: (untyped name, untyped params) -> ::String
17
+ end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orthoses
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.17.0
4
+ version: 1.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-11-20 00:00:00.000000000 Z
10
+ date: 2025-02-04 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rbs
@@ -64,6 +63,8 @@ files:
64
63
  - lib/orthoses/pp.rb
65
64
  - lib/orthoses/rbs_prototype_rb.rb
66
65
  - lib/orthoses/rbs_prototype_runtime.rb
66
+ - lib/orthoses/resolve_type_names.rb
67
+ - lib/orthoses/shims.rb
67
68
  - lib/orthoses/sort.rb
68
69
  - lib/orthoses/store.rb
69
70
  - lib/orthoses/tap.rb
@@ -103,6 +104,7 @@ files:
103
104
  - sig/orthoses/pp.rbs
104
105
  - sig/orthoses/rbs_prototype_rb.rbs
105
106
  - sig/orthoses/rbs_prototype_runtime.rbs
107
+ - sig/orthoses/resolve_type_names.rbs
106
108
  - sig/orthoses/sort.rbs
107
109
  - sig/orthoses/store.rbs
108
110
  - sig/orthoses/tap.rbs
@@ -116,7 +118,6 @@ licenses:
116
118
  metadata:
117
119
  homepage_uri: https://github.com/ksss/orthoses
118
120
  source_code_uri: https://github.com/ksss/orthoses
119
- post_install_message:
120
121
  rdoc_options: []
121
122
  require_paths:
122
123
  - lib
@@ -131,8 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
132
  - !ruby/object:Gem::Version
132
133
  version: '0'
133
134
  requirements: []
134
- rubygems_version: 3.5.22
135
- signing_key:
135
+ rubygems_version: 3.6.2
136
136
  specification_version: 4
137
137
  summary: Framework for Generate RBS
138
138
  test_files: []