Class: Solargraph::Suggestion
- Inherits:
-
Object
- Object
- Solargraph::Suggestion
- Defined in:
- lib/solargraph/suggestion.rb
Overview
Information about a class, module, method, or variable.
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
-
.pull(pin, return_type = nil) ⇒ Object
Generate a suggestion from a pin.
Instance Method Summary collapse
- #as_json(args = {}) ⇒ Object
- #docstring ⇒ YARD::Docstring
- #documentation ⇒ String
-
#has_doc? ⇒ Boolean
True if the suggestion has documentation.
-
#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.
- #params ⇒ Array<String>
-
#path ⇒ String
The full path of the suggestion.
- #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.
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/solargraph/suggestion.rb', line 41 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)
36 37 38 |
# File 'lib/solargraph/suggestion.rb', line 36 def arguments @arguments end |
#code_object ⇒ YARD::CodeObjects::Base (readonly)
39 40 41 |
# File 'lib/solargraph/suggestion.rb', line 39 def code_object @code_object end |
#detail ⇒ String (readonly)
27 28 29 |
# File 'lib/solargraph/suggestion.rb', line 27 def detail @detail end |
#insert ⇒ String (readonly)
24 25 26 |
# File 'lib/solargraph/suggestion.rb', line 24 def insert @insert end |
#kind ⇒ String (readonly)
21 22 23 |
# File 'lib/solargraph/suggestion.rb', line 21 def kind @kind end |
#label ⇒ String (readonly)
18 19 20 |
# File 'lib/solargraph/suggestion.rb', line 18 def label @label end |
#location ⇒ String (readonly)
33 34 35 |
# File 'lib/solargraph/suggestion.rb', line 33 def location @location end |
Class Method Details
.pull(pin, return_type = nil) ⇒ Object
Generate a suggestion from a pin.
144 145 146 |
# File 'lib/solargraph/suggestion.rb', line 144 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 || pin.return_type, location: pin.location) end |
Instance Method Details
#as_json(args = {}) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/solargraph/suggestion.rb', line 120 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, has_doc: has_doc? } result[:documentation] = documentation if args[:all] result end |
#docstring ⇒ YARD::Docstring
84 85 86 |
# File 'lib/solargraph/suggestion.rb', line 84 def docstring @docstring ||= @code_object.nil? ? nil : @code_object.docstring end |
#documentation ⇒ String
89 90 91 |
# File 'lib/solargraph/suggestion.rb', line 89 def documentation @documentation ||= (docstring.nil? ? '' : @helper.html_markup_rdoc(docstring)) end |
#has_doc? ⇒ Boolean
True if the suggestion has documentation. Useful for determining whether a client should resolve a suggestion's path to retrieve more information about it.
116 117 118 |
# File 'lib/solargraph/suggestion.rb', line 116 def has_doc? !documentation.empty? end |
#params ⇒ Array<String>
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/solargraph/suggestion.rb', line 94 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
The full path of the suggestion.
Examples:
- MyClass
- MyModule::MyClass
- MyClass#instance_method
- MyModule.singleton_method
64 65 66 |
# File 'lib/solargraph/suggestion.rb', line 64 def path @path ||= (code_object.nil? ? label : code_object.path) end |
#return_type ⇒ String
74 75 76 77 78 79 80 81 |
# File 'lib/solargraph/suggestion.rb', line 74 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
137 138 139 |
# File 'lib/solargraph/suggestion.rb', line 137 def to_json args = {} as_json.to_json(args) end |
#to_s ⇒ String
69 70 71 |
# File 'lib/solargraph/suggestion.rb', line 69 def to_s label end |