Class: Solargraph::Pin::Attribute

Inherits:
BaseMethod show all
Defined in:
lib/solargraph/pin/attribute.rb

Instance Attribute Summary collapse

Attributes inherited from BaseMethod

#visibility

Attributes inherited from Closure

#scope

Attributes inherited from Base

#code_object, #location, #name, #return_type

Attributes included from Common

#closure, #location

Instance Method Summary collapse

Methods inherited from BaseMethod

#parameter_names, #parameters, #return_type, #typify

Methods inherited from Closure

#binder, #context

Methods inherited from Base

#==, #comments, #deprecated?, #directives, #docstring, #filename, #infer, #inspect, #macros, #maybe_directives?, #nearly?, #probed?, #proxied?, #proxy, #realize, #to_s, #try_merge!, #typify, #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

#binder, #comments, #context, #name, #namespace, #return_type

Constructor Details

#initialize(access: :reader, **splat) ⇒ Attribute

Returns a new instance of Attribute

Parameters:

  • access (::Symbol)

    :reader or :writer


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

def initialize access: :reader, **splat
  super(splat)
  @access = access
end

Instance Attribute Details

#access::Symbol (readonly)

Returns :reader or :writer

Returns:

  • (::Symbol)

    :reader or :writer


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

def access
  @access
end

Instance Method Details

#completion_item_kindObject


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

def completion_item_kind
  Solargraph::LanguageServer::CompletionItemKinds::PROPERTY
end

#kindObject


13
14
15
# File 'lib/solargraph/pin/attribute.rb', line 13

def kind
  Solargraph::Pin::ATTRIBUTE
end

#pathObject


25
26
27
# File 'lib/solargraph/pin/attribute.rb', line 25

def path
  @path ||= namespace + (scope == :instance ? '#' : '.') + name
end

#probe(api_map) ⇒ Object


29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/solargraph/pin/attribute.rb', line 29

def probe api_map
  types = []
  varname = "@#{name.gsub(/=$/, '')}"
  pins = api_map.get_instance_variable_pins(binder.namespace, binder.scope).select { |iv| iv.name == varname }
  pins.each do |pin|
    type = pin.typify(api_map)
    type = pin.probe(api_map) if type.undefined?
    types.push type if type.defined?
  end
  return ComplexType::UNDEFINED if types.empty?
  ComplexType.try_parse(*types.map(&:tag).uniq)
end

#symbol_kindObject


21
22
23
# File 'lib/solargraph/pin/attribute.rb', line 21

def symbol_kind
  Solargraph::LanguageServer::SymbolKinds::PROPERTY
end