tapioca 0.17.10 → 0.19.0

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.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -2
  3. data/lib/tapioca/bundler_ext/auto_require_hook.rb +0 -3
  4. data/lib/tapioca/cli.rb +1 -3
  5. data/lib/tapioca/commands/annotations.rb +0 -2
  6. data/lib/tapioca/commands/check_shims.rb +0 -1
  7. data/lib/tapioca/commands/command.rb +0 -1
  8. data/lib/tapioca/dsl/compiler.rb +7 -6
  9. data/lib/tapioca/dsl/compilers/aasm.rb +4 -5
  10. data/lib/tapioca/dsl/compilers/action_controller_helpers.rb +0 -4
  11. data/lib/tapioca/dsl/compilers/action_mailer.rb +0 -4
  12. data/lib/tapioca/dsl/compilers/action_text.rb +0 -4
  13. data/lib/tapioca/dsl/compilers/active_job.rb +0 -4
  14. data/lib/tapioca/dsl/compilers/active_model_attributes.rb +0 -4
  15. data/lib/tapioca/dsl/compilers/active_model_secure_password.rb +0 -4
  16. data/lib/tapioca/dsl/compilers/active_model_validations_confirmation.rb +0 -2
  17. data/lib/tapioca/dsl/compilers/active_record_associations.rb +0 -5
  18. data/lib/tapioca/dsl/compilers/active_record_columns.rb +0 -3
  19. data/lib/tapioca/dsl/compilers/active_record_delegated_types.rb +0 -3
  20. data/lib/tapioca/dsl/compilers/active_record_enum.rb +0 -4
  21. data/lib/tapioca/dsl/compilers/active_record_fixtures.rb +0 -4
  22. data/lib/tapioca/dsl/compilers/active_record_relations.rb +33 -6
  23. data/lib/tapioca/dsl/compilers/active_record_scope.rb +0 -1
  24. data/lib/tapioca/dsl/compilers/active_record_secure_token.rb +0 -3
  25. data/lib/tapioca/dsl/compilers/active_record_store.rb +0 -3
  26. data/lib/tapioca/dsl/compilers/active_record_typed_store.rb +0 -4
  27. data/lib/tapioca/dsl/compilers/active_resource.rb +0 -4
  28. data/lib/tapioca/dsl/compilers/active_storage.rb +0 -4
  29. data/lib/tapioca/dsl/compilers/active_support_concern.rb +0 -4
  30. data/lib/tapioca/dsl/compilers/active_support_current_attributes.rb +3 -18
  31. data/lib/tapioca/dsl/compilers/active_support_environment_inquirer.rb +60 -0
  32. data/lib/tapioca/dsl/compilers/active_support_time_ext.rb +0 -4
  33. data/lib/tapioca/dsl/compilers/config.rb +0 -4
  34. data/lib/tapioca/dsl/compilers/frozen_record.rb +0 -4
  35. data/lib/tapioca/dsl/compilers/graphql_input_object.rb +0 -4
  36. data/lib/tapioca/dsl/compilers/graphql_mutation.rb +0 -4
  37. data/lib/tapioca/dsl/compilers/identity_cache.rb +0 -4
  38. data/lib/tapioca/dsl/compilers/json_api_client_resource.rb +3 -17
  39. data/lib/tapioca/dsl/compilers/kredis.rb +0 -4
  40. data/lib/tapioca/dsl/compilers/mixed_in_class_attributes.rb +0 -4
  41. data/lib/tapioca/dsl/compilers/protobuf.rb +0 -4
  42. data/lib/tapioca/dsl/compilers/rails_generators.rb +0 -4
  43. data/lib/tapioca/dsl/compilers/sidekiq_worker.rb +0 -4
  44. data/lib/tapioca/dsl/compilers/smart_properties.rb +0 -4
  45. data/lib/tapioca/dsl/compilers/state_machines.rb +0 -4
  46. data/lib/tapioca/dsl/compilers/url_helpers.rb +0 -3
  47. data/lib/tapioca/dsl/helpers/active_model_type_helper.rb +0 -2
  48. data/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb +0 -5
  49. data/lib/tapioca/dsl/helpers/active_record_constants_helper.rb +0 -2
  50. data/lib/tapioca/dsl/helpers/graphql_type_helper.rb +0 -2
  51. data/lib/tapioca/dsl/pipeline.rb +0 -2
  52. data/lib/tapioca/executor.rb +0 -2
  53. data/lib/tapioca/gem/events.rb +0 -15
  54. data/lib/tapioca/gem/listeners/base.rb +0 -1
  55. data/lib/tapioca/gem/listeners/documentation.rb +94 -0
  56. data/lib/tapioca/gem/listeners/dynamic_mixins.rb +0 -2
  57. data/lib/tapioca/gem/listeners/foreign_constants.rb +0 -2
  58. data/lib/tapioca/gem/listeners/methods.rb +0 -2
  59. data/lib/tapioca/gem/listeners/mixins.rb +0 -2
  60. data/lib/tapioca/gem/listeners/remove_empty_payload_scopes.rb +0 -2
  61. data/lib/tapioca/gem/listeners/sorbet_enums.rb +0 -2
  62. data/lib/tapioca/gem/listeners/sorbet_helpers.rb +0 -2
  63. data/lib/tapioca/gem/listeners/sorbet_props.rb +0 -1
  64. data/lib/tapioca/gem/listeners/sorbet_required_ancestors.rb +0 -2
  65. data/lib/tapioca/gem/listeners/sorbet_signatures.rb +1 -7
  66. data/lib/tapioca/gem/listeners/sorbet_type_variables.rb +0 -2
  67. data/lib/tapioca/gem/listeners/source_location.rb +6 -7
  68. data/lib/tapioca/gem/listeners/subconstants.rb +0 -2
  69. data/lib/tapioca/gem/listeners.rb +1 -1
  70. data/lib/tapioca/gem/pipeline.rb +2 -4
  71. data/lib/tapioca/gemfile.rb +0 -18
  72. data/lib/tapioca/helpers/cli_helper.rb +0 -1
  73. data/lib/tapioca/helpers/config_helper.rb +0 -1
  74. data/lib/tapioca/helpers/env_helper.rb +0 -1
  75. data/lib/tapioca/helpers/gem_helper.rb +0 -2
  76. data/lib/tapioca/helpers/git_attributes.rb +0 -2
  77. data/lib/tapioca/helpers/package_url.rb +416 -0
  78. data/lib/tapioca/helpers/rbi_files_helper.rb +0 -1
  79. data/lib/tapioca/helpers/rbi_helper.rb +7 -3
  80. data/lib/tapioca/helpers/sorbet_helper.rb +0 -2
  81. data/lib/tapioca/helpers/test/content.rb +0 -1
  82. data/lib/tapioca/helpers/test/dsl_compiler.rb +0 -3
  83. data/lib/tapioca/helpers/test/isolation.rb +0 -6
  84. data/lib/tapioca/helpers/test/template.rb +1 -9
  85. data/lib/tapioca/internal.rb +2 -2
  86. data/lib/tapioca/loaders/dsl.rb +0 -4
  87. data/lib/tapioca/loaders/gem.rb +0 -4
  88. data/lib/tapioca/loaders/loader.rb +0 -1
  89. data/lib/tapioca/rbi_ext/model.rb +4 -5
  90. data/lib/tapioca/rbi_formatter.rb +0 -2
  91. data/lib/tapioca/repo_index.rb +0 -3
  92. data/lib/tapioca/runtime/dynamic_mixin_compiler.rb +0 -3
  93. data/lib/tapioca/runtime/generic_type_registry.rb +0 -4
  94. data/lib/tapioca/runtime/reflection.rb +14 -13
  95. data/lib/tapioca/runtime/trackers/autoload.rb +0 -3
  96. data/lib/tapioca/runtime/trackers/constant_definition.rb +27 -5
  97. data/lib/tapioca/runtime/trackers/method_definition.rb +0 -1
  98. data/lib/tapioca/runtime/trackers/mixin.rb +0 -3
  99. data/lib/tapioca/runtime/trackers/required_ancestor.rb +0 -2
  100. data/lib/tapioca/runtime/trackers/tracker.rb +0 -3
  101. data/lib/tapioca/runtime/trackers.rb +0 -4
  102. data/lib/tapioca/sorbet_ext/generic_name_patch.rb +0 -2
  103. data/lib/tapioca/static/requires_compiler.rb +0 -2
  104. data/lib/tapioca/static/symbol_loader.rb +13 -6
  105. data/lib/tapioca/static/symbol_table_parser.rb +0 -4
  106. data/lib/tapioca/version.rb +1 -1
  107. data/lib/tapioca.rb +0 -2
  108. metadata +28 -15
  109. data/lib/tapioca/gem/listeners/yard_doc.rb +0 -112
  110. data/lib/tapioca/helpers/source_uri.rb +0 -84
  111. data/lib/tapioca/runtime/attached_class_of_32.rb +0 -20
  112. data/lib/tapioca/runtime/attached_class_of_legacy.rb +0 -24
@@ -0,0 +1,60 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ return unless defined?(ActiveSupport::EnvironmentInquirer)
5
+
6
+ module Tapioca
7
+ module Dsl
8
+ module Compilers
9
+ # `Tapioca::Dsl::Compilers::ActiveSupportEnvironmentInquirer` decorates an RBI file for non-default environment
10
+ # files in the `config/environments` directory.
11
+ #
12
+ # For example, in a Rails application with the following files:
13
+ #
14
+ # - config/environments/development.rb
15
+ # - config/environments/demo.rb
16
+ # - config/environments/production.rb
17
+ # - config/environments/staging.rb
18
+ # - config/environments/test.rb
19
+ #
20
+ # this compiler will produce an RBI file with the following content:
21
+ # ~~~rbi
22
+ # # typed: true
23
+ #
24
+ # class ActiveSupport::EnvironmentInquirer
25
+ # sig { returns(T::Boolean) }
26
+ # def demo?; end
27
+ #
28
+ # sig { returns(T::Boolean) }
29
+ # def staging?; end
30
+ # end
31
+ # ~~~
32
+ #: [ConstantType = singleton(::ActiveSupport::EnvironmentInquirer)]
33
+ class ActiveSupportEnvironmentInquirer < Compiler
34
+ # @override
35
+ #: -> void
36
+ def decorate
37
+ envs = Rails.root.glob("config/environments/*.rb").map { |f| f.basename(".rb").to_s }.sort
38
+ envs -= ::ActiveSupport::EnvironmentInquirer::DEFAULT_ENVIRONMENTS
39
+ return if envs.none?
40
+
41
+ root.create_path(::ActiveSupport::EnvironmentInquirer) do |mod|
42
+ envs.each do |env|
43
+ mod.create_method("#{env}?", return_type: "T::Boolean")
44
+ end
45
+ end
46
+ end
47
+
48
+ class << self
49
+ # @override
50
+ #: -> T::Enumerable[T::Module[top]]
51
+ def gather_constants
52
+ return [] unless defined?(Rails.application) && Rails.application
53
+
54
+ [::ActiveSupport::EnvironmentInquirer]
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -36,8 +36,6 @@ module Tapioca
36
36
  # ```
37
37
  #: [ConstantType = singleton(::Time)]
38
38
  class ActiveSupportTimeExt < Compiler
39
- extend T::Sig
40
-
41
39
  # @override
42
40
  #: -> void
43
41
  def decorate
@@ -55,8 +53,6 @@ module Tapioca
55
53
  end
56
54
 
57
55
  class << self
58
- extend T::Sig
59
-
60
56
  # @override
61
57
  #: -> Enumerable[T::Module[top]]
62
58
  def gather_constants
@@ -42,8 +42,6 @@ module Tapioca
42
42
  # ```
43
43
  #: [ConstantType = T::Module[top]]
44
44
  class Config < Compiler
45
- extend T::Sig
46
-
47
45
  CONFIG_OPTIONS_SUFFIX = "ConfigOptions"
48
46
 
49
47
  # @override
@@ -93,8 +91,6 @@ module Tapioca
93
91
  end
94
92
 
95
93
  class << self
96
- extend T::Sig
97
-
98
94
  # @override
99
95
  #: -> Enumerable[T::Module[top]]
100
96
  def gather_constants
@@ -60,8 +60,6 @@ module Tapioca
60
60
  # ~~~
61
61
  #: [ConstantType = (singleton(::FrozenRecord::Base) & Extensions::FrozenRecord)]
62
62
  class FrozenRecord < Compiler
63
- extend T::Sig
64
-
65
63
  # @override
66
64
  #: -> void
67
65
  def decorate
@@ -85,8 +83,6 @@ module Tapioca
85
83
  end
86
84
 
87
85
  class << self
88
- extend T::Sig
89
-
90
86
  # @override
91
87
  #: -> Enumerable[T::Module[top]]
92
88
  def gather_constants
@@ -36,8 +36,6 @@ module Tapioca
36
36
  # ~~~
37
37
  #: [ConstantType = singleton(GraphQL::Schema::InputObject)]
38
38
  class GraphqlInputObject < Compiler
39
- extend T::Sig
40
-
41
39
  # @override
42
40
  #: -> void
43
41
  def decorate
@@ -74,8 +72,6 @@ module Tapioca
74
72
  end
75
73
 
76
74
  class << self
77
- extend T::Sig
78
-
79
75
  # @override
80
76
  #: -> Enumerable[T::Module[top]]
81
77
  def gather_constants
@@ -37,8 +37,6 @@ module Tapioca
37
37
  # ~~~
38
38
  #: [ConstantType = singleton(GraphQL::Schema::Mutation)]
39
39
  class GraphqlMutation < Compiler
40
- extend T::Sig
41
-
42
40
  # @override
43
41
  #: -> void
44
42
  def decorate
@@ -71,8 +69,6 @@ module Tapioca
71
69
  end
72
70
 
73
71
  class << self
74
- extend T::Sig
75
-
76
72
  # @override
77
73
  #: -> Enumerable[T::Module[top]]
78
74
  def gather_constants
@@ -57,8 +57,6 @@ module Tapioca
57
57
  # ~~~
58
58
  #: [ConstantType = singleton(::ActiveRecord::Base)]
59
59
  class IdentityCache < Compiler
60
- extend T::Sig
61
-
62
60
  COLLECTION_TYPE = ->(type) { "T::Array[::#{type}]" } #: ^((T::Module[top] | String) type) -> String
63
61
 
64
62
  # @override
@@ -92,8 +90,6 @@ module Tapioca
92
90
  end
93
91
 
94
92
  class << self
95
- extend T::Sig
96
-
97
93
  # @override
98
94
  #: -> Enumerable[T::Module[top]]
99
95
  def gather_constants
@@ -81,8 +81,6 @@ module Tapioca
81
81
  # ~~~
82
82
  #: [ConstantType = singleton(::JsonApiClient::Resource)]
83
83
  class JsonApiClientResource < Compiler
84
- extend T::Sig
85
-
86
84
  # @override
87
85
  #: -> void
88
86
  def decorate
@@ -106,8 +104,6 @@ module Tapioca
106
104
  end
107
105
 
108
106
  class << self
109
- extend T::Sig
110
-
111
107
  # @override
112
108
  #: -> Enumerable[T::Module[top]]
113
109
  def gather_constants
@@ -142,17 +138,7 @@ module Tapioca
142
138
  type = ::JsonApiClient::Schema::TypeFactory.type_for(property.type)
143
139
  return "T.untyped" if type.nil?
144
140
 
145
- sorbet_type = if type.respond_to?(:sorbet_type)
146
- line, file = type.method(:sorbet_type).source_location
147
-
148
- $stderr.puts <<~MESSAGE
149
- WARNING: `#sorbet_type` is deprecated. Please rename your method to `#__tapioca_type`."
150
-
151
- Defined on line #{line} of #{file}
152
- MESSAGE
153
-
154
- type.sorbet_type
155
- elsif type.respond_to?(:__tapioca_type)
141
+ tapioca_type = if type.respond_to?(:__tapioca_type)
156
142
  type.__tapioca_type
157
143
  elsif type == ::JsonApiClient::Schema::Types::Integer
158
144
  "::Integer"
@@ -171,9 +157,9 @@ module Tapioca
171
157
  end
172
158
 
173
159
  if property.default.nil?
174
- as_nilable_type(sorbet_type)
160
+ as_nilable_type(tapioca_type)
175
161
  else
176
- sorbet_type
162
+ tapioca_type
177
163
  end
178
164
  end
179
165
 
@@ -65,8 +65,6 @@ module Tapioca
65
65
  # ~~~
66
66
  #: [ConstantType = (Class[::Kredis::Attributes] & ::Kredis::Attributes::ClassMethods & Extensions::Kredis)]
67
67
  class Kredis < Compiler
68
- extend T::Sig
69
-
70
68
  # @override
71
69
  #: -> void
72
70
  def decorate
@@ -85,8 +83,6 @@ module Tapioca
85
83
  end
86
84
 
87
85
  class << self
88
- extend T::Sig
89
-
90
86
  # @override
91
87
  #: -> Enumerable[T::Module[top]]
92
88
  def gather_constants
@@ -46,8 +46,6 @@ module Tapioca
46
46
  # ~~~
47
47
  #: [ConstantType = T::Module[top]]
48
48
  class MixedInClassAttributes < Compiler
49
- extend T::Sig
50
-
51
49
  # @override
52
50
  #: -> void
53
51
  def decorate
@@ -60,8 +58,6 @@ module Tapioca
60
58
  end
61
59
 
62
60
  class << self
63
- extend T::Sig
64
-
65
61
  # @override
66
62
  #: -> Enumerable[T::Module[top]]
67
63
  def gather_constants
@@ -73,8 +73,6 @@ module Tapioca
73
73
  prop :default, String
74
74
  end
75
75
 
76
- extend T::Sig
77
-
78
76
  FIELD_RE = /^[a-z_][a-zA-Z0-9_]*$/
79
77
 
80
78
  # @override
@@ -153,8 +151,6 @@ module Tapioca
153
151
  end
154
152
 
155
153
  class << self
156
- extend T::Sig
157
-
158
154
  # @override
159
155
  #: -> Enumerable[T::Module[top]]
160
156
  def gather_constants
@@ -35,8 +35,6 @@ module Tapioca
35
35
  # ~~~
36
36
  #: [ConstantType = singleton(::Rails::Generators::Base)]
37
37
  class RailsGenerators < Compiler
38
- extend T::Sig
39
-
40
38
  BUILT_IN_MATCHER = /::(ActionMailbox|ActionText|ActiveRecord|Rails)::Generators/
41
39
 
42
40
  # @override
@@ -57,8 +55,6 @@ module Tapioca
57
55
  end
58
56
 
59
57
  class << self
60
- extend T::Sig
61
-
62
58
  # @override
63
59
  #: -> Enumerable[T::Module[top]]
64
60
  def gather_constants
@@ -43,8 +43,6 @@ module Tapioca
43
43
  # * `self.perform_in` will also accept a `ActiveSupport::Duration` value
44
44
  #: [ConstantType = singleton(::Sidekiq::Worker)]
45
45
  class SidekiqWorker < Compiler
46
- extend T::Sig
47
-
48
46
  # @override
49
47
  #: -> void
50
48
  def decorate
@@ -84,8 +82,6 @@ module Tapioca
84
82
  end
85
83
 
86
84
  class << self
87
- extend T::Sig
88
-
89
85
  # @override
90
86
  #: -> Enumerable[T::Module[top]]
91
87
  def gather_constants
@@ -60,8 +60,6 @@ module Tapioca
60
60
  # ~~~
61
61
  #: [ConstantType = singleton(::SmartProperties)]
62
62
  class SmartProperties < Compiler
63
- extend T::Sig
64
-
65
63
  # @override
66
64
  #: -> void
67
65
  def decorate
@@ -81,8 +79,6 @@ module Tapioca
81
79
  end
82
80
 
83
81
  class << self
84
- extend T::Sig
85
-
86
82
  # @override
87
83
  #: -> Enumerable[T::Module[top]]
88
84
  def gather_constants
@@ -111,8 +111,6 @@ module Tapioca
111
111
  # ~~~
112
112
  #: [ConstantType = (T::Module[top] & ::StateMachines::ClassMethods)]
113
113
  class StateMachines < Compiler
114
- extend T::Sig
115
-
116
114
  # @override
117
115
  #: -> void
118
116
  def decorate
@@ -155,8 +153,6 @@ module Tapioca
155
153
  end
156
154
 
157
155
  class << self
158
- extend T::Sig
159
-
160
156
  # @override
161
157
  #: -> Enumerable[T::Module[top]]
162
158
  def gather_constants
@@ -80,8 +80,6 @@ module Tapioca
80
80
  # ~~~
81
81
  #: [ConstantType = T::Module[top]]
82
82
  class UrlHelpers < Compiler
83
- extend T::Sig
84
-
85
83
  # @override
86
84
  #: -> void
87
85
  def decorate
@@ -97,7 +95,6 @@ module Tapioca
97
95
  end
98
96
 
99
97
  class << self
100
- extend T::Sig
101
98
  # @override
102
99
  #: -> Enumerable[T::Module[top]]
103
100
  def gather_constants
@@ -6,8 +6,6 @@ module Tapioca
6
6
  module Helpers
7
7
  module ActiveModelTypeHelper
8
8
  class << self
9
- extend T::Sig
10
-
11
9
  # Returns the type indicated by the custom ActiveModel::Type::Value.
12
10
  # Accepts subclasses of ActiveModel::Type::Value as well as classes that implement similar methods.
13
11
  #: (untyped type_value) -> String
@@ -7,12 +7,9 @@ module Tapioca
7
7
  module Dsl
8
8
  module Helpers
9
9
  class ActiveRecordColumnTypeHelper
10
- extend T::Sig
11
10
  include RBIHelper
12
11
 
13
12
  class ColumnTypeOption < T::Enum
14
- extend T::Sig
15
-
16
13
  enums do
17
14
  Untyped = new("untyped")
18
15
  Nilable = new("nilable")
@@ -20,8 +17,6 @@ module Tapioca
20
17
  end
21
18
 
22
19
  class << self
23
- extend T::Sig
24
-
25
20
  #: (
26
21
  #| Hash[String, untyped] options,
27
22
  #| ) { (String value, ColumnTypeOption default_column_type_option) -> void } -> ColumnTypeOption
@@ -5,8 +5,6 @@ module Tapioca
5
5
  module Dsl
6
6
  module Helpers
7
7
  module ActiveRecordConstantsHelper
8
- extend T::Sig
9
-
10
8
  ReflectionType = T.type_alias do
11
9
  T.any(::ActiveRecord::Reflection::ThroughReflection, ::ActiveRecord::Reflection::AssociationReflection)
12
10
  end
@@ -7,8 +7,6 @@ module Tapioca
7
7
  module GraphqlTypeHelper
8
8
  extend self
9
9
 
10
- extend T::Sig
11
-
12
10
  #: (
13
11
  #| GraphQL::Schema::Argument argument,
14
12
  #| (singleton(GraphQL::Schema::Mutation) | singleton(GraphQL::Schema::InputObject)) constant
@@ -4,8 +4,6 @@
4
4
  module Tapioca
5
5
  module Dsl
6
6
  class Pipeline
7
- extend T::Sig
8
-
9
7
  #: Enumerable[singleton(Compiler)]
10
8
  attr_reader :active_compilers
11
9
 
@@ -3,8 +3,6 @@
3
3
 
4
4
  module Tapioca
5
5
  class Executor
6
- extend T::Sig
7
-
8
6
  MINIMUM_ITEMS_PER_WORKER = 2 #: Integer
9
7
 
10
8
  #: (Array[untyped] queue, ?number_of_workers: Integer?) -> void
@@ -5,12 +5,9 @@ module Tapioca
5
5
  module Gem
6
6
  # @abstract
7
7
  class Event
8
- extend T::Sig
9
8
  end
10
9
 
11
10
  class SymbolFound < Event
12
- extend T::Sig
13
-
14
11
  #: String
15
12
  attr_reader :symbol
16
13
 
@@ -22,8 +19,6 @@ module Tapioca
22
19
  end
23
20
 
24
21
  class ConstantFound < Event
25
- extend T::Sig
26
-
27
22
  #: String
28
23
  attr_reader :symbol
29
24
 
@@ -41,8 +36,6 @@ module Tapioca
41
36
  end
42
37
 
43
38
  class ForeignConstantFound < ConstantFound
44
- extend T::Sig
45
-
46
39
  # @override
47
40
  #: -> T::Module[top]
48
41
  def constant
@@ -57,8 +50,6 @@ module Tapioca
57
50
 
58
51
  # @abstract
59
52
  class NodeAdded < Event
60
- extend T::Sig
61
-
62
53
  #: String
63
54
  attr_reader :symbol
64
55
 
@@ -74,8 +65,6 @@ module Tapioca
74
65
  end
75
66
 
76
67
  class ConstNodeAdded < NodeAdded
77
- extend T::Sig
78
-
79
68
  #: RBI::Const
80
69
  attr_reader :node
81
70
 
@@ -87,8 +76,6 @@ module Tapioca
87
76
  end
88
77
 
89
78
  class ScopeNodeAdded < NodeAdded
90
- extend T::Sig
91
-
92
79
  #: RBI::Scope
93
80
  attr_reader :node
94
81
 
@@ -102,8 +89,6 @@ module Tapioca
102
89
  class ForeignScopeNodeAdded < ScopeNodeAdded; end
103
90
 
104
91
  class MethodNodeAdded < NodeAdded
105
- extend T::Sig
106
-
107
92
  #: UnboundMethod
108
93
  attr_reader :method
109
94
 
@@ -6,7 +6,6 @@ module Tapioca
6
6
  module Listeners
7
7
  # @abstract
8
8
  class Base
9
- extend T::Sig
10
9
  #: (Pipeline pipeline) -> void
11
10
  def initialize(pipeline)
12
11
  @pipeline = pipeline
@@ -0,0 +1,94 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Tapioca
5
+ module Gem
6
+ module Listeners
7
+ class Documentation < Base
8
+ IGNORED_COMMENTS = [
9
+ ":doc:",
10
+ ":nodoc:",
11
+ "typed:",
12
+ "frozen_string_literal:",
13
+ "encoding:",
14
+ "warn_indent:",
15
+ "shareable_constant_value:",
16
+ "rubocop:",
17
+ "@requires_ancestor:",
18
+ ] #: Array[String]
19
+
20
+ #: (Pipeline pipeline, Rubydex::Graph gem_graph) -> void
21
+ def initialize(pipeline, gem_graph)
22
+ super(pipeline)
23
+
24
+ @gem_graph = gem_graph
25
+ end
26
+
27
+ private
28
+
29
+ #: (String line) -> bool
30
+ def rbs_comment?(line)
31
+ line.start_with?(": ", "| ")
32
+ end
33
+
34
+ # @override
35
+ #: (ConstNodeAdded event) -> void
36
+ def on_const(event)
37
+ event.node.comments = documentation_comments(event.symbol)
38
+ end
39
+
40
+ # @override
41
+ #: (ScopeNodeAdded event) -> void
42
+ def on_scope(event)
43
+ event.node.comments = documentation_comments(event.symbol)
44
+ end
45
+
46
+ # @override
47
+ #: (MethodNodeAdded event) -> void
48
+ def on_method(event)
49
+ name = if event.constant.singleton_class?
50
+ "#{event.symbol}::<#{event.symbol.split("::").last}>##{event.node.name}()"
51
+ else
52
+ "#{event.symbol}##{event.node.name}()"
53
+ end
54
+ event.node.comments = documentation_comments(name, sigs: event.node.sigs)
55
+ end
56
+
57
+ #: (String name, ?sigs: Array[RBI::Sig]) -> Array[RBI::Comment]
58
+ def documentation_comments(name, sigs: [])
59
+ declaration = @gem_graph[name]
60
+ # For attr_writer methods (name ending in =), fall back to reader docs
61
+ if declaration.nil? && name.end_with?("=()")
62
+ declaration = @gem_graph[name.delete_suffix("=()") + "()"]
63
+ end
64
+ # For singleton methods (Class::<Class>#method()), fall back to instance method docs.
65
+ # This handles module_function and extend self methods which Rubydex indexes
66
+ # only under the instance method name.
67
+ if declaration.nil? && name.include?("::<")
68
+ declaration = @gem_graph[name.sub(/::<[^>]+>#/, "#")]
69
+ end
70
+ return [] unless declaration
71
+
72
+ comments = declaration.definitions.flat_map(&:comments)
73
+ comments.uniq!
74
+ return [] if comments.empty?
75
+
76
+ lines = comments
77
+ .map { |comment| comment.string.gsub(/^#+ ?/, "") }
78
+ .reject { |line| IGNORED_COMMENTS.any? { |comment| line.include?(comment) } || rbs_comment?(line) }
79
+
80
+ # Strip leading and trailing blank lines, matching YARD's behavior
81
+ lines = lines.reverse_each.drop_while(&:empty?).reverse_each.drop_while(&:empty?)
82
+
83
+ lines.map! { |line| RBI::Comment.new(line) }
84
+ end
85
+
86
+ # @override
87
+ #: (NodeAdded event) -> bool
88
+ def ignore?(event)
89
+ event.is_a?(Tapioca::Gem::ForeignScopeNodeAdded)
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -5,8 +5,6 @@ module Tapioca
5
5
  module Gem
6
6
  module Listeners
7
7
  class DynamicMixins < Base
8
- extend T::Sig
9
-
10
8
  include Runtime::Reflection
11
9
 
12
10
  private
@@ -5,8 +5,6 @@ module Tapioca
5
5
  module Gem
6
6
  module Listeners
7
7
  class ForeignConstants < Base
8
- extend T::Sig
9
-
10
8
  include Runtime::Reflection
11
9
 
12
10
  private
@@ -5,8 +5,6 @@ module Tapioca
5
5
  module Gem
6
6
  module Listeners
7
7
  class Methods < Base
8
- extend T::Sig
9
-
10
8
  include RBIHelper
11
9
  include Runtime::Reflection
12
10
 
@@ -5,8 +5,6 @@ module Tapioca
5
5
  module Gem
6
6
  module Listeners
7
7
  class Mixins < Base
8
- extend T::Sig
9
-
10
8
  include Runtime::Reflection
11
9
 
12
10
  private
@@ -5,8 +5,6 @@ module Tapioca
5
5
  module Gem
6
6
  module Listeners
7
7
  class RemoveEmptyPayloadScopes < Base
8
- extend T::Sig
9
-
10
8
  include Runtime::Reflection
11
9
 
12
10
  private
@@ -5,8 +5,6 @@ module Tapioca
5
5
  module Gem
6
6
  module Listeners
7
7
  class SorbetEnums < Base
8
- extend T::Sig
9
-
10
8
  private
11
9
 
12
10
  # @override
@@ -5,8 +5,6 @@ module Tapioca
5
5
  module Gem
6
6
  module Listeners
7
7
  class SorbetHelpers < Base
8
- extend T::Sig
9
-
10
8
  include Runtime::Reflection
11
9
 
12
10
  private