Class: Solargraph::Pin::Method

Inherits:
BaseMethod show all
Includes:
(rubyvm? ? Rubyvm::NodeMethods : Legacy(rubyvm? ? Rubyvm::NodeMethods : Legacy::NodeMethods)
Defined in:
lib/solargraph/pin/method.rb

Direct Known Subclasses

DuckMethod, YardPin::Method

Instance Attribute Summary collapse

Attributes inherited from BaseMethod

#node, #visibility

Attributes inherited from Closure

#scope

Attributes inherited from Base

#code_object, #location, #name, #path, #return_type

Attributes included from Common

#closure, #location

Instance Method Summary collapse

Methods inherited from BaseMethod

#documentation, #explicit?, #path, #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?, #probed?, #proxied?, #proxy, #realize, #to_s, #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, #path, #return_type

Constructor Details

#initialize(parameters: [], node: nil, **splat) ⇒ Method

Returns a new instance of Method.

Parameters:

  • args (Array<String>)
  • node (Parser::AST::Node, nil) (defaults to: nil)


13
14
15
16
17
# File 'lib/solargraph/pin/method.rb', line 13

def initialize parameters: [], node: nil, **splat
  super(**splat)
  @parameters = parameters
  @node = node
end

Instance Attribute Details

#parametersArray<String> (readonly)

Returns:

  • (Array<String>)


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

def parameters
  @parameters
end

Instance Method Details

#completion_item_kindObject



24
25
26
# File 'lib/solargraph/pin/method.rb', line 24

def completion_item_kind
  Solargraph::LanguageServer::CompletionItemKinds::METHOD
end

#nearly?(other) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
# File 'lib/solargraph/pin/method.rb', line 32

def nearly? other
  return false unless super
  parameters == other.parameters and
    scope == other.scope and
    visibility == other.visibility
end

#overloadsArray<Pin::Method>

Returns:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/solargraph/pin/method.rb', line 50

def overloads
  @overloads ||= docstring.tags(:overload).map do |tag|
    Solargraph::Pin::Method.new(
      name: name,
      closure: self,
      # args: tag.parameters.map(&:first),
      parameters: tag.parameters.map do |src|
        Pin::Parameter.new(
          location: location,
          closure: self,
          comments: tag.docstring.all.to_s,
          name: src.first,
          presence: location ? location.range : nil,
          decl: :arg
        )
      end,
      comments: tag.docstring.all.to_s
    )
  end
end

#parameter_namesArray<String>

Returns:

  • (Array<String>)


20
21
22
# File 'lib/solargraph/pin/method.rb', line 20

def parameter_names
  @parameter_names ||= parameters.map(&:name)
end

#probe(api_map) ⇒ Object



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

def probe api_map
  infer_from_return_nodes(api_map)
end

#symbol_kindObject



28
29
30
# File 'lib/solargraph/pin/method.rb', line 28

def symbol_kind
  LanguageServer::SymbolKinds::METHOD
end

#try_merge!(pin) ⇒ Object



43
44
45
46
47
# File 'lib/solargraph/pin/method.rb', line 43

def try_merge! pin
  return false unless super
  @node = pin.node
  true
end