Class: Solargraph::Pin::Namespace

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

Direct Known Subclasses

YardPin::Namespace

Instance Attribute Summary collapse

Attributes inherited from Base

#code_object, #location, #name

Attributes included from Common

#closure, #location

Instance Method Summary collapse

Methods inherited from Closure

#context

Methods inherited from Base

#==, #comments, #deprecated?, #directives, #docstring, #filename, #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

Methods included from Common

#comments, #context, #name

Constructor Details

#initialize(type: :class, visibility: :public, **splat) ⇒ Namespace

def initialize location, namespace, name, comments, type, visibility


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/solargraph/pin/namespace.rb', line 11

def initialize type: :class, visibility: :public, **splat
  # super(location, namespace, name, comments)
  super(splat)
  @type = type
  @visibility = visibility
  if name.start_with?('::')
    @name = name[2..-1]
    @closure = Pin::ROOT_PIN
  end
  @gate = @name
  if @gate.include?('::')
    parts = @gate.split('::')
    @name = parts.last
    adjusted = (@closure ? @closure.path : Pin::ROOT_PIN.path).split('::') + parts[0..-2]
    # @closure = Pin::Base.new(kind: NAMESPACE, name: adjusted.join('::'))
    @closure = Pin::Namespace.new(name: adjusted.join('::'))
    @context = nil
  end
end

Instance Attribute Details

#type::Symbol (readonly)

Returns :class or :module

Returns:

  • (::Symbol)

    :class or :module


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

def type
  @type
end

#visibility::Symbol (readonly)

Returns :public or :private

Returns:

  • (::Symbol)

    :public or :private


5
6
7
# File 'lib/solargraph/pin/namespace.rb', line 5

def visibility
  @visibility
end

Instance Method Details

#binderObject


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

def binder
  full_context
end

#completion_item_kindObject


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

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

#domainsObject


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

def domains
  @domains ||= []
end

#full_contextObject


39
40
41
# File 'lib/solargraph/pin/namespace.rb', line 39

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

#kindObject


35
36
37
# File 'lib/solargraph/pin/namespace.rb', line 35

def kind
  Pin::NAMESPACE
end

#namespaceObject


31
32
33
# File 'lib/solargraph/pin/namespace.rb', line 31

def namespace
  context.namespace
end

#pathObject


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

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

#return_typeObject


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

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

#scopeObject


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

def scope
  context.scope
end

#symbol_kindInteger

Returns:

  • (Integer)

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

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

#typify(api_map) ⇒ Object


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

def typify api_map
  return_type
end