From 49779e49629080e3fa12b1b0e7a35f8a1b757d6f Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Thu, 12 Oct 2023 23:04:39 +0100 Subject: [PATCH] Fix DAP's completion request with new IRB's completor In IRB 1.8.2, the completor's design and API has been changed and thus would break DAP server's completion request. This commit fixes the issue by introducing a `Completor` class that abstracts away the differences between the old and new completor. --- lib/debug/completor.rb | 22 ++++++++++++++++++++++ lib/debug/server_dap.rb | 4 +++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 lib/debug/completor.rb diff --git a/lib/debug/completor.rb b/lib/debug/completor.rb new file mode 100644 index 000000000..b6a485a0e --- /dev/null +++ b/lib/debug/completor.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require "irb/completion" + +module DEBUGGER__ + class Completor + class << self + # old IRB completion API + if defined?(IRB::InputCompletor) + def retrieve_completion_data(input, binding) + IRB::InputCompletor.retrieve_completion_data(input, bind: binding).compact + end + else + COMPLETOR = IRB::RegexpCompletor.new + + def retrieve_completion_data(input, binding) + COMPLETOR.retrieve_completion_data(input, bind: binding, doc_namespace: false).compact + end + end + end + end +end diff --git a/lib/debug/server_dap.rb b/lib/debug/server_dap.rb index 8dbefda8a..6328a462e 100644 --- a/lib/debug/server_dap.rb +++ b/lib/debug/server_dap.rb @@ -5,6 +5,8 @@ require 'tmpdir' require 'fileutils' +require_relative 'completor' + module DEBUGGER__ module UI_DAP SHOW_PROTOCOL = ENV['DEBUG_DAP_SHOW_PROTOCOL'] == '1' || ENV['RUBY_DEBUG_DAP_SHOW_PROTOCOL'] == '1' @@ -980,7 +982,7 @@ def process_dap args frame = get_frame(fid) if (b = frame&.binding) && word = text&.split(/[\s\{]/)&.last - words = IRB::InputCompletor::retrieve_completion_data(word, bind: b).compact + words = Completor.retrieve_completion_data(word, b) end event! :protocol_result, :completions, req, targets: (words || []).map{|phrase|