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.

@sg-ignore Declared return type generic<T>, nil does not match

inferred type ::YARD::CodeObjects::Base, nil for
Solargraph::ApiMap::SourceToYard#code_object_at

Parameters:

  • path (String)
  • klass (Class<generic<T>>) (defaults to: YARD::CodeObjects::Base)

Returns:

  • (generic<T>, nil)


15
16
17
18
# File 'lib/solargraph/api_map/source_to_yard.rb', line 15

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>

Returns:

  • (Array<String>)


21
22
23
# File 'lib/solargraph/api_map/source_to_yard.rb', line 21

def code_object_paths
  code_object_map.keys
end

#rake_yard(store) ⇒ void

This method returns an undefined value.

Parameters:



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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/solargraph/api_map/source_to_yard.rb', line 27

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
      # @param obj [YARD::CodeObjects::RootObject]
      code_object_map[pin.path] ||= YARD::CodeObjects::ClassObject.new(root_code_object, pin.path) do |obj|
        # @sg-ignore flow sensitive typing needs to handle attrs
        next if pin.location.nil? || pin.location.filename.nil?
        # @sg-ignore flow sensitive typing needs to handle attrs
        obj.add_file(pin.location.filename, pin.location.range.start.line, !pin.comments.empty?)
      end
    else
      # @param obj [YARD::CodeObjects::RootObject]
      code_object_map[pin.path] ||= YARD::CodeObjects::ModuleObject.new(root_code_object, pin.path) do |obj|
        # @sg-ignore flow sensitive typing needs to handle attrs
        next if pin.location.nil? || pin.location.filename.nil?
        # @sg-ignore flow sensitive typing needs to handle attrs
        obj.add_file(pin.location.filename, pin.location.range.start.line, !pin.comments.empty?)
      end
    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)
      unless include_object.nil? || include_object.nil?
        include_object.instance_mixins.push code_object_map[ref.type.to_s]
      end
    end
    store.get_extends(pin.path).each do |ref|
      extend_object = code_object_at(pin.path, YARD::CodeObjects::ClassObject)
      next unless extend_object
      code_object = code_object_map[ref.type.to_s]
      next unless code_object
      extend_object.class_mixins.push code_object
      extend_object.instance_mixins.push code_object
    end
  end
  store.method_pins.each do |pin|
    if pin.code_object
      code_object_map[pin.path] ||= pin.code_object
      next
    end

    # @sg-ignore Need to add nil check here
    # @param obj [YARD::CodeObjects::RootObject]
    code_object_map[pin.path] ||= YARD::CodeObjects::MethodObject.new(
      code_object_at(pin.namespace, YARD::CodeObjects::NamespaceObject), pin.name, pin.scope
    ) do |obj|
      # @sg-ignore flow sensitive typing needs to handle attrs
      next if pin.location.nil? || pin.location.filename.nil?
      # @sg-ignore flow sensitive typing needs to handle attrs
      obj.add_file pin.location.filename, pin.location.range.start.line
    end
    method_object = code_object_at(pin.path, YARD::CodeObjects::MethodObject)
    # @sg-ignore Need to add nil check here
    method_object.docstring = pin.docstring
    # @sg-ignore Need to add nil check here
    method_object.visibility = pin.visibility || :public
    # @sg-ignore Need to add nil check here
    method_object.parameters = pin.parameters.map do |p|
      [p.full_name, p.asgn_code]
    end
  end
end