File tree Expand file tree Collapse file tree 5 files changed +40
-6
lines changed
Expand file tree Collapse file tree 5 files changed +40
-6
lines changed Original file line number Diff line number Diff line change @@ -11,9 +11,9 @@ class ComplexType
1111 autoload :TypeMethods , 'solargraph/complex_type/type_methods'
1212 autoload :UniqueType , 'solargraph/complex_type/unique_type'
1313
14- # @param types [Array<UniqueType>]
14+ # @param types [Array<[ UniqueType, ComplexType] >]
1515 def initialize types = [ UniqueType ::UNDEFINED ]
16- @items = types . uniq ( &:to_s )
16+ @items = types . flat_map ( & :items ) . uniq ( &:to_s )
1717 end
1818
1919 # @param api_map [ApiMap]
@@ -136,10 +136,10 @@ def all_params
136136 @items . first . all_params || [ ]
137137 end
138138
139- protected
140-
141139 attr_reader :items
142140
141+ protected
142+
143143 def reduce_object
144144 return self if name != 'Object' || subtypes . empty?
145145 ComplexType . try_parse ( reduce_class ( subtypes . join ( ', ' ) ) )
Original file line number Diff line number Diff line change @@ -51,6 +51,10 @@ def to_s
5151 tag
5252 end
5353
54+ def items
55+ [ self ]
56+ end
57+
5458 def to_rbs
5559 "#{ namespace } #{ parameters? ? "[#{ subtypes . map { |s | s . to_rbs } . join ( ', ' ) } ]" : '' } "
5660 end
@@ -127,7 +131,7 @@ def self_to dst
127131 def selfy?
128132 @name == 'self' || @key_types . any? ( &:selfy? ) || @subtypes . any? ( &:selfy? )
129133 end
130-
134+
131135 UNDEFINED = UniqueType . new ( 'undefined' )
132136 BOOLEAN = UniqueType . new ( 'Boolean' )
133137 end
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ def symbol_kind
4646 end
4747
4848 def return_type
49- @return_type ||= ComplexType . try_parse ( * signatures . map ( &:return_type ) . map ( &:to_s ) )
49+ @return_type ||= ComplexType . new ( signatures . map ( &:return_type ) . flat_map ( &:items ) )
5050 end
5151
5252 # @return [Signature]
Original file line number Diff line number Diff line change 4747 expect ( types . first . scope ) . to eq ( :instance )
4848 end
4949
50+ it "identify rooted types" do
51+ types = Solargraph ::ComplexType . parse '::Array'
52+ expect ( types . map ( &:rooted? ) ) . to eq ( [ true ] )
53+ end
54+
55+ it "identify unrooted types" do
56+ types = Solargraph ::ComplexType . parse 'Array'
57+ expect ( types . map ( &:rooted? ) ) . to eq ( [ false ] )
58+ end
59+
5060 it "detects namespace and scope for classes with subtypes" do
5161 types = Solargraph ::ComplexType . parse 'Class<String>'
5262 expect ( types . length ) . to eq ( 1 )
Original file line number Diff line number Diff line change @@ -42,6 +42,26 @@ def foo bar:, baz: MyClass.new
4242 expect ( pin . documentation ) . to include ( 'description2' )
4343 end
4444
45+ it "tracks rooted status in return types" do
46+ source = Solargraph ::Source . new ( <<~COMMENTS )
47+ class Foo; end
48+ module Bar
49+ class Foo; end
50+ class Baz
51+ # @return [::Foo]
52+ def bing; end
53+ # @return [Foo]
54+ def bazzle; end
55+ end
56+ end
57+ COMMENTS
58+ map = Solargraph ::SourceMap . map ( source )
59+ bazzle = map . pins . select { |pin | pin . path == 'Bar::Baz#bazzle' } . first
60+ expect ( bazzle . return_type . rooted? ) . to eq ( false )
61+ bing = map . pins . select { |pin | pin . path == 'Bar::Baz#bing' } . first
62+ expect ( bing . return_type . rooted? ) . to eq ( true )
63+ end
64+
4565 it "includes yieldparam tags in documentation" do
4666 comments = <<~COMMENTS
4767 @yieldparam one [First] description1
You can’t perform that action at this time.
0 commit comments