Class: Solargraph::SourceMap::Clip
- Inherits:
-
Object
- Object
- Solargraph::SourceMap::Clip
- Defined in:
- lib/solargraph/source_map/clip.rb
Overview
A static analysis tool for obtaining definitions, completions, signatures, and type inferences from a cursor.
Instance Method Summary collapse
- #complete ⇒ Completion
- #define ⇒ Array<Pin::Base>
- #infer ⇒ ComplexType
-
#initialize(api_map, cursor) ⇒ Clip
constructor
A new instance of Clip.
-
#locals ⇒ Array<Solargraph::Pin::Base>
Get an array of all the locals that are visible from the cursors’s position.
- #signify ⇒ Array<Pin::Base>
Constructor Details
#initialize(api_map, cursor) ⇒ Clip
Returns a new instance of Clip.
9 10 11 12 |
# File 'lib/solargraph/source_map/clip.rb', line 9 def initialize api_map, cursor @api_map = api_map @cursor = cursor end |
Instance Method Details
#complete ⇒ Completion
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/solargraph/source_map/clip.rb', line 23 def complete return package_completions(api_map.get_symbols) if cursor.chain.literal? && cursor.chain.links.last.word == '<Symbol>' return Completion.new([], cursor.range) if cursor.chain.literal? || cursor.comment? result = [] if cursor.chain.constant? || cursor.start_of_constant? if cursor.chain.undefined? type = cursor.chain.base.infer(api_map, context_pin, locals) else full = cursor.chain.links.first.word if full.include?('::') type = ComplexType.parse(full.split('::')[0..-2].join('::')) elsif cursor.chain.links.length > 1 type = ComplexType.parse(full) else type = ComplexType::UNDEFINED end end result.concat api_map.get_constants(type.undefined? ? '' : type.namespace, cursor.start_of_constant? ? '' : context_pin.context.namespace) else type = cursor.chain.base.infer(api_map, context_pin, locals) result.concat api_map.get_complex_type_methods(type, context_pin.context.namespace, cursor.chain.links.length == 1) if cursor.chain.links.length == 1 if cursor.word.start_with?('@@') return package_completions(api_map.get_class_variable_pins(context_pin.context.namespace)) elsif cursor.word.start_with?('@') return package_completions(api_map.get_instance_variable_pins(context_pin.context.namespace, context_pin.context.scope)) elsif cursor.word.start_with?('$') return package_completions(api_map.get_global_variable_pins) end result.concat locals result.concat api_map.get_constants('', context_pin.context.namespace) result.concat api_map.get_methods(context_pin.context.namespace, scope: context_pin.context.scope, visibility: [:public, :private, :protected]) result.concat api_map.get_methods('Kernel') result.concat ApiMap.keywords end end package_completions(result) end |
#define ⇒ Array<Pin::Base>
15 16 17 18 19 20 |
# File 'lib/solargraph/source_map/clip.rb', line 15 def define return [] if cursor.comment? || cursor.chain.literal? result = cursor.chain.define(api_map, context_pin, locals) result.concat(source_map.pins.select{ |p| p.location.range.start.line == cursor.position.line }) if result.empty? result end |
#infer ⇒ ComplexType
70 71 72 |
# File 'lib/solargraph/source_map/clip.rb', line 70 def infer cursor.chain.infer(api_map, context_pin, locals) end |
#locals ⇒ Array<Solargraph::Pin::Base>
Get an array of all the locals that are visible from the cursors’s position. Locals can be local variables, method parameters, or block parameters. The array starts with the nearest local pin.
79 80 81 82 83 |
# File 'lib/solargraph/source_map/clip.rb', line 79 def locals @locals ||= source_map.locals.select { |pin| pin.visible_from?(block, Position.new(cursor.position.line, (cursor.position.column.zero? ? 0 : cursor.position.column - 1))) }.reverse end |