Skip to content

Commit 3649e0b

Browse files
committed
Filter Rubydex declarations to namespaces, constants, and aliases
1 parent d368c8c commit 3649e0b

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

lib/tapioca/gem/pipeline.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def initialize(
3232

3333
@payload_symbols = Static::SymbolLoader.payload_symbols #: Set[String]
3434
gem_graph = Static::SymbolLoader.graph_from_paths(@gem.files) #: Rubydex::Graph
35-
gem_symbols = gem_graph.declarations.map(&:name).to_set
35+
gem_symbols = Static::SymbolLoader.symbols_from_graph(gem_graph)
3636
engine_symbols = Static::SymbolLoader.engine_symbols(@gem)
3737
@bootstrap_symbols = gem_symbols.union(engine_symbols) #: Set[String]
3838

lib/tapioca/static/symbol_loader.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,28 @@ def graph_from_paths(paths)
2626
graph
2727
end
2828

29+
#: (Rubydex::Graph graph) -> Set[String]
30+
def symbols_from_graph(graph)
31+
graph.declarations.filter_map do |decl|
32+
next unless decl.is_a?(Rubydex::Namespace) ||
33+
decl.is_a?(Rubydex::Constant) ||
34+
decl.is_a?(Rubydex::ConstantAlias) ||
35+
decl.is_a?(Rubydex::Todo)
36+
37+
# Declarations added by `graph.resolve` only have `rubydex:built-in` definitions.
38+
# We exclude those unless the namespace has method or constant members defined in
39+
# source files, which indicates a class reopening (e.g. `class Object; def Nokogiri(); end`).
40+
if decl.definitions.any? && decl.definitions.all? { |defn| defn.location.uri == "rubydex:built-in" }
41+
next unless decl.is_a?(Rubydex::Namespace) && decl.members.any? do |m|
42+
(m.is_a?(Rubydex::Method) || m.is_a?(Rubydex::Constant) || m.is_a?(Rubydex::ConstantAlias)) &&
43+
m.definitions.any?
44+
end
45+
end
46+
47+
decl.name
48+
end.to_set
49+
end
50+
2951
#: (Gemfile::GemSpec gem) -> Set[String]
3052
def engine_symbols(gem)
3153
gem_engine = engines.find do |engine|
@@ -47,7 +69,7 @@ def engine_symbols(gem)
4769
end
4870

4971
engine_graph = graph_from_paths(paths)
50-
engine_graph.declarations.map(&:name).to_set
72+
symbols_from_graph(engine_graph)
5173
rescue
5274
Set.new
5375
end

0 commit comments

Comments
 (0)