class Solargraph::Pin::Base
The base class for map pins.
Attributes
@return [YARD::CodeObjects::Base]
@return [Solargraph::Location]
@return [String]
@return [String]
@return [Boolean]
@return [Boolean]
@return [ComplexType]
Public Class Methods
@param location [Solargraph::Location] @param kind [Integer] @param closure [Solargraph::Pin::Closure] @param name [String] @param comments [String]
# File lib/solargraph/pin/base.rb, line 29 def initialize location: nil, closure: nil, name: '', comments: '' @location = location @closure = closure @name = name @comments = comments end
Public Instance Methods
@return [String]
# File lib/solargraph/pin/base.rb, line 37 def comments @comments ||= '' end
@return [Integer]
# File lib/solargraph/pin/base.rb, line 48 def completion_item_kind LanguageServer::CompletionItemKinds::KEYWORD end
@return [Boolean]
# File lib/solargraph/pin/base.rb, line 128 def deprecated? @deprecated ||= docstring.has_tag?('deprecated') end
@return [Array<YARD::Tags::Directive>]
# File lib/solargraph/pin/base.rb, line 104 def directives parse_comments unless defined?(@directives) @directives end
@return [YARD::Docstring]
# File lib/solargraph/pin/base.rb, line 98 def docstring parse_comments unless defined?(@docstring) @docstring ||= Solargraph::Source.parse_docstring('').to_docstring end
@return [String, nil]
# File lib/solargraph/pin/base.rb, line 42 def filename return nil if location.nil? location.filename end
# File lib/solargraph/pin/base.rb, line 216 def identity @identity ||= "#{closure.context.namespace}|#{name}" end
@deprecated Use typify
and/or probe
instead @param api_map [ApiMap] @return [ComplexType]
# File lib/solargraph/pin/base.rb, line 155 def infer api_map Solargraph::Logging.logger.warn "WARNING: Pin #infer methods are deprecated. Use #typify or #probe instead." type = typify(api_map) return type unless type.undefined? probe api_map end
# File lib/solargraph/pin/base.rb, line 220 def inspect "#<#{self.class} `#{self.path}` at #{self.location.inspect}>" end
@return [Array<YARD::Tags::MacroDirective>]
# File lib/solargraph/pin/base.rb, line 110 def macros @macros ||= collect_macros end
Perform a quick check to see if this pin possibly includes YARD directives. This method does not require parsing the comments.
After the comments have been parsed, this method will return false if no directives were found, regardless of whether it previously appeared possible.
@return [Boolean]
# File lib/solargraph/pin/base.rb, line 122 def maybe_directives? return !@directives.empty? if defined?(@directives) @maybe_directives ||= comments.include?('@!') end
True if the specified pin is a near match to this one. A near match indicates that the pins contain mostly the same data. Any differences between them should not have an impact on the API surface.
@param other [Solargraph::Pin::Base, Object] @return [Boolean]
# File lib/solargraph/pin/base.rb, line 80 def nearly? other self.class == other.class && name == other.name && (closure == other.closure || (closure && closure.nearly?(other.closure))) && (comments == other.comments || (((maybe_directives? == false && other.maybe_directives? == false) || compare_directives(directives, other.directives)) && compare_docstring_tags(docstring, other.docstring)) ) end
Infer the pin's return type via static code analysis.
@param api_map [ApiMap] @return [ComplexType]
# File lib/solargraph/pin/base.rb, line 148 def probe api_map typify api_map end
# File lib/solargraph/pin/base.rb, line 186 def probed? @probed ||= false end
# File lib/solargraph/pin/base.rb, line 182 def proxied? @proxied ||= false end
Return a proxy for this pin with the specified return type. Other than the return type and the proxied?
setting, the proxy should be a clone of the original.
@param return_type
[ComplexType] @return [self]
# File lib/solargraph/pin/base.rb, line 209 def proxy return_type result = dup result.return_type = return_type result.proxied = true result end
@param api_map [ApiMap] @return [self]
# File lib/solargraph/pin/base.rb, line 192 def realize api_map return self if return_type.defined? type = typify(api_map) return proxy(type) if type.defined? type = probe(api_map) return self if type.undefined? result = proxy(type) result.probed = true result end
The pin's return type.
@return [ComplexType]
# File lib/solargraph/pin/base.rb, line 93 def return_type @return_type ||= ComplexType::UNDEFINED end
@return [Integer, nil]
# File lib/solargraph/pin/base.rb, line 53 def symbol_kind nil end
# File lib/solargraph/pin/base.rb, line 57 def to_s name.to_s end
Try to merge data from another pin. Merges are only possible if the pins are near matches (see the nearly?
method). The changes should not have any side effects on the API surface.
@param pin [Pin::Base] The pin to merge into this one @return [Boolean] True if the pins were merged
# File lib/solargraph/pin/base.rb, line 168 def try_merge! pin return false unless nearly?(pin) @location = pin.location @closure = pin.closure return true if comments == pin.comments @comments = pin.comments @docstring = pin.docstring @return_type = pin.return_type @documentation = nil @deprecated = nil reset_conversions true end
Get a fully qualified type from the pin's return type.
The relative type is determined from YARD documentation (@return, @param, @type, etc.) and its namespaces are fully qualified using the provided ApiMap
.
@param api_map [ApiMap] @return [ComplexType]
# File lib/solargraph/pin/base.rb, line 140 def typify api_map return_type.qualify(api_map, namespace) end
@return [Boolean]
# File lib/solargraph/pin/base.rb, line 62 def variable? false end
Private Instance Methods
@return [Array<YARD::Tags::Handlers::Directive>]
# File lib/solargraph/pin/base.rb, line 289 def collect_macros return [] unless maybe_directives? parse = Solargraph::Source.parse_docstring(comments) parse.directives.select{ |d| d.tag.tag_name == 'macro' } end
@param dir1 [Array<YARD::Tags::Directive>] @param dir2 [Array<YARD::Tags::Directive>] @return [Boolean]
# File lib/solargraph/pin/base.rb, line 269 def compare_directives dir1, dir2 return false if dir1.length != dir2.length dir1.each_index do |i| return false unless compare_tags(dir1[i].tag, dir2[i].tag) end true end
@return [void]
# File lib/solargraph/pin/base.rb, line 238 def parse_comments # HACK: Avoid a NoMethodError on nil with empty overload tags if comments.nil? || comments.empty? || comments.strip.end_with?('@overload') @docstring = nil @directives = [] else # HACK: Pass a dummy code object to the parser for plugins that # expect it not to be nil parse = Solargraph::Source.parse_docstring(comments) @docstring = parse.to_docstring @directives = parse.directives end end