From db0aa94604066defbd53371bc781d3210f24fcba Mon Sep 17 00:00:00 2001 From: Vince Broz Date: Sat, 26 Apr 2025 09:01:34 -0400 Subject: [PATCH 1/4] Improve inspect()/desc()/to_s() methods for better debugging output --- lib/solargraph/complex_type.rb | 4 ++++ lib/solargraph/complex_type/unique_type.rb | 4 ++++ lib/solargraph/pin/base.rb | 22 ++++++++++++++++------ lib/solargraph/pin/namespace.rb | 2 +- lib/solargraph/source/chain.rb | 8 ++++++++ lib/solargraph/source/chain/link.rb | 11 ++++++++++- 6 files changed, 43 insertions(+), 8 deletions(-) diff --git a/lib/solargraph/complex_type.rb b/lib/solargraph/complex_type.rb index 7f1e81b09..f87efd2a4 100644 --- a/lib/solargraph/complex_type.rb +++ b/lib/solargraph/complex_type.rb @@ -130,6 +130,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 6dfd9d2b0..09b10812e 100644 --- a/lib/solargraph/complex_type/unique_type.rb +++ b/lib/solargraph/complex_type/unique_type.rb @@ -92,6 +92,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 13b2e4c15..9a6394dd7 100644 --- a/lib/solargraph/pin/base.rb +++ b/lib/solargraph/pin/base.rb @@ -99,7 +99,7 @@ def symbol_kind end def to_s - to_rbs + desc end # @return [Boolean] @@ -272,19 +272,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/namespace.rb b/lib/solargraph/pin/namespace.rb index d4e66a354..1f5bba45d 100644 --- a/lib/solargraph/pin/namespace.rb +++ b/lib/solargraph/pin/namespace.rb @@ -48,7 +48,7 @@ def desc if name.nil? '(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 699eb1c40..148a30f0b 100644 --- a/lib/solargraph/source/chain.rb +++ b/lib/solargraph/source/chain.rb @@ -148,6 +148,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 e3ef36229..7a2a91da5 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? From 7a43b1a4fed2c3e6e5dc72f2d5505bba4828680e Mon Sep 17 00:00:00 2001 From: Vince Broz Date: Sat, 26 Apr 2025 09:25:57 -0400 Subject: [PATCH 2/4] Improve inspect()/desc()/to_s() methods for better debugging output --- lib/solargraph/pin/base_variable.rb | 4 ++-- spec/pin/parameter_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/solargraph/pin/base_variable.rb b/lib/solargraph/pin/base_variable.rb index 4c42351aa..0cb1f3ffe 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/spec/pin/parameter_spec.rb b/spec/pin/parameter_spec.rb index ce9ea5e1b..362e02abb 100644 --- a/spec/pin/parameter_spec.rb +++ b/spec/pin/parameter_spec.rb @@ -139,7 +139,7 @@ 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 From 879f3d650737d6b97a1287b337743279b68ac6bd Mon Sep 17 00:00:00 2001 From: Vince Broz Date: Tue, 29 Apr 2025 16:34:15 -0400 Subject: [PATCH 3/4] Improve inspect()/desc()/to_s() methods for better debugging output --- lib/solargraph/api_map.rb | 9 +++++++++ lib/solargraph/api_map/cache.rb | 9 +++++++++ 2 files changed, 18 insertions(+) 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] From dbe2886008b8a7b6dfe483d061d3e6380c6087d1 Mon Sep 17 00:00:00 2001 From: Vince Broz Date: Tue, 29 Apr 2025 16:39:08 -0400 Subject: [PATCH 4/4] Improve inspect()/desc()/to_s() methods for better debugging output --- lib/solargraph/api_map/store.rb | 8 ++++++++ 1 file changed, 8 insertions(+) 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]