Module: Solargraph::YardMap::Helpers

Included in:
Mapper::ToConstant, Mapper::ToMethod, Mapper::ToNamespace, ToMethod
Defined in:
lib/solargraph/yard_map/helpers.rb

Class Method Summary collapse

Class Method Details

.create_closure_namespace_for(code_object, spec) ⇒ Solargraph::Pin::Namespace

Parameters:

  • code_object (YARD::CodeObjects::Base)
  • spec (Gem::Specification, nil)

Returns:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/solargraph/yard_map/helpers.rb', line 24

def create_closure_namespace_for(code_object, spec)
  code_object_for_location = code_object
  # code_object.namespace is sometimes a YARD proxy object pointing to a method path ("Object#new")

  code_object_for_location = code_object.namespace if code_object.namespace.is_a?(YARD::CodeObjects::NamespaceObject)
  namespace_location = object_location(code_object_for_location, spec)
  ns_name = code_object.namespace.to_s
  if ns_name.empty?
    Solargraph::Pin::ROOT_PIN
  else
    Solargraph::Pin::Namespace.new(
      name: ns_name,
      closure: Pin::ROOT_PIN,
      gates: [code_object.namespace.to_s],
      source: :yardoc,
      location: namespace_location
    )
  end
end

.object_location(code_object, spec) ⇒ Solargraph::Location?

Parameters:

  • code_object (YARD::CodeObjects::Base)
  • spec (Gem::Specification, nil)

Returns:



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/solargraph/yard_map/helpers.rb', line 9

def object_location code_object, spec
  if spec.nil? || code_object.nil? || code_object.file.nil? || code_object.line.nil?
    if code_object.namespace.is_a?(YARD::CodeObjects::NamespaceObject)
      # If the code object is a namespace, use the namespace's location

      return object_location(code_object.namespace, spec)
    end
    return Solargraph::Location.new(__FILE__, Solargraph::Range.from_to(__LINE__ - 1, 0, __LINE__ - 1, 0))
  end
  file = File.join(spec.full_gem_path, code_object.file)
  Solargraph::Location.new(file, Solargraph::Range.from_to(code_object.line - 1, 0, code_object.line - 1, 0))
end