Module: Solargraph::ApiMap::SourceToYard

Defined in:
lib/solargraph/api_map/source_to_yard.rb

Instance Method Summary collapse

Instance Method Details

#code_object_at(path, klass = YARD::CodeObjects::Base) ⇒ generic<T>?

Get the YARD CodeObject at the specified path.



13
14
15
16
# File 'lib/solargraph/api_map/source_to_yard.rb', line 13

def code_object_at path, klass = YARD::CodeObjects::Base
  obj = code_object_map[path]
  obj if obj&.is_a?(klass)
end

#code_object_pathsArray<String>



19
20
21
# File 'lib/solargraph/api_map/source_to_yard.rb', line 19

def code_object_paths
  code_object_map.keys
end

#rake_yard(store) ⇒ void



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/solargraph/api_map/source_to_yard.rb', line 25

def rake_yard store
  YARD::Registry.clear
  code_object_map.clear
  store.namespace_pins.each do |pin|
    next if pin.path.nil? || pin.path.empty?
    if pin.code_object
      code_object_map[pin.path] ||= pin.code_object
      next
    end
    if pin.type == :class
      code_object_map[pin.path] ||= YARD::CodeObjects::ClassObject.new(root_code_object, pin.path) { |obj|
        next if pin.location.nil? || pin.location.filename.nil?
        obj.add_file(pin.location.filename, pin.location.range.start.line, !pin.comments.empty?)
      }
    else
      code_object_map[pin.path] ||= YARD::CodeObjects::ModuleObject.new(root_code_object, pin.path) { |obj|
        next if pin.location.nil? || pin.location.filename.nil?
        obj.add_file(pin.location.filename, pin.location.range.start.line, !pin.comments.empty?)
      }
    end
    code_object_map[pin.path].docstring = pin.docstring
    store.get_includes(pin.path).each do |ref|
      include_object = code_object_at(pin.path, YARD::CodeObjects::ClassObject)
      include_object.instance_mixins.push code_object_map[ref] unless include_object.nil? or include_object.nil?
    end
    store.get_extends(pin.path).each do |ref|
      extend_object = code_object_at(pin.path, YARD::CodeObjects::ClassObject)
      extend_object.instance_mixins.push code_object_map[ref] unless extend_object.nil? or extend_object.nil?
      extend_object.class_mixins.push code_object_map[ref] unless extend_object.nil? or extend_object.nil?
    end
  end
  store.method_pins.each do |pin|
    if pin.code_object
      code_object_map[pin.path] ||= pin.code_object
      next
    end

    code_object_map[pin.path] ||= YARD::CodeObjects::MethodObject.new(code_object_at(pin.namespace, YARD::CodeObjects::NamespaceObject), pin.name, pin.scope) { |obj|
      next if pin.location.nil? || pin.location.filename.nil?
      obj.add_file pin.location.filename, pin.location.range.start.line
    }
    method_object = code_object_at(pin.path, YARD::CodeObjects::MethodObject)
    method_object.docstring = pin.docstring
    method_object.visibility = pin.visibility || :public
    method_object.parameters = pin.parameters.map do |p|
      [p.name, p.asgn_code]
    end
  end
end