Skip to content

Commit

Permalink
Include acts like extend inside sclass
Browse files Browse the repository at this point in the history
  • Loading branch information
castwide committed Sep 12, 2020
1 parent 9924401 commit 53b3af0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/solargraph/parser/rubyvm/node_processors/send_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def process_include
return unless Parser.is_ast_node?(node.children.last)
node.children.last.children[0..-2].each do |i|
next unless [:COLON2, :COLON3, :CONST].include?(i.type)
pins.push Pin::Reference::Include.new(
type = region.scope == :class ? Pin::Reference::Extend : Pin::Reference::Include
pins.push type.new(
location: get_node_location(i),
closure: region.closure,
name: unpack_name(i)
Expand Down
2 changes: 1 addition & 1 deletion lib/solargraph/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Solargraph
VERSION = '0.39.15'
VERSION = '0.39.16'
end
18 changes: 18 additions & 0 deletions spec/api_map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -704,4 +704,22 @@ def self.inside █ end
expect(names).to include('@var2')
expect(names).not_to include('@var3')
end

it 'finds class methods from modules included from class << self' do
source = Solargraph::Source.load_string(%(
module Extender
def foo; end
end
class Example
class << self
include Extender
end
end
))
api_map = Solargraph::ApiMap.new
api_map.map source
pins = api_map.get_methods('Example', scope: :class)
expect(pins.map(&:name)).to include('foo')
end
end
16 changes: 16 additions & 0 deletions spec/source_map/node_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,20 @@ def bar(&arg); end
))
expect(map.locals.first.decl).to eq(:blockarg)
end

it 'generates extend pins for modules included in class << self' do
map = Solargraph::SourceMap.load_string(%(
module Extender
def foo; end
end
class Example
class << self
include Extender
end
end
))
ext = map.pins.select { |pin| pin.is_a?(Solargraph::Pin::Reference::Extend) }.first
expect(ext.name).to eq('Extender')
end
end

0 comments on commit 53b3af0

Please sign in to comment.