Skip to content

Commit

Permalink
Resolve included namespaces with conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
castwide committed Sep 13, 2020
1 parent be66f03 commit 0052bd0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/solargraph/api_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ def inner_qualify name, root, skip
return nil if name.nil?
return nil if skip.include?(root)
skip.add root
possibles = []
if name == ''
if root == ''
return ''
Expand All @@ -672,16 +673,19 @@ def inner_qualify name, root, skip
incs = store.get_includes(roots.join('::'))
incs.each do |inc|
foundinc = inner_qualify(name, inc, skip)
return foundinc unless foundinc.nil?
possibles.push foundinc unless foundinc.nil?
end
roots.pop
end
incs = store.get_includes('')
incs.each do |inc|
foundinc = inner_qualify(name, inc, skip)
return foundinc unless foundinc.nil?
if possibles.empty?
incs = store.get_includes('')
incs.each do |inc|
foundinc = inner_qualify(name, inc, skip)
possibles.push foundinc unless foundinc.nil?
end
end
return name if store.namespace_exists?(name)
return possibles.last
end
end

Expand Down
18 changes: 18 additions & 0 deletions spec/api_map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,24 @@ module Includer
expect(fqns).to eq('Foo::Bar')
end

it "qualifies namespaces with conflicting includes" do
source = Solargraph::Source.load_string(%(
module Bar; end
module Foo
module Bar; end
end
module Foo
module Includer
include Bar
end
end
))
api_map = Solargraph::ApiMap.new
api_map.map source
fqns = api_map.qualify('Bar', 'Foo::Includer')
expect(fqns).to eq('Foo::Bar')
end

it "qualifies namespaces from root includes" do
source = Solargraph::Source.load_string(%(
module A
Expand Down

0 comments on commit 0052bd0

Please sign in to comment.