15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/solargraph/yard_map/directives/method_directive.rb', line 15
def process_directive source, pins, source_position, , directive
namespace = closure_at(pins, source_position) || pins.first
namespace = closure_at(pins, ) if namespace.location&.range&.start&.line&.< .line begin
src = Solargraph::Source.load_string("def #{directive.tag.name};end", source.filename)
region = Parser::Region.new(source: src, closure: namespace)
method_gen_pins = Parser.process_node(src.node, region).first.select { |pin| pin.is_a?(Pin::Method) }
gen_pin = method_gen_pins.last
return [] if gen_pin.nil?
shifted = Solargraph::Position.new(.line,
source.code.lines[.line].to_s.chomp.length)
= Solargraph::Source.parse_docstring(directive.tag.text.to_s).to_docstring.all.to_s
gen_pin.instance_variable_set(:@comments, )
gen_pin.instance_variable_set(:@location,
Solargraph::Location.new(source.filename, Range.new(shifted, shifted)))
gen_pin.instance_variable_set(:@explicit, false)
[gen_pin]
rescue Parser::SyntaxError
[]
end
end
|