Class: Solargraph::Pin::Namespace

Inherits:
Closure show all
Defined in:
lib/solargraph/pin/namespace.rb

Constant Summary

Constants included from Logging

Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS

Instance Attribute Summary collapse

Attributes inherited from Base

#code_object, #combine_priority, #directives, #docstring, #location, #name, #source, #type_location

Attributes included from Common

#context, #location

Instance Method Summary collapse

Methods inherited from Closure

#combine_with, #context, #generic_defaults, #generics, #rbs_generics

Methods inherited from Base

#==, #all_location_text, #all_rooted?, #assert_location_provided, #assert_same, #assert_same_array_content, #assert_same_count, #assert_same_macros, #assert_source_provided, #best_location, #choose, #choose_longer, #choose_node, #choose_pin_attr, #choose_pin_attr_with_same_name, #choose_priority, #combine_directives, #combine_name, #combine_return_type, #combine_with, #comments, #deprecated?, #desc, #dodgy_return_type_source?, #erase_generics, #filename, #identity, #infer, #inspect, #macros, #maybe_directives?, #nearly?, #needs_consistent_name?, #prefer_rbs_location, #presence_certain?, #probe, #probed?, #proxied?, #proxy, #rbs_location?, #realize, #reset_generated!, #resolve_generics, #resolve_generics_from_context, #to_s, #transform_types, #type_desc, #variable?

Methods included from Logging

logger

Methods included from Documenting

#documentation, normalize_indentation, strip_html_comments

Methods included from Conversions

#completion_item, #deprecated?, #detail, #link_documentation, #probed?, #proxied?, #reset_conversions, #resolve_completion_item, #signature_help, #text_documentation

Methods included from Common

#comments, #name, #source

Constructor Details

#initialize(type: :class, visibility: :public, gates: [''], name: '', **splat) ⇒ Namespace

Returns a new instance of Namespace.

Parameters:

  • type (::Symbol) (defaults to: :class)

    :class or :module

  • visibility (::Symbol) (defaults to: :public)

    :public or :private

  • gates (::Array<String>) (defaults to: [''])
  • name (String) (defaults to: '')


23
24
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
# File 'lib/solargraph/pin/namespace.rb', line 23

def initialize type: :class, visibility: :public, gates: [''], name: '', **splat
  # super(location, namespace, name, comments)
  super(**splat, name: name)
  @type = type
  @visibility = visibility
  if name.start_with?('::')
    # @type [String]
    name = name[2..-1] || ''
    @closure = Solargraph::Pin::ROOT_PIN
  end
  @open_gates = gates
  if name.include?('::')
    # In this case, a chained namespace was opened (e.g., Foo::Bar)
    # but Foo does not exist.
    parts = name.split('::')
    name = parts.pop
    closure_name = if [Solargraph::Pin::ROOT_PIN, nil].include?(closure)
      ''
    else
      closure.full_context.namespace + '::'
    end
    closure_name += parts.join('::')
    @closure = Pin::Namespace.new(name: closure_name, gates: [parts.join('::')], source: :namespace)
    @context = nil
  end
  @name = name
end

Instance Attribute Details

#closureObject (readonly)

does not assert like super, as a namespace without a closure may be the root level namespace, or it may not yet be qualified



17
18
19
# File 'lib/solargraph/pin/namespace.rb', line 17

def closure
  @closure
end

#type::Symbol (readonly)

Returns :class or :module.

Returns:

  • (::Symbol)

    :class or :module



12
13
14
# File 'lib/solargraph/pin/namespace.rb', line 12

def type
  @type
end

#visibility::Symbol (readonly)

Returns :public or :private.

Returns:

  • (::Symbol)

    :public or :private



9
10
11
# File 'lib/solargraph/pin/namespace.rb', line 9

def visibility
  @visibility
end

Instance Method Details

#binderObject



71
72
73
# File 'lib/solargraph/pin/namespace.rb', line 71

def binder
  full_context
end

#completion_item_kindObject



79
80
81
# File 'lib/solargraph/pin/namespace.rb', line 79

def completion_item_kind
  (type == :class ? LanguageServer::CompletionItemKinds::CLASS : LanguageServer::CompletionItemKinds::MODULE)
end

#domainsArray<String>

Returns:

  • (Array<String>)


98
99
100
# File 'lib/solargraph/pin/namespace.rb', line 98

def domains
  @domains ||= []
end

#full_contextObject



67
68
69
# File 'lib/solargraph/pin/namespace.rb', line 67

def full_context
  @full_context ||= ComplexType.try_parse("::#{type.to_s.capitalize}<#{path}>")
end

#gatesObject



106
107
108
109
110
111
112
# File 'lib/solargraph/pin/namespace.rb', line 106

def gates
  @gates ||= if path.empty?
    @open_gates
  else
    [path] + @open_gates
  end
end

#inner_descObject



55
56
57
58
59
60
61
# File 'lib/solargraph/pin/namespace.rb', line 55

def inner_desc
  if name.nil? || name.empty?
    '(top-level)'
  else
    super
  end
end

#namespaceObject



63
64
65
# File 'lib/solargraph/pin/namespace.rb', line 63

def namespace
  context.namespace
end

#pathString

Returns:

  • (String)


89
90
91
# File 'lib/solargraph/pin/namespace.rb', line 89

def path
  @path ||= (namespace.empty? ? '' : "#{namespace}::") + name
end

#return_typeObject



93
94
95
# File 'lib/solargraph/pin/namespace.rb', line 93

def return_type
  @return_type ||= ComplexType.try_parse( (type == :class ? '::Class' : '::Module') + "<::#{path}>")
end

#scopeObject



75
76
77
# File 'lib/solargraph/pin/namespace.rb', line 75

def scope
  context.scope
end

#symbol_kindInteger

Returns:

  • (Integer)


84
85
86
# File 'lib/solargraph/pin/namespace.rb', line 84

def symbol_kind
  (type == :class ? LanguageServer::SymbolKinds::CLASS : LanguageServer::SymbolKinds::MODULE)
end

#to_rbsObject



51
52
53
# File 'lib/solargraph/pin/namespace.rb', line 51

def to_rbs
  "#{@type.to_s} #{return_type.all_params.first.to_rbs}#{rbs_generics}".strip
end

#typify(api_map) ⇒ Object



102
103
104
# File 'lib/solargraph/pin/namespace.rb', line 102

def typify api_map
  return_type
end