Class: Solargraph::Pin::Namespace

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

Instance Attribute Summary collapse

Attributes inherited from Base

#code_object, #location, #name, #source

Attributes included from Common

#closure, #location

Instance Method Summary collapse

Methods inherited from Closure

#context

Methods inherited from Base

#==, #comments, #deprecated?, #directives, #docstring, #filename, #identity, #infer, #inspect, #macros, #maybe_directives?, #nearly?, #probe, #probed?, #proxied?, #proxy, #realize, #to_s, #try_merge!, #variable?

Methods included from Documenting

#documentation

Methods included from Conversions

#completion_item, #detail, #link_documentation, #reset_conversions, #resolve_completion_item, #signature_help, #text_documentation

Methods included from Common

#comments, #context, #name

Constructor Details

#initialize(type: :class, visibility: :public, gates: [''], parameters: [], **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: [''])


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/solargraph/pin/namespace.rb', line 17

def initialize type: :class, visibility: :public, gates: [''], parameters: [], **splat
  # super(location, namespace, name, comments)
  super(**splat)
  @type = type
  @visibility = visibility
  if name.start_with?('::')
    @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('::')])
    @context = nil
  end
  @parameters = parameters
end

Instance Attribute Details

#parametersObject (readonly)

Returns the value of attribute parameters.



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

def parameters
  @parameters
end

#type::Symbol (readonly)

Returns :class or :module.

Returns:

  • (::Symbol)

    :class or :module



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

def type
  @type
end

#visibility::Symbol (readonly)

Returns :public or :private.

Returns:

  • (::Symbol)

    :public or :private



7
8
9
# File 'lib/solargraph/pin/namespace.rb', line 7

def visibility
  @visibility
end

Instance Method Details

#binderObject



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

def binder
  full_context
end

#completion_item_kindObject



60
61
62
# File 'lib/solargraph/pin/namespace.rb', line 60

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

#domainsObject



77
78
79
# File 'lib/solargraph/pin/namespace.rb', line 77

def domains
  @domains ||= []
end

#full_contextObject



48
49
50
# File 'lib/solargraph/pin/namespace.rb', line 48

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

#gatesObject



85
86
87
88
89
90
91
# File 'lib/solargraph/pin/namespace.rb', line 85

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

#namespaceObject



44
45
46
# File 'lib/solargraph/pin/namespace.rb', line 44

def namespace
  context.namespace
end

#pathObject



69
70
71
# File 'lib/solargraph/pin/namespace.rb', line 69

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

#return_typeObject



73
74
75
# File 'lib/solargraph/pin/namespace.rb', line 73

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

#scopeObject



56
57
58
# File 'lib/solargraph/pin/namespace.rb', line 56

def scope
  context.scope
end

#symbol_kindInteger

Returns:

  • (Integer)


65
66
67
# File 'lib/solargraph/pin/namespace.rb', line 65

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

#typify(api_map) ⇒ Object



81
82
83
# File 'lib/solargraph/pin/namespace.rb', line 81

def typify api_map
  return_type
end