From 595f384b60b8a3ce38e8c906cc33510ba6a24089 Mon Sep 17 00:00:00 2001 From: Daniel Orner Date: Wed, 19 Jul 2023 14:42:29 -0400 Subject: [PATCH 1/4] Update Parlour and resolve root namespaces --- lib/sord/resolver.rb | 19 +++++++++++++------ sord.gemspec | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/sord/resolver.rb b/lib/sord/resolver.rb index f7a45d2..0f9606d 100644 --- a/lib/sord/resolver.rb +++ b/lib/sord/resolver.rb @@ -70,14 +70,21 @@ def self.add_rbi_objects_to_paths(nodes, names_to_paths, path=[]) klasses = [ Parlour::RbiGenerator::Constant, Parlour::RbiGenerator::ModuleNamespace, - Parlour::RbiGenerator::ClassNamespace + Parlour::RbiGenerator::ClassNamespace, + Parlour::RbiGenerator::Namespace + ] + child_only_classes = [ + Parlour::RbiGenerator::Namespace ] nodes.each do |node| - next unless klasses.include?(node.class) - new_path = path + [node.name] - names_to_paths[node.name] ||= Set.new - names_to_paths[node.name] << new_path.join('::') - add_rbi_objects_to_paths(node.children, names_to_paths, new_path) if node.respond_to?(:children) + if klasses.include?(node.class) + new_path = path + [node.name] + unless child_only_classes.include?(node.class) + names_to_paths[node.name] ||= Set.new + names_to_paths[node.name] << new_path.join('::') + end + add_rbi_objects_to_paths(node.children, names_to_paths, new_path) if node.respond_to?(:children) + end end end diff --git a/sord.gemspec b/sord.gemspec index 0705801..e32df25 100644 --- a/sord.gemspec +++ b/sord.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'yard' spec.add_dependency 'sorbet-runtime' spec.add_dependency 'commander', '~> 4.5' - spec.add_dependency 'parlour', '~> 5.0' + spec.add_dependency 'parlour', '~> 8.0' spec.add_dependency 'rbs', '~> 3.0' spec.add_development_dependency "bundler", "~> 2.0" From 37c84ebe87e970187d72beb893f6366c21c70e69 Mon Sep 17 00:00:00 2001 From: Daniel Orner Date: Wed, 19 Jul 2023 14:52:34 -0400 Subject: [PATCH 2/4] This test fails now since parlour doesn't package rbi files --- spec/resolver_spec.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spec/resolver_spec.rb b/spec/resolver_spec.rb index 8586891..abd86f2 100644 --- a/spec/resolver_spec.rb +++ b/spec/resolver_spec.rb @@ -161,8 +161,4 @@ class B expect(subject.path_for('B')).to be nil # Ambiguous end - it 'resolves included gem rbi files' do - subject.prepare - expect(subject.path_for('Parlour::TypeLoader')).to eq 'Parlour::TypeLoader' - end end From 3ebd863cf5e1b750b5f3507bfccbeb490d1b8c62 Mon Sep 17 00:00:00 2001 From: Daniel Orner Date: Wed, 19 Jul 2023 14:55:53 -0400 Subject: [PATCH 3/4] Redo this - *only* read the sorbet directory --- lib/sord/resolver.rb | 11 +++-------- spec/resolver_spec.rb | 4 ++++ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/sord/resolver.rb b/lib/sord/resolver.rb index 0f9606d..c7641cf 100644 --- a/lib/sord/resolver.rb +++ b/lib/sord/resolver.rb @@ -30,14 +30,9 @@ def self.load_gem_objects(hash) end add_rbs_objects_to_paths(env, hash) - gem_paths = Bundler.load.specs.map(&:full_gem_path) - gem_paths.each do |path| - next unless File.exist?("#{path}/rbi") - - Dir["#{path}/rbi/**/*.rbi"].each do |sigfile| - tree = Parlour::TypeLoader.load_file(sigfile) - add_rbi_objects_to_paths(tree.children, hash) - end + Dir["#{Dir.pwd}/sorbet/rbi/**/*.rbi"].each do |sigfile| + tree = Parlour::TypeLoader.load_file(sigfile) + add_rbi_objects_to_paths(tree.children, hash) end end diff --git a/spec/resolver_spec.rb b/spec/resolver_spec.rb index abd86f2..736ce9e 100644 --- a/spec/resolver_spec.rb +++ b/spec/resolver_spec.rb @@ -161,4 +161,8 @@ class B expect(subject.path_for('B')).to be nil # Ambiguous end + it 'resolves included gem rbi files' do + subject.prepare + expect(subject.path_for('Parlour::RbiGenerator')).to eq 'Parlour::RbiGenerator' + end end From 714ab955a0332beedc0598fedcbf2f2721199750 Mon Sep 17 00:00:00 2001 From: Daniel Orner Date: Wed, 19 Jul 2023 15:43:35 -0400 Subject: [PATCH 4/4] put back RBI --- lib/sord/resolver.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/sord/resolver.rb b/lib/sord/resolver.rb index c7641cf..323ccfc 100644 --- a/lib/sord/resolver.rb +++ b/lib/sord/resolver.rb @@ -30,9 +30,14 @@ def self.load_gem_objects(hash) end add_rbs_objects_to_paths(env, hash) - Dir["#{Dir.pwd}/sorbet/rbi/**/*.rbi"].each do |sigfile| - tree = Parlour::TypeLoader.load_file(sigfile) - add_rbi_objects_to_paths(tree.children, hash) + gem_paths = Bundler.load.specs.map(&:full_gem_path) + ["#{Dir.pwd}/sorbet"] + gem_paths.each do |path| + next unless File.exist?("#{path}/rbi") + + Dir["#{path}/rbi/**/*.rbi"].each do |sigfile| + tree = Parlour::TypeLoader.load_file(sigfile) + add_rbi_objects_to_paths(tree.children, hash) + end end end