Class: RubyLsp::Runar::Completion
- Inherits:
-
Object
- Object
- RubyLsp::Runar::Completion
- Defined in:
- lib/ruby_lsp/runar/completion.rb
Overview
Completion listener that suggests Runar type constants and builtin function names in .runar.rb contract files.
See module-level comment for full documentation.
Constant Summary collapse
- TYPE_NAMES =
All Runar type constant names, matching the constants defined in Runar::Types.
Hover::TYPE_DOCS.keys.freeze
- BUILTIN_NAMES =
All Runar builtin function names, derived from Hover::BUILTIN_DOCS to keep a single source of truth.
Hover::BUILTIN_DOCS.keys.freeze
Instance Method Summary collapse
-
#initialize(response_builder, _node_context, dispatcher, uri) ⇒ Completion
constructor
Instantiate the listener and register it with the dispatcher.
-
#on_call_node_enter(node) ⇒ Object
Fired when the cursor is on (or within) a method call node.
-
#on_constant_read_node_enter(node) ⇒ Object
Fired when the cursor is on (or within) a bare constant reference.
Constructor Details
#initialize(response_builder, _node_context, dispatcher, uri) ⇒ Completion
Instantiate the listener and register it with the dispatcher.
response_builder - CollectionResponseBuilder node_context - RubyLsp::NodeContext for the current cursor position dispatcher - Prism::Dispatcher that fires AST node events uri - URI::Generic identifying the file being completed
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ruby_lsp/runar/completion.rb', line 43 def initialize(response_builder, _node_context, dispatcher, uri) @response_builder = response_builder @uri = uri return unless runar_file? dispatcher.register( self, :on_constant_read_node_enter, :on_call_node_enter ) end |
Instance Method Details
#on_call_node_enter(node) ⇒ Object
Fired when the cursor is on (or within) a method call node.
Offers completions for all Runar builtin functions whose name starts with the characters already typed, provided the call has no explicit receiver (i.e. bare calls like ‘sha2…` rather than `obj.sha2…`).
node - Prism::CallNode
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ruby_lsp/runar/completion.rb', line 77 def on_call_node_enter(node) return if node.receiver = node. return if .nil? || .empty? loc = node. return unless loc push_builtin_completions(range_from_location(loc), ) end |
#on_constant_read_node_enter(node) ⇒ Object
Fired when the cursor is on (or within) a bare constant reference.
Offers completions for all Runar type constants whose name starts with the characters already typed. This covers the common case of typing a type after ‘prop :name, `.
node - Prism::ConstantReadNode
63 64 65 66 67 68 |
# File 'lib/ruby_lsp/runar/completion.rb', line 63 def on_constant_read_node_enter(node) typed = node.slice return if typed.nil? || typed.empty? push_type_completions(range_from_location(node.location), typed) end |