Class: Solargraph::Suggestion
- Inherits:
-
Object
- Object
- Solargraph::Suggestion
- Defined in:
- lib/solargraph/suggestion.rb
Constant Summary collapse
- CLASS =
'Class'- CONSTANT =
'Constant'- FIELD =
'Field'- KEYWORD =
'Keyword'- METHOD =
'Method'- MODULE =
'Module'- PROPERTY =
'Property'- SNIPPET =
'Snippet'- VARIABLE =
'Variable'
Instance Attribute Summary collapse
- #arguments ⇒ Array<String> readonly
- #code_object ⇒ YARD::CodeObjects::Base readonly
- #detail ⇒ String readonly
- #insert ⇒ String readonly
- #kind ⇒ String readonly
- #label ⇒ String readonly
- #location ⇒ String readonly
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(args = {}) ⇒ Object
- #docstring ⇒ YARD::Docstring
- #documentation ⇒ String
-
#initialize(label, kind: KEYWORD, insert: nil, detail: nil, docstring: nil, code_object: nil, location: nil, arguments: [], return_type: nil, path: nil) ⇒ Suggestion
constructor
A new instance of Suggestion.
- #inject_detail ⇒ Object
- #params ⇒ Array<String>
- #path ⇒ String
- #return_type ⇒ String
- #to_json(args = {}) ⇒ Object
- #to_s ⇒ String
Constructor Details
#initialize(label, kind: KEYWORD, insert: nil, detail: nil, docstring: nil, code_object: nil, location: nil, arguments: [], return_type: nil, path: nil) ⇒ Suggestion
Returns a new instance of Suggestion.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/solargraph/suggestion.rb', line 37 def initialize label, kind: KEYWORD, insert: nil, detail: nil, docstring: nil, code_object: nil, location: nil, arguments: [], return_type: nil, path: nil @helper = Server::Helpers.new @label = label.to_s @kind = kind @insert = insert || @label @detail = detail @code_object = code_object @docstring = docstring @location = location @arguments = arguments @return_type = return_type @path = path end |
Instance Attribute Details
#arguments ⇒ Array<String> (readonly)
35 36 37 |
# File 'lib/solargraph/suggestion.rb', line 35 def arguments @arguments end |
#code_object ⇒ YARD::CodeObjects::Base (readonly)
29 30 31 |
# File 'lib/solargraph/suggestion.rb', line 29 def code_object @code_object end |
#detail ⇒ String (readonly)
26 27 28 |
# File 'lib/solargraph/suggestion.rb', line 26 def detail @detail end |
#insert ⇒ String (readonly)
23 24 25 |
# File 'lib/solargraph/suggestion.rb', line 23 def insert @insert end |
#kind ⇒ String (readonly)
20 21 22 |
# File 'lib/solargraph/suggestion.rb', line 20 def kind @kind end |
#label ⇒ String (readonly)
17 18 19 |
# File 'lib/solargraph/suggestion.rb', line 17 def label @label end |
#location ⇒ String (readonly)
32 33 34 |
# File 'lib/solargraph/suggestion.rb', line 32 def location @location end |
Class Method Details
.pull(pin, return_type = nil) ⇒ Object
123 124 125 |
# File 'lib/solargraph/suggestion.rb', line 123 def self.pull pin, return_type = nil Suggestion.new(pin.name, insert: pin.name.gsub(/=/, ' = '), kind: pin.kind, docstring: pin.docstring, detail: pin.namespace, arguments: pin.parameters, path: pin.path, return_type: return_type, location: pin.location) end |
Instance Method Details
#as_json(args = {}) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/solargraph/suggestion.rb', line 102 def as_json args = {} result = { label: @label, kind: @kind, insert: @insert, detail: @detail, path: path, location: (@location.nil? ? nil : @location.to_s), arguments: @arguments, params: params, return_type: return_type } result[:documentation] = documentation if args[:all] result end |
#docstring ⇒ YARD::Docstring
72 73 74 |
# File 'lib/solargraph/suggestion.rb', line 72 def docstring @docstring ||= @code_object.nil? ? nil : @code_object.docstring end |
#documentation ⇒ String
77 78 79 |
# File 'lib/solargraph/suggestion.rb', line 77 def documentation @documentation ||= (docstring.nil? ? '' : @helper.html_markup_rdoc(docstring)) end |
#inject_detail ⇒ Object
99 100 |
# File 'lib/solargraph/suggestion.rb', line 99 def inject_detail end |
#params ⇒ Array<String>
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/solargraph/suggestion.rb', line 82 def params if @params.nil? @params = [] return @params if docstring.nil? = docstring.(:param) unless .empty? .each do |t| txt = t.name.to_s txt += " [#{t.types.join(',')}]" unless t.types.nil? or t.types.empty? txt += " #{t.text}" unless t.text.nil? or t.text.empty? @params.push txt end end end @params end |
#path ⇒ String
52 53 54 |
# File 'lib/solargraph/suggestion.rb', line 52 def path @path ||= (code_object.nil? ? label : code_object.path) end |
#return_type ⇒ String
62 63 64 65 66 67 68 69 |
# File 'lib/solargraph/suggestion.rb', line 62 def return_type if @return_type.nil? and !docstring.nil? ol = docstring.tag(:overload) t = ol.nil? ? docstring.tag(:return) : ol.tag(:return) @return_type = t.types[0] unless t.nil? or t.types.nil? end @return_type end |
#to_json(args = {}) ⇒ Object
118 119 120 |
# File 'lib/solargraph/suggestion.rb', line 118 def to_json args = {} as_json.to_json(args) end |
#to_s ⇒ String
57 58 59 |
# File 'lib/solargraph/suggestion.rb', line 57 def to_s label end |