Class: IRB::TypeCompletor

Inherits:
BaseCompletor show all
Defined in:
lib/irb/completion.rb

Overview

:nodoc:

Constant Summary

Constants inherited from BaseCompletor

BaseCompletor::GEM_PATHS, BaseCompletor::HELP_COMMAND_PREPOSING

Instance Method Summary collapse

Methods inherited from BaseCompletor

#command_candidates, #command_document_target, #retrieve_files_to_require_from_load_path, #retrieve_files_to_require_relative_from_current_dir, #retrieve_gem_and_system_load_path

Constructor Details

#initialize(context) ⇒ TypeCompletor

Returns a new instance of TypeCompletor.



116
117
118
# File 'lib/irb/completion.rb', line 116

def initialize(context)
  @context = context
end

Instance Method Details

#completion_candidates(preposing, target, _postposing, bind:) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/irb/completion.rb', line 124

def completion_candidates(preposing, target, _postposing, bind:)
  # When completing the argument of `help` command, only commands should be candidates
  return command_candidates(target) if preposing.match?(HELP_COMMAND_PREPOSING)

  commands = if preposing.empty?
    command_candidates(target)
  # It doesn't make sense to propose commands with other preposing
  else
    []
  end

  result = ReplTypeCompletor.analyze(preposing + target, binding: bind, filename: @context.irb_path)

  return commands unless result

  encoded_candidates = result.completion_candidates.filter_map do |i|
    encoded = i.encode(Encoding.default_external)
    target + encoded
  rescue Encoding::UndefinedConversionError
    # If the string cannot be converted, we just ignore it
    nil
  end
  commands | encoded_candidates
end

#doc_namespace(preposing, matched, _postposing, bind:) ⇒ Object



149
150
151
152
153
154
# File 'lib/irb/completion.rb', line 149

def doc_namespace(preposing, matched, _postposing, bind:)
  command_document_target(preposing, matched) || begin
    result = ReplTypeCompletor.analyze(preposing + matched, binding: bind, filename: @context.irb_path)
    result&.doc_namespace('')
  end
end

#inspectObject



120
121
122
# File 'lib/irb/completion.rb', line 120

def inspect
  ReplTypeCompletor.info
end