Skip to content

Commit

Permalink
[ruby/irb] Fix display_document params in noautocomplete mode
Browse files Browse the repository at this point in the history
(ruby/irb#826)

* Fix display_document params in noautocomplete mode

* Fix wrong preposing and target order in display_document

The fixed wrong-ordered value is not used in RegexpCompletor, so this change does not affect the test.

ruby/irb@08208adb5e
  • Loading branch information
tompng authored and matzbot committed Jan 1, 2024
1 parent c149cd3 commit c0e3c3b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions lib/irb/input-method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,13 @@ def auto_indent(&block)
@auto_indent_proc = block
end

def retrieve_doc_namespace(matched)
preposing, _target, postposing, bind = @completion_params
@completor.doc_namespace(preposing, matched, postposing, bind: bind)
end

def show_doc_dialog_proc
doc_namespace = ->(matched) {
preposing, _target, postposing, bind = @completion_params
@completor.doc_namespace(preposing, matched, postposing, bind: bind)
}
input_method = self # self is changed in the lambda below.
->() {
dialog.trap_key = nil
alt_d = [
Expand All @@ -311,7 +313,7 @@ def show_doc_dialog_proc
cursor_pos_to_render, result, pointer, autocomplete_dialog = context.pop(4)
return nil if result.nil? or pointer.nil? or pointer < 0

name = doc_namespace.call(result[pointer])
name = input_method.retrieve_doc_namespace(result[pointer])
# Use first one because document dialog does not support multiple namespaces.
name = name.first if name.is_a?(Array)

Expand Down Expand Up @@ -419,8 +421,7 @@ def display_document(matched, driver: nil)
return
end

_target, preposing, postposing, bind = @completion_params
namespace = @completor.doc_namespace(preposing, matched, postposing, bind: bind)
namespace = retrieve_doc_namespace(matched)
return unless namespace

driver ||= RDoc::RI::Driver.new
Expand Down
2 changes: 1 addition & 1 deletion test/irb/test_input_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def setup

def display_document(target, bind)
input_method = IRB::RelineInputMethod.new(IRB::RegexpCompletor.new)
input_method.instance_variable_set(:@completion_params, [target, '', '', bind])
input_method.instance_variable_set(:@completion_params, ['', target, '', bind])
input_method.display_document(target, driver: @driver)
end

Expand Down

0 comments on commit c0e3c3b

Please sign in to comment.