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>
- #gates ⇒ Object
- #in_block? ⇒ Boolean
- #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>
- #translate(phrase) ⇒ Array<Solargraph::Pin::Base>
Constructor Details
#initialize(api_map, cursor) ⇒ Clip
Returns a new instance of Clip.
11 12 13 14 |
# File 'lib/solargraph/source_map/clip.rb', line 11 def initialize api_map, cursor @api_map = api_map @cursor = cursor end |
Instance Method Details
#complete ⇒ Completion
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/solargraph/source_map/clip.rb', line 25 def complete return package_completions([]) if !source_map.source.parsed? || cursor.string? 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? if cursor.comment? tag_complete else code_complete end end |
#define ⇒ Array<Pin::Base>
17 18 19 20 21 22 |
# File 'lib/solargraph/source_map/clip.rb', line 17 def define return [] if cursor.comment? || cursor.chain.literal? result = cursor.chain.define(api_map, block, locals) result.concat((source_map.pins + source_map.locals).select{ |p| p.name == cursor.word && p.location.range.contain?(cursor.position) }) if result.empty? result end |
#gates ⇒ Object
63 64 65 |
# File 'lib/solargraph/source_map/clip.rb', line 63 def gates block.gates end |
#in_block? ⇒ Boolean
67 68 69 70 71 72 73 |
# File 'lib/solargraph/source_map/clip.rb', line 67 def in_block? return @in_block unless @in_block.nil? @in_block = begin tree = cursor.source.tree_at(cursor.position.line, cursor.position.column) Parser.is_ast_node?(tree[1]) && [:block, :ITER].include?(tree[1].type) end end |
#infer ⇒ ComplexType
44 45 46 47 48 |
# File 'lib/solargraph/source_map/clip.rb', line 44 def infer result = cursor.chain.infer(api_map, block, locals) return result unless result.tag == 'self' ComplexType.try_parse(cursor.chain.base.infer(api_map, block, locals).namespace) 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.
55 56 57 58 59 60 61 |
# File 'lib/solargraph/source_map/clip.rb', line 55 def locals loc_pos = context_pin.location.range.contain?(cursor.position) ? cursor.position : context_pin.location.range.ending adj_pos = Position.new(loc_pos.line, (loc_pos.column.zero? ? 0 : loc_pos.column - 1)) @locals ||= source_map.locals.select { |pin| pin.visible_from?(block, adj_pos) }.reverse end |
#signify ⇒ Array<Pin::Base>
37 38 39 40 41 |
# File 'lib/solargraph/source_map/clip.rb', line 37 def signify return [] unless cursor.argument? chain = Parser.chain(cursor.recipient_node, cursor.filename) chain.define(api_map, context_pin, locals).select { |pin| pin.is_a?(Pin::Method) } end |
#translate(phrase) ⇒ Array<Solargraph::Pin::Base>
77 78 79 80 |
# File 'lib/solargraph/source_map/clip.rb', line 77 def translate phrase chain = Parser.chain(Parser.parse(phrase)) chain.define(api_map, block, locals) end |