class Samovar::Completion::Provider
Expands static, dynamic, and native completion providers.
Public Class Methods
Source
# File vendor/bundle/ruby/4.0.0/gems/samovar-2.5.1/lib/samovar/completion/provider.rb, line 17 def initialize(context, completions) @context = context @completions = completions end
Public Instance Methods
Source
# File vendor/bundle/ruby/4.0.0/gems/samovar-2.5.1/lib/samovar/completion/provider.rb, line 25 def suggestions case @completions when nil Result.new when Symbol native_suggestions else matching_suggestions end end
Generate suggestions from the provider.
@returns [Result] The matching completion suggestions.
Protected Instance Methods
Source
# File vendor/bundle/ruby/4.0.0/gems/samovar-2.5.1/lib/samovar/completion/provider.rb, line 41 def matching_suggestions values = @completions if values.respond_to?(:call) values = values.call(@context) end values = Array(values).filter_map do |value| suggestion = Suggestion.wrap(value) suggestion if suggestion.start_with?(@context.current) end return Result.new(values) end
Generate matching suggestions from static or dynamic completions.
@returns [Result] The matching completion suggestions.
Source
# File vendor/bundle/ruby/4.0.0/gems/samovar-2.5.1/lib/samovar/completion/provider.rb, line 60 def native_suggestions case @completions when :path, :file Result.new([Suggestion.new(@context.current, description: "Path", type: :path)]) when :directory Result.new([Suggestion.new(@context.current, description: "Directory", type: :directory)]) when :executable Result.new([Suggestion.new(@context.current, description: "Executable", type: :executable)]) else Result.new end end
Generate native shell completion requests.
@returns [Result] The native completion request suggestions.