Class: Solargraph::Pin::Method

Inherits:
Base
  • Object
show all
Defined in:
lib/solargraph/pin/method.rb

Direct Known Subclasses

DuckMethod, YardPin::Method

Instance Attribute Summary collapse

Attributes inherited from Base

#location, #name, #namespace

Instance Method Summary collapse

Methods inherited from Base

#==, #comments, #deprecated?, #directives, #docstring, #filename, #infer, #macros, #maybe_directives?, #return_type, #to_s, #try_merge!, #variable?

Methods included from Conversions

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

Constructor Details

#initialize(location, namespace, name, comments, scope, visibility, args) ⇒ Method

Returns a new instance of Method.



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

def initialize location, namespace, name, comments, scope, visibility, args
  super(location, namespace, name, comments)
  @scope = scope
  @visibility = visibility
  @parameters = args
end

Instance Attribute Details

#parametersArray<String> (readonly)

Returns:

  • (Array<String>)


11
12
13
# File 'lib/solargraph/pin/method.rb', line 11

def parameters
  @parameters
end

#scopeSymbol (readonly)

Returns :instance or :class.

Returns:

  • (Symbol)

    :instance or :class



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

def scope
  @scope
end

#visibilitySymbol (readonly)

Returns :public, :private, or :protected.

Returns:

  • (Symbol)

    :public, :private, or :protected



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

def visibility
  @visibility
end

Instance Method Details

#completion_item_kindObject



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

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

#contextObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/solargraph/pin/method.rb', line 33

def context
  @context ||= begin
    if scope == :class
      # @todo Determine whether the namespace is a class or a module
      ComplexType.parse("Class<#{namespace}>")
    else
      ComplexType.parse(namespace)
    end
  end
end

#documentationObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/solargraph/pin/method.rb', line 57

def documentation
  if @documentation.nil?
    @documentation ||= super || ''
    param_tags = docstring.tags(:param)
    unless param_tags.nil? or param_tags.empty?
      @documentation += "\n\n" unless @documentation.empty?
      @documentation += "Params:\n"
      lines = []
      param_tags.each do |p|
        l = "* #{p.name}"
        l += " [#{p.types.join(', ')}]" unless p.types.nil? or p.types.empty?
        l += " #{p.text}"
        lines.push l
      end
      @documentation += lines.join("\n")
    end
  end
  @documentation
end

#kindObject



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

def kind
  Solargraph::Pin::METHOD
end

#nearly?(other) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
80
81
82
# File 'lib/solargraph/pin/method.rb', line 77

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

#parameter_namesArray<String>

Returns:

  • (Array<String>)


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

def parameter_names
  @parameter_names ||= parameters.map{|p| p.split(/[ =:]/).first}
end

#pathObject



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

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

#return_complex_typeObject



53
54
55
# File 'lib/solargraph/pin/method.rb', line 53

def return_complex_type
  @return_complex_type ||= generate_complex_type
end

#symbol_kindInteger

Returns:

  • (Integer)


49
50
51
# File 'lib/solargraph/pin/method.rb', line 49

def symbol_kind
  LanguageServer::SymbolKinds::METHOD
end