Class: Toys::Completion::Context
- Inherits:
-
Object
- Object
- Toys::Completion::Context
- Defined in:
- lib/toys/completion.rb
Overview
The context in which to determine completion candidates.
The #fragment is the entire word being completed, and each candidate returned for it must be a replacement for that entire word. If the shell replaces less than the whole word, because it breaks words at certain characters, the completion engine trims the candidates to match; that is not the concern of a completion.
Instance Attribute Summary collapse
-
#fragment ⇒ String
readonly
The current string fragment to complete.
-
#loader ⇒ Toys::Loader
readonly
The loader providing the tools being completed.
-
#previous_words ⇒ Array<String>
readonly
All previous words.
Instance Method Summary collapse
-
#[](key) ⇒ Object
(also: #get)
Get data for arbitrary key.
-
#arg_parser ⇒ Toys::ArgParser
Current ArgParser indicating the status of argument parsing up to this point.
-
#args ⇒ Array<String>
An array of complete arguments passed to the tool, prior to the fragment to complete.
-
#initialize(loader:, previous_words: [], fragment: "", **params) ⇒ Context
constructor
Create a completion context.
-
#tool ⇒ Toys::ToolDefinition
The tool being invoked, which should control the completion.
-
#with(**delta_params) ⇒ Toys::Completion::Context
Create a new completion context with the given modifications.
Constructor Details
#initialize(loader:, previous_words: [], fragment: "", **params) ⇒ Context
Create a completion context.
Extra params are optional and can be used to affect the behavior in specific cases. Currently these are:
shell: :bashcauses the FileSystem completion to include glob expansions, since bash doesn't handle those directlydisable_flags: truecauses tool completion to omit flag completions which is used by thetoys dobuilt-in tool
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/toys/completion.rb', line 43 def initialize(loader:, previous_words: [], fragment: "", **params) @loader = loader @previous_words = previous_words @fragment = fragment extra_params = { loader: loader, previous_words: previous_words, fragment: fragment } @params = params.merge(extra_params) @tool = nil @args = nil @arg_parser = nil end |
Instance Attribute Details
#fragment ⇒ String (readonly)
The current string fragment to complete. This is the entire word under the cursor, and candidates must replace all of it.
83 84 85 |
# File 'lib/toys/completion.rb', line 83 def fragment @fragment end |
#loader ⇒ Toys::Loader (readonly)
The loader providing the tools being completed.
70 71 72 |
# File 'lib/toys/completion.rb', line 70 def loader @loader end |
#previous_words ⇒ Array<String> (readonly)
All previous words.
76 77 78 |
# File 'lib/toys/completion.rb', line 76 def previous_words @previous_words end |
Instance Method Details
#[](key) ⇒ Object Also known as: get
Get data for arbitrary key.
90 91 92 |
# File 'lib/toys/completion.rb', line 90 def [](key) @params[key] end |
#arg_parser ⇒ Toys::ArgParser
Current ArgParser indicating the status of argument parsing up to this point.
120 121 122 123 |
# File 'lib/toys/completion.rb', line 120 def arg_parser lookup_tool @arg_parser ||= ArgParser.new(@tool, @loader).parse(@args) end |
#args ⇒ Array<String>
An array of complete arguments passed to the tool, prior to the fragment to complete.
109 110 111 112 |
# File 'lib/toys/completion.rb', line 109 def args lookup_tool @args end |
#tool ⇒ Toys::ToolDefinition
The tool being invoked, which should control the completion.
99 100 101 102 |
# File 'lib/toys/completion.rb', line 99 def tool lookup_tool @tool end |
#with(**delta_params) ⇒ Toys::Completion::Context
Create a new completion context with the given modifications.
62 63 64 |
# File 'lib/toys/completion.rb', line 62 def with(**delta_params) Context.new(**@params, **delta_params) end |