Skip to content

Commit

Permalink
[ruby/irb] Use gem repl_type_completor, remove type_completion
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng authored and matzbot committed Nov 29, 2023
1 parent b549722 commit 86d9a6d
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 3,372 deletions.
21 changes: 21 additions & 0 deletions lib/irb/completion.rb
Expand Up @@ -93,6 +93,27 @@ def retrieve_files_to_require_relative_from_current_dir
end
end

class TypeCompletor < BaseCompletor # :nodoc:
def initialize(context)
@context = context
end

def inspect
ReplTypeCompletor.info
end

def completion_candidates(preposing, target, _postposing, bind:)
result = ReplTypeCompletor.analyze(preposing + target, binding: bind, filename: @context.irb_path)
return [] unless result
result.completion_candidates.map { target + _1 }
end

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

class RegexpCompletor < BaseCompletor # :nodoc:
using Module.new {
refine ::Binding do
Expand Down
22 changes: 9 additions & 13 deletions lib/irb/context.rb
Expand Up @@ -176,26 +176,22 @@ def initialize(irb, workspace = nil, input_method = nil)
RegexpCompletor.new
end

TYPE_COMPLETION_REQUIRED_PRISM_VERSION = '0.18.0'

private def build_type_completor
unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0') && RUBY_ENGINE != 'truffleruby'
warn 'TypeCompletion requires RUBY_VERSION >= 3.0.0'
if RUBY_ENGINE == 'truffleruby'
# Avoid SynatxError. truffleruby does not support endless method definition yet.
warn 'TypeCompletor is not supported on TruffleRuby yet'
return
end

begin
require 'prism'
require 'repl_type_completor'
rescue LoadError => e
warn "TypeCompletion requires Prism: #{e.message}"
warn "TypeCompletor requires `gem repl_type_completor`: #{e.message}"
return
end
unless Gem::Version.new(Prism::VERSION) >= Gem::Version.new(TYPE_COMPLETION_REQUIRED_PRISM_VERSION)
warn "TypeCompletion requires Prism::VERSION >= #{TYPE_COMPLETION_REQUIRED_PRISM_VERSION}"
return
end
require 'irb/type_completion/completor'
TypeCompletion::Types.preload_in_thread
TypeCompletion::Completor.new

ReplTypeCompletor.preload_rbs
TypeCompletor.new(self)
end

def save_history=(val)
Expand Down
241 changes: 0 additions & 241 deletions lib/irb/type_completion/completor.rb

This file was deleted.

13 changes: 0 additions & 13 deletions lib/irb/type_completion/methods.rb

This file was deleted.

0 comments on commit 86d9a6d

Please sign in to comment.