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>
Relevant pins for infering the type of the Cursor’s position.
- #gates ⇒ ::Array<String>
- #infer ⇒ ComplexType
-
#initialize(api_map, cursor) ⇒ Clip
constructor
A new instance of Clip.
-
#locals ⇒ ::Array<Solargraph::Pin::LocalVariable>
Get an array of all the locals that are visible from the cursors’s position.
- #signify ⇒ Array<Pin::Method>
- #translate(phrase) ⇒ Array<Solargraph::Pin::Base>
- #types ⇒ Array<Pin::Base>
Constructor Details
#initialize(api_map, cursor) ⇒ Clip
Returns a new instance of Clip.
11 12 13 14 15 16 |
# File 'lib/solargraph/source_map/clip.rb', line 11 def initialize api_map, cursor @api_map = api_map @cursor = cursor closure_pin = closure closure_pin.rebind(api_map) if closure_pin.is_a?(Pin::Block) && !Solargraph::Range.from_node(closure_pin.receiver).contain?(cursor.range.start) end |
Instance Method Details
#complete ⇒ Completion
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/solargraph/source_map/clip.rb', line 33 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>
Returns Relevant pins for infering the type of the Cursor’s position.
19 20 21 22 23 24 25 |
# File 'lib/solargraph/source_map/clip.rb', line 19 def define return [] if cursor.comment? || cursor.chain.literal? result = cursor.chain.define(api_map, closure, locals) result.concat file_global_methods 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 ⇒ ::Array<String>
74 75 76 |
# File 'lib/solargraph/source_map/clip.rb', line 74 def gates closure.gates end |
#infer ⇒ ComplexType
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/solargraph/source_map/clip.rb', line 52 def infer result = cursor.chain.infer(api_map, closure, locals) if result.tag == 'Class' # HACK: Exception to return BasicObject from Class#new dfn = cursor.chain.define(api_map, closure, locals).first return ComplexType.try_parse('::BasicObject') if dfn && dfn.path == 'Class#new' end # should receive result with selfs resolved from infer() Solargraph.assert_or_log(:clip_infer_self, 'Received selfy inference') if result.selfy? result end |
#locals ⇒ ::Array<Solargraph::Pin::LocalVariable>
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.
69 70 71 |
# File 'lib/solargraph/source_map/clip.rb', line 69 def locals @locals ||= source_map.locals_at(location) end |
#signify ⇒ Array<Pin::Method>
45 46 47 48 49 |
# File 'lib/solargraph/source_map/clip.rb', line 45 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>
80 81 82 83 |
# File 'lib/solargraph/source_map/clip.rb', line 80 def translate phrase chain = Parser.chain(Parser.parse(phrase)) chain.define(api_map, closure, locals) end |
#types ⇒ Array<Pin::Base>
28 29 30 |
# File 'lib/solargraph/source_map/clip.rb', line 28 def types infer.namespaces.map { |namespace| api_map.get_path_pins(namespace) }.flatten end |