diff --git a/lib/solargraph/api_map.rb b/lib/solargraph/api_map.rb index 65b263628..095c156e0 100755 --- a/lib/solargraph/api_map.rb +++ b/lib/solargraph/api_map.rb @@ -48,6 +48,15 @@ def hash equality_fields.hash end + def to_s + self.class.to_s + end + + # avoid enormous dump + def inspect + to_s + end + # @param pins [Array] # @return [self] def index pins diff --git a/lib/solargraph/api_map/cache.rb b/lib/solargraph/api_map/cache.rb index 1edac7c7c..8fc60b03a 100644 --- a/lib/solargraph/api_map/cache.rb +++ b/lib/solargraph/api_map/cache.rb @@ -16,6 +16,15 @@ def initialize @clips = {} end + def to_s + self.class.to_s + end + + # avoid enormous dump + def inspect + to_s + end + # @param fqns [String] # @param scope [Symbol] # @param visibility [Array] diff --git a/lib/solargraph/api_map/store.rb b/lib/solargraph/api_map/store.rb index 2150e9915..3e987d5f1 100644 --- a/lib/solargraph/api_map/store.rb +++ b/lib/solargraph/api_map/store.rb @@ -16,6 +16,14 @@ def initialize pins = [] index end + def to_s + self.class.to_s + end + + def inspect + to_s + end + # @param fqns [String] # @param visibility [Array] # @return [Enumerable] diff --git a/lib/solargraph/complex_type.rb b/lib/solargraph/complex_type.rb index c9db3ab6e..88563ebfc 100644 --- a/lib/solargraph/complex_type.rb +++ b/lib/solargraph/complex_type.rb @@ -154,6 +154,10 @@ def to_s map(&:tag).join(', ') end + def desc + rooted_tags + end + def rooted_tags map(&:rooted_tag).join(', ') end diff --git a/lib/solargraph/complex_type/unique_type.rb b/lib/solargraph/complex_type/unique_type.rb index b51bd5d71..eef6320df 100644 --- a/lib/solargraph/complex_type/unique_type.rb +++ b/lib/solargraph/complex_type/unique_type.rb @@ -112,6 +112,10 @@ def rbs_name end end + def desc + rooted_tags + end + # @return [String] def to_rbs if duck_type? diff --git a/lib/solargraph/pin/base.rb b/lib/solargraph/pin/base.rb index 114442481..825a3c286 100644 --- a/lib/solargraph/pin/base.rb +++ b/lib/solargraph/pin/base.rb @@ -103,7 +103,7 @@ def symbol_kind end def to_s - to_rbs + desc end # @return [Boolean] @@ -276,19 +276,29 @@ def to_rbs return_type.to_rbs end - # @return [String, nil] - def desc + # @return [String] + def type_desc + rbs = to_rbs + # RBS doesn't have a way to represent a Class type + rbs = return_type.rooted_tags if return_type.name == 'Class' if path - if to_rbs - path + ' ' + to_rbs + if rbs + path + ' ' + rbs else path end else - to_rbs + rbs end end + # @return [String] + def desc + closure_info = closure&.desc + binder_info = binder&.desc + "[#{type_desc}, closure=#{closure_info}, binder=#{binder}" + end + def inspect "#<#{self.class} `#{self.desc}` at #{self.location.inspect}>" end diff --git a/lib/solargraph/pin/base_variable.rb b/lib/solargraph/pin/base_variable.rb index 77ee18e3e..e4758ee63 100644 --- a/lib/solargraph/pin/base_variable.rb +++ b/lib/solargraph/pin/base_variable.rb @@ -100,8 +100,8 @@ def try_merge! pin true end - def desc - "#{to_rbs} = #{assignment&.type.inspect}" + def type_desc + "#{super} = #{assignment&.type.inspect}" end private diff --git a/lib/solargraph/pin/namespace.rb b/lib/solargraph/pin/namespace.rb index 2da291961..6158626d8 100644 --- a/lib/solargraph/pin/namespace.rb +++ b/lib/solargraph/pin/namespace.rb @@ -48,7 +48,7 @@ def desc if name.nil? || name.empty? '(top-level)' else - to_rbs + return_type.rooted_tags end end diff --git a/lib/solargraph/source/chain.rb b/lib/solargraph/source/chain.rb index 9ae70713c..48b08775c 100644 --- a/lib/solargraph/source/chain.rb +++ b/lib/solargraph/source/chain.rb @@ -160,6 +160,14 @@ def nullable? links.any?(&:nullable?) end + def desc + links.map(&:desc).to_s + end + + def to_s + desc + end + private # @param pins [::Array] diff --git a/lib/solargraph/source/chain/link.rb b/lib/solargraph/source/chain/link.rb index ec33f8045..040297d7c 100644 --- a/lib/solargraph/source/chain/link.rb +++ b/lib/solargraph/source/chain/link.rb @@ -31,8 +31,17 @@ def resolve api_map, name_pin, locals [] end + # debugging description of contents; not for machine use + def desc + word + end + + def to_s + desc + end + def inspect - "#{self.class} #{word}" + "#<#{self.class} - `#{self.desc}`>" end def head? diff --git a/spec/pin/parameter_spec.rb b/spec/pin/parameter_spec.rb index 067152881..4f9915c70 100644 --- a/spec/pin/parameter_spec.rb +++ b/spec/pin/parameter_spec.rb @@ -139,7 +139,8 @@ def yielder(&blk) expect(method.documentation).to eq("Block Params:\n* [Array] \n\nBlock Returns:\n* [Integer] \n\nReturns:\n* [Integer] \n\nVisibility: public") expect(method.return_type.tag).to eq('Integer') - expect(map.locals.map(&:to_s)).to eq(['blk ::Proc', 'things Set']) + + expect(map.locals.map(&:to_rbs)).to eq(['blk ::Proc', 'things Set']) expect(map.locals.map(&:return_type).map(&:to_s)).to eq(%w[Proc Set]) expect(map.locals.map(&:decl)).to eq(%i[blockarg arg]) end