From c0e3c3b6feabac564523c28462e8e45c447b0f0f Mon Sep 17 00:00:00 2001 From: tomoya ishida Date: Mon, 1 Jan 2024 22:57:11 +0900 Subject: [ruby/irb] Fix display_document params in noautocomplete mode (https://github.com/ruby/irb/pull/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. https://github.com/ruby/irb/commit/08208adb5e --- lib/irb/input-method.rb | 15 ++++++++------- test/irb/test_input_method.rb | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb index b74974b925..7e83963764 100644 --- a/lib/irb/input-method.rb +++ b/lib/irb/input-method.rb @@ -291,11 +291,13 @@ module IRB @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 = [ @@ -311,7 +313,7 @@ module IRB 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) @@ -419,8 +421,7 @@ module IRB 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 diff --git a/test/irb/test_input_method.rb b/test/irb/test_input_method.rb index e6a1b06e82..6974fe2df8 100644 --- a/test/irb/test_input_method.rb +++ b/test/irb/test_input_method.rb @@ -90,7 +90,7 @@ module TestIRB 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 -- cgit v1.2.3