From 08208adb5ee150e96983590dad7c3319881a9e32 Mon Sep 17 00:00:00 2001 From: tomoya ishida Date: Mon, 1 Jan 2024 22:57:11 +0900 Subject: [PATCH] Fix display_document params in noautocomplete mode (#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. --- 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 b74974b92..7e8396376 100644 --- a/lib/irb/input-method.rb +++ b/lib/irb/input-method.rb @@ -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 = [ @@ -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) @@ -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 diff --git a/test/irb/test_input_method.rb b/test/irb/test_input_method.rb index e6a1b06e8..6974fe2df 100644 --- a/test/irb/test_input_method.rb +++ b/test/irb/test_input_method.rb @@ -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