Class: Solargraph::Pin::Attribute

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

Instance Attribute Summary collapse

Attributes inherited from BaseMethod

#node, #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

#documentation, #explicit?, #parameter_names, #parameters, #return_type, #typify

Methods inherited from Closure

#binder, #context, #gates

Methods inherited from Base

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

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) (defaults to: :reader)

    :reader or :writer



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/solargraph/pin/attribute.rb', line 10

def initialize access: :reader, **splat
  super(**splat)
  @access = access
  if access == :writer
    parameters.push(
      Pin::Parameter.new(name: 'value', decl: :arg, closure: self)
    )
    if return_type.defined?
      docstring.add_tag YARD::Tags::Tag.new(:param, '', return_type.to_s.split(', '), 'value')
    end
  end
end

Instance Attribute Details

#access::Symbol (readonly)

Returns :reader or :writer.

Returns:

  • (::Symbol)

    :reader or :writer



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

def access
  @access
end

Instance Method Details

#completion_item_kindObject



23
24
25
# File 'lib/solargraph/pin/attribute.rb', line 23

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

#pathObject



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

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

#probe(api_map) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/solargraph/pin/attribute.rb', line 35

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



27
28
29
# File 'lib/solargraph/pin/attribute.rb', line 27

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