@@ -136,12 +136,45 @@ def constant_in_gem?(name)
136
136
gem . contains_path? ( loc . file )
137
137
end
138
138
139
- sig { params ( method_name : Symbol , owner : Module ) . returns ( T . any ( [ String , Integer ] , NilClass , T ::Boolean ) ) }
139
+ class MethodDefinitionLookupResult
140
+ extend T ::Helpers
141
+ abstract!
142
+ end
143
+
144
+ # The method doesn't seem to exist
145
+ class MethodUnknown < MethodDefinitionLookupResult ; end
146
+
147
+ # The method is not defined in the gem
148
+ class MethodNotInGem < MethodDefinitionLookupResult ; end
149
+
150
+ # The method probably defined in the gem but doesn't have a source location
151
+ class MethodInGemWithoutLocation < MethodDefinitionLookupResult ; end
152
+
153
+ # The method defined in gem and has a source location
154
+ class MethodInGemWithLocation < MethodDefinitionLookupResult
155
+ extend T ::Sig
156
+
157
+ sig { returns ( Runtime ::SourceLocation ) }
158
+ attr_reader :location
159
+
160
+ sig { params ( location : Runtime ::SourceLocation ) . void }
161
+ def initialize ( location )
162
+ @location = location
163
+ super ( )
164
+ end
165
+ end
166
+
167
+ sig do
168
+ params (
169
+ method_name : Symbol ,
170
+ owner : Module ,
171
+ ) . returns ( MethodDefinitionLookupResult )
172
+ end
140
173
def method_definition_in_gem ( method_name , owner )
141
174
definitions = Tapioca ::Runtime ::Trackers ::MethodDefinition . method_definitions_for ( method_name , owner )
142
175
143
176
# If the source location of the method isn't available, signal that by returning nil.
144
- return if definitions . empty?
177
+ return MethodUnknown . new if definitions . empty?
145
178
146
179
# Look up the first entry that matches a file in the gem.
147
180
found = definitions . find { |loc | @gem . contains_path? ( loc . file ) }
@@ -151,13 +184,13 @@ def method_definition_in_gem(method_name, owner)
151
184
found = definitions . find { |loc | loc . file == "(eval)" }
152
185
# However, we can just return true to signal that the method should be included.
153
186
# We can't provide a source location for it, but we want it to be included in the gem RBI.
154
- return true if found
187
+ return MethodInGemWithoutLocation . new if found
155
188
end
156
189
157
190
# If we searched but couldn't find a source location in the gem, return false to signal that.
158
- return false unless found
191
+ return MethodNotInGem . new unless found
159
192
160
- found
193
+ MethodInGemWithLocation . new ( found )
161
194
end
162
195
163
196
# Helpers
0 commit comments