Class: Solargraph::Suggestion

Inherits:
Object
  • Object
show all
Defined in:
lib/solargraph/suggestion.rb

Constant Summary collapse

CLASS =
'Class'
KEYWORD =
'Keyword'
MODULE =
'Module'
METHOD =
'Method'
VARIABLE =
'Variable'
SNIPPET =
'Snippet'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, kind: KEYWORD, insert: nil, detail: nil, documentation: nil, code_object: nil, location: nil) ⇒ Suggestion

Returns a new instance of Suggestion.



15
16
17
18
19
20
21
22
23
# File 'lib/solargraph/suggestion.rb', line 15

def initialize label, kind: KEYWORD, insert: nil, detail: nil, documentation: nil, code_object: nil, location: nil
  @label = label.to_s
  @kind = kind
  @insert = insert || @label
  @detail = detail
  @code_object = code_object
  @documentation = documentation
  @location = location
end

Instance Attribute Details

#code_object ⇒ Object (readonly)

Returns the value of attribute code_object.



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

def code_object
  @code_object
end

#detail ⇒ Object (readonly)

Returns the value of attribute detail.



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

def detail
  @detail
end

#documentation ⇒ Object (readonly)

Returns the value of attribute documentation.



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

def documentation
  @documentation
end

#insert ⇒ Object (readonly)

Returns the value of attribute insert.



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

def insert
  @insert
end

#kind ⇒ Object (readonly)

Returns the value of attribute kind.



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

def kind
  @kind
end

#label ⇒ Object (readonly)

Returns the value of attribute label.



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

def label
  @label
end

#location ⇒ Object (readonly)

Returns the value of attribute location.



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

def location
  @location
end

Instance Method Details

#path ⇒ Object



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

def path
  code_object.nil? ? label : code_object.path
end

#return_type ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/solargraph/suggestion.rb', line 33

def return_type
  if code_object.nil?
    unless documentation.nil?
      match = documentation.all.match(/@return \[([a-z0-9:_]*)/i)
      return match[1]
    end
  else
    o = code_object.tag(:overload)
    if o.nil?
      r = code_object.tag(:return)
    else
      r = o.tag(:return)
    end
    return r.types[0] unless r.nil?
  end
  nil
end

#to_json(args = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/solargraph/suggestion.rb', line 51

def to_json args={}
  obj = {
    label: @label,
    kind: @kind,
    insert: @insert,
    detail: @detail,
    path: path,
    location: (@location.nil? ? nil : @location.to_s)
  }
  if @code_object.nil?
    obj[:documentation] = @documentation.all unless @documentation.nil?
  else
    obj[:documentation] = @code_object.docstring.all unless @code_object.docstring.nil?
  end
  obj.to_json(args)
end

#to_s ⇒ Object



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

def to_s
  label
end